[英]Creating a date exactly one month in the past in SAS
I am trying to create two datetime variables in SAS 9.3. 我正在尝试在SAS 9.3中创建两个日期时间变量。 The first, "endDate" is the current datetime at the time the program is run.
第一个“ endDate”是程序运行时的当前日期时间。 The second, "startDate" is exactly one month in the past.
第二个“ startDate”恰好是过去一个月。
My code is: 我的代码是:
%let endDate = %sysfunc(DATETIME() datetime.);
%let startDate = %sysfunc(intnx('month', DATETIME(), -1) datetime.);
Based on any documentation I can find, I can't figure out what is wrong with it, but I am getting the following error message: 根据我能找到的任何文档,我无法弄清楚它出了什么问题,但是我收到以下错误消息:
"ERROR: Expected close parenthesis after macro function invocation not found." “错误:未找到宏函数调用后的预期右括号。”
What am I doing wrong? 我究竟做错了什么?
Some additional background: I want to use these two macro variables inside a proc sql statement so I can filter a table to data from within the past month at the run-time. 其他一些背景知识:我想在proc sql语句中使用这两个宏变量,以便可以在运行时将表筛选为过去一个月内的数据。
Thanks! 谢谢!
You have a couple of issues: 您有几个问题:
You don't need quotes around literals in a macro call 您不需要在宏调用中在文字前后加上引号
%let endDate = %sysfunc(DATETIME(), datetime.); %put &endDate; %let startDate = %sysfunc(intnx(dtmonth, %sysfunc(datetime()), -1), datetime.); %put &StartDate;
Four things: 四件事:
%sysfunc
%sysfunc
调用函数时,不需要在字符串参数周围加上单引号 %sysfunc
for every individual data step function you want to call in the macro environment, which means you need to nest them in this case as you're calling one function inside another. %sysfunc
,这意味着在这种情况下您需要嵌套它们,因为您要在另一个函数中调用另一个函数。 This can get messy. dtmonth
instead of month
. dtmonth
而不是month
。 %sysfunc
%sysfunc
的格式之间加逗号 Putting it all together: 放在一起:
%let endDate = %sysfunc(DATETIME(), datetime.);
%let startDate = %sysfunc(intnx(dtmonth, %sysfunc(DATETIME()), -1), datetime.);
%let endDate = %sysfunc(DATETIME(), datetime21.);
%let startDate =%sysfunc(putn(%sysfunc(intnx(dtmonth, %sysfunc(DATETIME()), -1,same)),datetime21.));
%put &enddate &startdate;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.