Hi ,
Can any one help me
i have a macro
%apps(month);
/*month format is yymmn6.*/;
...
...
..
%mend apps;
%apps(201301);
%apps(201302);
%apps(201303);
%apps(201304);
%apps(201305);
%apps(201306);
%apps(201307);
%apps(201308);
%apps(201309);
%apps(201310);
%apps(201311);
%apps(201312);
%apps(201401);
.
.
till today;
till now i am giving manual dates
now i have to do dynamically
when i pass macro in the month parameter then it has to create a dataset for each yearmonth till today
So what is the question? Maybe something like:
%macro apps (month); /* note the name is inconsistent as its not a month */ data _null_; do year=input(substr("&month.",1,4),best.) to year(today); do month=input(substr("&month.",5,2),best.) to 12; call execute(cats('data want',put(year,z4.),put(month,z2.),'; set have; run;')); end; end; run; %mend apps; %apps(201301);
%macro multiple_runs(N=,interval=,dateformat=);
%do j=0 %to &N. %by 1;
%let datestring&j. = %sysfunc(putn(%sysfunc(intnx(&interval,%sysfunc(today()),-&j.,beg)),&dateformat));
%apps(&&datestring&j.);
%end;
%mend;
/* Loops through the current month (datestr0) and 4 previous months. */
%multiple_runs(N=4,interval=month,dateformat=yymmn6.);
Set N to equal as many months back as you need to go.
Note there is no need for PUTN as %SYSFUNC() already accepts a format specification.
%sysfunc(intnx(&interval,%sysfunc(today()),-&j.,beg),&dateformat)
Instead of several macro call you can change your %apps() macro code to loop through years if that possible. If not find the below code that might work.
%macro loop_years(yyyymm=);
%do i=%substr(&yyyymm,1,4) %to %sysfunc(year(%sysfunc(today())));
%do j=%sysfunc(ifc(&i=%substr(&yyyymm,1,4),%substr(&yyyymm,5,2),01))
%to %sysfunc(ifc(&i=%sysfunc(year(%sysfunc(today()))),%sysfunc(month(%sysfunc(today()))),12));
%let month_j=%sysfunc(putn(&j,z2.));
%apps(&i&month_j);
%end;
%end;
%mend loop_years;
%loop_years(yyyymm=201305);
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.