DATA Step, Macro, Functions and more

run same macro many time with different parameters

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

run same macro many time with different parameters


I need to run the same macro CT 50 times changing just one of the several parameters. A, B, C...... are 50 variables that need to be replaced in the call macro.

%CT(param1=data, param2=inv, param3=A);

%CT(param1=data, param2=inv, param3=B);

%CT(param1=data, param2=inv, param3=C);

.....


Accepted Solutions
Solution
‎12-10-2012 04:43 PM
Contributor
Posts: 43

Re: run same macro many time with different parameters

I like Barry's 1st answer Smiley Happy  and below is how you would do for his second suggestion.

get the list of variables that needs to be passed to the macro and send them all to a macro variable separating them by a special character, say LIST for example:

the macro variable LIST would be like this A*B*C*D*............*Z

now loop it through all the parameters

%do i=1 %to 50;

     %let param=%scan(&list,&i,'*');

     %CT(param1=data, param2=inv, param3=&param);

%end;


hope this helps.

View solution in original post


All Replies
Super Contributor
Posts: 356

Re: run same macro many time with different parameters

Copy and paste works well Smiley Wink

or consider using a macro do / while loop


Solution
‎12-10-2012 04:43 PM
Contributor
Posts: 43

Re: run same macro many time with different parameters

I like Barry's 1st answer Smiley Happy  and below is how you would do for his second suggestion.

get the list of variables that needs to be passed to the macro and send them all to a macro variable separating them by a special character, say LIST for example:

the macro variable LIST would be like this A*B*C*D*............*Z

now loop it through all the parameters

%do i=1 %to 50;

     %let param=%scan(&list,&i,'*');

     %CT(param1=data, param2=inv, param3=&param);

%end;


hope this helps.

Super User
Posts: 5,256

Re: run same macro many time with different parameters

You can have you parameters stored in a SAS table, and call the macro by using call execute instead.

Data never sleeps
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 233 views
  • 5 likes
  • 4 in conversation