BookmarkSubscribeRSS Feed
CM64
Calcite | Level 5

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

2 REPLIES 2
Reeza
Super User

Your requirements are unclear, is it:

  • repeat each call 200 times
  • increment by 6 for each macro call up to 200

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


 

Tom
Super User Tom
Super User

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