SAS folks-
I’m looking for an easy way to generate a series of SAS dates given the start date and end date in macro variables (daily or monthly is typical). I run into this occasionally, and have not found a solution that always works.
Given macro variables START_DATE of 01apr1998 and END_DATE of 11feb2014, then ????
We are running SAS 9.3, and we have ETS, STAT, and GRAPH.
Thanks so much for your help!
Wendy T
Using the intnx function, you can change the month to days for different time periods, ie week, month, quarter etc. Check the documentation for the options ![]()
%let start_date=01Apr1998;
%let end_date=11feb2014;
data want_month;
date="&start_date"d;
do while (date<="&end_date"d);
output;
date=intnx('month', date, 1, 's');
end;
format date date9.;
run;
data want_day;
date="&start_date"d;
do while (date<="&end_date"d);
output;
date=intnx('day', date, 1, 's');
end;
format date date9.;
run;
%let start_date=01Apr1998;
%let end_date=11feb2014;
data want;
do date="&start_date"d to "&end_date"d;
output;
end;
format date date9.;
run;
Using the intnx function, you can change the month to days for different time periods, ie week, month, quarter etc. Check the documentation for the options ![]()
%let start_date=01Apr1998;
%let end_date=11feb2014;
data want_month;
date="&start_date"d;
do while (date<="&end_date"d);
output;
date=intnx('month', date, 1, 's');
end;
format date date9.;
run;
data want_day;
date="&start_date"d;
do while (date<="&end_date"d);
output;
date=intnx('day', date, 1, 's');
end;
format date date9.;
run;
Reeza-
Thanks so much for your elegant answers - they were just what I needed!
Sorry for the delay in getting them marked - for some reason I have been unable to access the buttons.
Wendy T
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.