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.);
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
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.