SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
emwu9912
Calcite | Level 5

Hello! I'm trying to create a one-column dataset that goes from a start date of January 24th, 2020 to today's date. I've been updating the end date weekly, but I'd really like to make this dynamic. How do I properly use the SAS macro variable SYSDATE9 to accomplish this? Right now I'm getting this error:

 

ERROR: Invalid date/time/datetime constant '&sysdate9'd.
ERROR 77-185: Invalid number conversion on '&sysdate9'd.
 
Here is the code I have:

 

%put &=sysdate9;

 

data date;
length Date 8;
do Date = '24JAN2020'd to '&sysdate9'd;
output;
end;
format date yymmdd10.;
run;

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Macro variables have to be inside double-quotes to resolve. When inside single quotes they are treated as just plain text.

 

 

do Date = '24JAN2020'd to "&sysdate9"d;

 

or possibly:

date = '24Jan2020'd to today();

 

View solution in original post

4 REPLIES 4
ballardw
Super User

Macro variables have to be inside double-quotes to resolve. When inside single quotes they are treated as just plain text.

 

 

do Date = '24JAN2020'd to "&sysdate9"d;

 

or possibly:

date = '24Jan2020'd to today();

 

Cynthia_sas
SAS Super FREQ
Hi:
Macro variable references do not resolve in single quotes. So &sysdate9 is just a text string. If you want to have it resolve to today's day, you need to do:
"&sysdate9"d
with double quotes.

Hope this helps,
Cynthia
emwu9912
Calcite | Level 5

That did the trick. Thank you so much!

PaigeMiller
Diamond | Level 26

Also, please note that if you use &sysdate, and you leave your SAS session open overnight, &sysdate doesn't update at midnight. It shows the date when this particular SAS session was begun. If you want to read the current date and time, and avoid the problem of &sysdate not updating, you would use

 

%let today=%sysfunc(today());

 

--
Paige Miller

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1511 views
  • 0 likes
  • 4 in conversation