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
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!
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.