Hello!
Below is the date macros code, that I'm using in my program
DATA _NULL_;
if "&sysparm" EQ ' ' THEN DO;
call symput('begdate',put(intnx('qtr',TODAY(),-1,'b'),date9.));
call symput('enddate',put(intnx('qtr',TODAY(),-1,'e'),date9.));
END;
ELSE DO;
call symput('begdate',PUT(input(scan("&sysparm.", 1, ',' ) , mmddyy10.),date9.));
call symput('enddate',PUT(input(scan("&sysparm.", 2, ',' ) , mmddyy10.),date9.));
END;
RUN;
%put begdate3 : &begdate;
begdate3 : 01JAN2019
%put enddate3 : &enddate ;
enddate3 : 31MAR2019
While using the macro in the program,
mc.file_rcvd_date>= &begdate. and
mc.file_rcvd_date < &enddate.
I'm getting the below error.
rcvd_date>= &begdate. and
NOTE: Line generated by the macro variable "BEGDATE".
01JAN2019
_______
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, GE, GET,
GROUP, GT, GTT, HAVING, LE, LET, LT, LTT, NE, NET, OR, ORDER, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
rcvd_date < &enddate.
;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
Pleae help me on resolving this. Thanks.
Macro variables just perform text substitution when SAS executes your code, and then the text with the substitution must be legal valid working SAS code.
So
mc.file_rcvd_date>= &begdate. and mc.file_rcvd_date < &enddate.
resolves to
mc.file_rcvd_date>= 01JAN2019 and mc.file_rcvd_date < 31MAR2019
which is not legal valid working SAS code.
An important concept is that you should ALWAYS create legal valid working SAS code WITHOUT MACROS on one example of your code. Then you can be reasonably sure that the macro substitution will result is legal valid working SAS code.
In this case in particular, there is no need to format the dates in the macro variables, it is unnecessary work and causes the problem. It is unnecessary extra work, that produces no benefit, and offers many opportunities for typing errors or syntax errors, and also causes your program to fail.
DATA _NULL_;
if "&sysparm" EQ ' ' THEN DO;
call symput('begdate',TODAY(),-1,'b');
call symput('enddate',TODAY(),-1,'e');
END;
ELSE DO;
call symput('begdate',scan("&sysparm.", 1, ',' ));
call symput('enddate',scan("&sysparm.", 2, ',' ));
END;
RUN;
Macro variables just perform text substitution when SAS executes your code, and then the text with the substitution must be legal valid working SAS code.
So
mc.file_rcvd_date>= &begdate. and mc.file_rcvd_date < &enddate.
resolves to
mc.file_rcvd_date>= 01JAN2019 and mc.file_rcvd_date < 31MAR2019
which is not legal valid working SAS code.
An important concept is that you should ALWAYS create legal valid working SAS code WITHOUT MACROS on one example of your code. Then you can be reasonably sure that the macro substitution will result is legal valid working SAS code.
In this case in particular, there is no need to format the dates in the macro variables, it is unnecessary work and causes the problem. It is unnecessary extra work, that produces no benefit, and offers many opportunities for typing errors or syntax errors, and also causes your program to fail.
DATA _NULL_;
if "&sysparm" EQ ' ' THEN DO;
call symput('begdate',TODAY(),-1,'b');
call symput('enddate',TODAY(),-1,'e');
END;
ELSE DO;
call symput('begdate',scan("&sysparm.", 1, ',' ));
call symput('enddate',scan("&sysparm.", 2, ',' ));
END;
RUN;
Thanks for taking your time and explaining this to me. Much appreciated.
Correction:
Not sure what &SYSPARM values are, you may need something like this depending on the values in &sysparm, perhaps a different informat is needed.
ELSE DO;
call symput('begdate',input(scan("&sysparm.", 1, ',' ),anydtdte.));
call symput('enddate',input(scan("&sysparm.", 2, ',' ),anydtdte.));
END;
Hello!
Good morning! Below is the date macros code, that I'm using in my program
DATA _NULL_;
if "&sysparm" EQ '' THEN DO;
call symput('begdate',put(intnx('qtr',TODAY(),-1,'b'),date9.));
call symput('enddate',put(intnx('qtr',TODAY(),-1,'e'),date9.));
END;
ELSE DO;
call symput('begdate',PUT(input(scan("&sysparm.", 1, ',' ) , mmddyy10.),date9.));
call symput('enddate',PUT(input(scan("&sysparm.", 2, ',' ) , mmddyy10.),date9.));
END;
RUN;
%put begdate3 : &begdate;
begdate3 : 01JAN2019
%put enddate3 : &enddate ;
enddate3 : 31MAR2019
While using the macro in the program, I'm getting the below error.
rcvd_date>= &begdate. and
NOTE: Line generated by the macro variable "BEGDATE".
01JAN2019
_______
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, GE, GET,
GROUP, GT, GTT, HAVING, LE, LET, LT, LTT, NE, NET, OR, ORDER, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
rcvd_date < &enddate.
;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
Even though macro resolves to the required format, I'm getting the syntax error. Also, please validate if I'm using the right code.
Please help me on resolving this. Thanks.
I merged the double-post. Please keep a single question in a single topic.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.