Suppose I have two global macro variables called year and month that a user can change as need (or automatically set). I would like SAS to automatically create a dataset that has one variable called date and it will populate all the days on the month. So if year was set to 2020 and month was set to 5, then the dataset would be automatically created with all the days for May (31 of them) as YYMMDDS8. Is this possible?
Thanks!
Like this?
%let year = 2020;
%let month = 5;
data want;
do dt = mdy(&month, 1, &year) by 1 while (month(dt)=&month);
output;
end;
format dt yymmdds8.;
run;
Like this?
%let year = 2020;
%let month = 5;
data want;
do dt = mdy(&month, 1, &year) by 1 while (month(dt)=&month);
output;
end;
format dt yymmdds8.;
run;
nice! You original worked as well (I modified it to my needs...posted below for others). Thanks for both!
%let year = 2020;
%let month = 2;
data egtask.DATE_LIST;
do DATE = intnx('month', mdy(&month, 1, &year), 0, 'b') to
intnx('month', mdy(&month, 1, &year), 0, 'e');
output;
end;
format DATE yymmdds8.;
run;
Anytime 🙂 Glad to help
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.