How do I output this to a dataset?
This example shows how to use macro logic and a macro %DO loop to loop through a starting and ending date.
%macro date_loop(start,end);
/*converts the dates to SAS dates*/
%let start=%sysfunc(inputn(&start,anydtdte9.));
%let end=%sysfunc(inputn(&end,anydtdte9.));
/*determines the number of months between the two dates*/
%let dif=%sysfunc(intck(month,&start,&end));
%do i=0 %to &dif;
/*advances the date i months from the start date and applys the DATE9. format*/
%let date=%sysfunc(putn(%sysfunc(intnx(month,&start,&i,b)),date9.));
%put &date;
%end;
%mend;
%date_loop(01jun2008,01sep2009)
You would do that in a data step, not in macro logic. I've left the macro variables but that isn't needed either.
%let start="01Jan2018"d;
%let end="01Dec2018"d;
data want;
n_intervals = intck('month', &start, &end);
do i=0 to n_intervals;
date = intnx('month', &start, i, 'b');
output;
end;
run;
@BhargavDesai wrote:
How do I output this to a dataset?
This example shows how to use macro logic and a macro %DO loop to loop through a starting and ending date.
%macro date_loop(start,end); /*converts the dates to SAS dates*/ %let start=%sysfunc(inputn(&start,anydtdte9.)); %let end=%sysfunc(inputn(&end,anydtdte9.)); /*determines the number of months between the two dates*/ %let dif=%sysfunc(intck(month,&start,&end)); %do i=0 %to &dif; /*advances the date i months from the start date and applys the DATE9. format*/ %let date=%sysfunc(putn(%sysfunc(intnx(month,&start,&i,b)),date9.)); %put &date; %end; %mend; %date_loop(01jun2008,01sep2009)
CFC_SAS_Communities_400x225.jpg
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.