BookmarkSubscribeRSS Feed
SRINIVAS_N
Calcite | Level 5

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 

 

 

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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



cousineddie
Fluorite | Level 6
%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.);
cousineddie
Fluorite | Level 6

Set N to equal as many months back as you need to go. 

Tom
Super User Tom
Super User

Note there is no need for PUTN as %SYSFUNC() already accepts a format specification.

%sysfunc(intnx(&interval,%sysfunc(today()),-&j.,beg),&dateformat)
SuryaKiran
Meteorite | Level 14

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);
Thanks,
Suryakiran
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1730 views
  • 0 likes
  • 5 in conversation