Help using Base SAS procedures

"Date" macro variables

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 440
Accepted Solution

"Date" macro variables

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


Accepted Solutions
Solution
‎03-11-2016 12:41 PM
Super User
Posts: 17,829

Re: "Date" macro variables

[ Edited ]

Read the log - it's quite helpful Smiley Happy

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;

View solution in original post


All Replies
Solution
‎03-11-2016 12:41 PM
Super User
Posts: 17,829

Re: "Date" macro variables

[ Edited ]

Read the log - it's quite helpful Smiley Happy

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;
Super Contributor
Super Contributor
Posts: 440

Re: "Date" macro variables

ohhh right

cuz of the date9. format  a character variable is passed to dte2. did not realize  that Smiley Sad

 

Thank you Reeza

Super User
Posts: 5,083

Re: "Date" macro variables

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 320 views
  • 2 likes
  • 3 in conversation