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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

3 REPLIES 3
Reeza
Super User

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;
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

ohhh right

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

 

Thank you Reeza

Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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