BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WendyT
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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 Smiley Happy

%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;

View solution in original post

3 REPLIES 3
Reeza
Super User

%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;

Reeza
Super User

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 Smiley Happy

%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;

WendyT
Pyrite | Level 9

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

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

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
  • 3 replies
  • 46371 views
  • 8 likes
  • 2 in conversation