I'd like to call a macro 200 times and increment the parameter with each call, but I don't want to repeat each call 200 times. Is there a %do %loop that can provide what I need?
%macro Weeks(week=);
proc sort data=in.test1 out=test1_W&week. (keep=subject); by subject; where folder="WEEK&week."; run;
run;
%mend;
%Weeks(Week=6); *increment by 6 for each macro call up to 200;
%Weeks(Week=12);
%Weeks(Week=18);
.
.
.
%Weeks(Week=200);
Your requirements are unclear, is it:
Assuming the first one, use a data step loop and CALL EXECUTE. Modification for the second one is pretty straightforward in a data step as well.
data demo_run_macro;
increment=6;
do i=1 to 200;
str = catt('%weeks(week=', i*increment, ');');
call execute(str);
end;
run;
@CM64 wrote:
I'd like to call a macro 200 times and increment the parameter with each call, but I don't want to repeat each call 200 times. Is there a %do %loop that can provide what I need?
%macro Weeks(week=);
proc sort data=in.test1 out=test1_W&week. (keep=subject); by subject; where folder="WEEK&week."; run;
run;
%mend;
%Weeks(Week=6); *increment by 6 for each macro call up to 200;
%Weeks(Week=12);
%Weeks(Week=18);
.
.
.
%Weeks(Week=200);
To increment by 6 use the BY keyword on a DO loop.
filename code temp;
data _null_;
file code;
do week=6 to 200 by 6 ;
put '%weeks(' week= ')';
end;
run;
%include code / source2;
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!
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.