hi guys,
data _null_;
call symput ('dte1', put(today(),yymmn4.));
call symput ('dte2', put(today(),date9.));
run;
data test;
date1=&dte1;
date2=&dte2; run;
the code above wont work/run for date2=&dte2 but it works if date2="&dte2"
Can someone please explaing why?
Thx
Read the log - it's quite helpful 🙂
The generated code turns out to be:
date1=1603;
date2=11Mar2016;
For date1, it's a number so there's no issue.
For date1 however, it appears to be a character so it needs quotes. If you want to keep it as a date then include the d, to specifiy a date literal.
date2="&dte2."d;
The log indicates that it's trying to pass a character variable and points you to the error.
1087 data test;
1088 date1=&dte1;
SYMBOLGEN: Macro variable DTE1 resolves to 1603
1089 date2=&dte2;
SYMBOLGEN: Macro variable DTE2 resolves to 11MAR2016
NOTE: Line generated by the macro variable "DTE2".
1 11MAR2016
-------
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=,
<>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR,
^=, |, ||, ~=.
1090
1091 run;
Read the log - it's quite helpful 🙂
The generated code turns out to be:
date1=1603;
date2=11Mar2016;
For date1, it's a number so there's no issue.
For date1 however, it appears to be a character so it needs quotes. If you want to keep it as a date then include the d, to specifiy a date literal.
date2="&dte2."d;
The log indicates that it's trying to pass a character variable and points you to the error.
1087 data test;
1088 date1=&dte1;
SYMBOLGEN: Macro variable DTE1 resolves to 1603
1089 date2=&dte2;
SYMBOLGEN: Macro variable DTE2 resolves to 11MAR2016
NOTE: Line generated by the macro variable "DTE2".
1 11MAR2016
-------
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=,
<>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR,
^=, |, ||, ~=.
1090
1091 run;
ohhh right
cuz of the date9. format a character variable is passed to dte2. did not realize that 😞
Thank you Reeza
What would you expect SAS to do if you typed this in a DATA step:
dte2=11Mar2016;
Of course it would generate an error. That's the program you generated, so that's the result that you got.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.