[英]dynamic date range of one year in Proc SQL pass through query
New to SAS and SQL and struggling to create a dynamic range in PROC SQL. SAS和SQL的新手,正在努力在PROC SQL中创建动态范围。
As of now, code is hard coded as - 截至目前,代码已被硬编码为-
xxxx.xx_ccyymm_xx between '201607' and '201706'. 在'201607'和'201706'之间的xxxx.xx_ccyymm_xx。 Trying to create a dynamic range so that next month when it is run, it takes on values as 201608 and 201707.
尝试创建动态范围,以便在下个月运行该动态范围时,其取值为201608和201707。
*the variable stores date as in string format *变量以字符串格式存储日期
Someone please suggest a way out!! 有人建议出路!!
Sincere Thanks in advance. 真诚的感谢。
In proc sql
: 在
proc sql
:
. . .
where xxxx.xx_ccyymm_xx <= put(today(), yymmn6.) and
xxxx.xx_ccyymm_xx <= put(intnx('year', today(), 1), yymmn6.)
You can use macro variables to hold the strings. 您可以使用宏变量来保存字符串。 You can use %SYSFUNC() to call the INTNX() function to adjust the date by months.
您可以使用%SYSFUNC()调用INTNX()函数来按月调整日期。 You could use the automatic macro variable &SYSDATE9 to have the day your SAS session started in DATE9 format, or call the DATE() function to get the actual current date.
您可以使用自动宏变量&SYSDATE9以DATE9格式开始SAS会话的日期,或者调用DATE()函数以获取实际的当前日期。
%let today=%sysfunc(date(),date9);
Then you can generate your YYYYMM format strings from that. 然后,您可以从中生成YYYYMM格式的字符串。
%let current_month=%sysfunc(putn("&today"d,yymmn6));
%let start_month=%sysfunc(intnx(month,"&today"d,-11),yymmn6);
Then in your query use the macro variables 然后在查询中使用宏变量
where myvar between "&start_month" and "¤t_month"
If you want to have it apply based on run-time: 如果要基于运行时应用它:
xxxx.xx_ccyymm_xx between
left(convert(varchar,dateadd(month,-11,getdate()),112),6)
and
left(convert(varchar,getdate(),112),6)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.