- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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:
%put &=sysdate9;
data date;
length Date 8;
do Date = '24JAN2020'd to '&sysdate9'd;
output;
end;
format date yymmdd10.;
run;
Thanks in advance!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That did the trick. Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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