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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 1309 views
  • 0 likes
  • 4 in conversation