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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.