BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I need to Run series of macros for each date from 23AUG2020 until 05SEP2020.

What is the way to perform it with minimum code length?

One more issue that the the dates of running will not include Saturday and Sunday because it is not  business days

 


%MMacro(date='23AUG2020'd,CAT=X1,Ffmt=FF1F.);
%MMacro(date='23AUG2020'd,CAT=X2,Ffmt=FF2F.);
%MMacro(date='23AUG2020'd,CAT=X3,Ffmt=FF3F.);
%MMacro(date='23AUG2020'd,CAT=X4,Ffmt=FF4F.);
%MMacro(date='23AUG2020'd,CAT=X5,Ffmt=FF5F.);
%MMacro(date='23AUG2020'd,CAT=X6,Ffmt=FF6F.);
%MMacro(date='23AUG2020'd,CAT=X7,Ffmt=FF7F.);
%MMacro(date='23AUG2020'd,CAT=X8,Ffmt=FF8F.);
%MMacro(date='23AUG2020'd,CAT=X9,Ffmt=FF9F.);
%MMacro(date='23AUG2020'd,CAT=X10,Ffmt=FF10F.);


%MMacro(date='24AUG2020'd,CAT=X1,Ffmt=FF1F.);
%MMacro(date='24AUG2020'd,CAT=X2,Ffmt=FF2F.);
%MMacro(date='24AUG2020'd,CAT=X3,Ffmt=FF3F.);
%MMacro(date='24AUG2020'd,CAT=X4,Ffmt=FF4F.);
%MMacro(date='24AUG2020'd,CAT=X5,Ffmt=FF5F.);
%MMacro(date='24AUG2020'd,CAT=X6,Ffmt=FF6F.);
%MMacro(date='24AUG2020'd,CAT=X7,Ffmt=FF7F.);
%MMacro(date='24AUG2020'd,CAT=X8,Ffmt=FF8F.);
%MMacro(date='24AUG2020'd,CAT=X9,Ffmt=FF9F.);
%MMacro(date='24AUG2020'd,CAT=X10,Ffmt=FF10F.);


 until

%MMacro(date='05SEP2020'd,CAT=X1,Ffmt=FF1F.);
%MMacro(date='05SEP2020'd,CAT=X2,Ffmt=FF2F.);
%MMacro(date='05SEP2020'd,CAT=X3,Ffmt=FF3F.);
%MMacro(date='05SEP2020'd,CAT=X4,Ffmt=FF4F.);
%MMacro(date='05SEP2020'd,CAT=X5,Ffmt=FF5F.);
%MMacro(date='05SEP2020'd,CAT=X6,Ffmt=FF6F.);
%MMacro(date='05SEP2020'd,CAT=X7,Ffmt=FF7F.);
%MMacro(date='05SEP2020'd,CAT=X8,Ffmt=FF8F.);
%MMacro(date='05SEP2020'd,CAT=X9,Ffmt=FF9F.);
%MMacro(date='05SEP2020'd,CAT=X10,Ffmt=FF10F.);


 

 

2 REPLIES 2
Kurt_Bremser
Super User

Two nested %DO loops:

%macro outer;
%do loopdate = %sysfunc(inputn(20200823,yymmdd8.)) %to %sysfunc(inputn(20200905,yymmdd8.));
  %do i = 1 %to 10;
    %mmacro(date=&loopdate.,cat=X&i.,ffmt=FF&i.F.);
  %end;
%end;
%mend;
%outer
unison
Lapis Lazuli | Level 10

Another approach -- using the data step routine to loop through the date range and inner-loop (1-10) range and call the execute routine to invoke the macro.

*Table to show the macro parameters;
proc sql;
	create table temp 
	(
		DATE char(12),
		CAT char(3),
		FFmt char(6)
	);
quit;

*Dummy macro definition that inserts the macro parameters into the temp table;
%macro MMacro(date=,CAT=,Ffmt=);
	proc sql;
		insert into temp
		values ("&date","&cat","&ffmt");
	;quit;
%mend;

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
*User input macro variables;
%let sdt = 23AUG2020;
%let edt = 05SEP2020;
%let inner_loops = 10;

*Loop through date range and number of inner_loops;
data _null_;
	format i date9.;
	day_cnt=0;

	do until(i>="&edt"d);
		n_cnt=1;
		i=intnx('day', "&sdt"d, day_cnt);

		do j=1 to &inner_loops;
			str=cats('%MMacro(date=', cats("'", put(i, date9.), "'d"), ',CAT=X', n_cnt,',Ffmt=FF', n_cnt, 'F.);'); *<---- Build the command;
			call execute(str); *<---- Execute the "str" command;
			n_cnt+1;
		end;
		day_cnt+1;
	end;
run;

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
*Check all of the macro parameter values that were used;
proc print data=temp;
run;
-unison

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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