[英]How to use macro in WHERE statement in PROC SQL?
%let CHECK_DATE = %sysfunc(SUM(&end_of_period.,1),yymmdd10.);
proc sql;
select * from table1
where Source_Date < input(&CHECK_DATE.,yymmdd10.);
quit;
&CHECK_DATE is a date macro in the format of '2015-12-31'; &CHECK_DATE是日期宏,格式为“ 2015-12-31”;
Source_Date is the SAS date value. Source_Date是SAS日期值。
I get this error when I try to run this code. 尝试运行此代码时出现此错误。 Not sure why... 不知道为什么
_
22
_
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, (, +, -, BTRIM, CALCULATED, CASE, EXISTS, INPUT, NOT, PUT, SUBSTRING, TRANSLATE, USER, ^, ~.
ERROR 200-322: The symbol is not recognized and will be ignored.
_
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
I assume it is just because you have not put quotes around your character literal that you passing to the INPUT()
function. 我想这仅仅是因为您没有在传递给INPUT()
函数的字符文字周围加上引号。
This code runs. 此代码运行。
data table1;
source_date=date();
format source_date yymmdd10.;
run;
%let end_of_period=%sysfunc(date());
%put &=end_of_period ;
%let CHECK_DATE = %sysfunc(SUM(&end_of_period.,1),yymmdd10.);
%put &=check_date ;
proc sql;
select * from table1
where Source_Date < input("&CHECK_DATE",yymmdd10.)
;
quit;
But it would be much easier to not use &CHECK_DATE
and just code the where clause using &END_OF_PERIOD
. 但是,不使用&CHECK_DATE
而仅使用&CHECK_DATE
编写where子句会容易&END_OF_PERIOD
。
proc sql;
select * from table1
where Source_Date < &end_of_period + 1
;
quit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.