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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

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
  • 830 views
  • 0 likes
  • 3 in conversation