BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
West26
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
West26
Obsidian | Level 7

Thanks for taking your time and explaining this to me. Much appreciated.

PaigeMiller
Diamond | Level 26

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;

 

 

--
Paige Miller
West26
Obsidian | Level 7

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.

Astounding
PROC Star
Your syntax is incorrect. Without macro language, this would be wrong:

rcvd_date > 01JAN2019 and

The correct reference to a date would be:

rcvd_date > "01JAN2019"d and

You need to force macro language to generate the same comparison:

rcvd_date> "&begdate."d and

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 767 views
  • 0 likes
  • 4 in conversation