4
votes

I'm trying to call macros at run-time based on the inputs provided.

the macro execution step will be like below

%(&macrovariable);

whereas the value of the macrovariable will be provided at run time.

is this possible or is there any way of acheiving this?

2

2 Answers

5
votes

Easy.

%macro test(a);
%put Test says &a;
%mend;

%let mymacro = test;

%&mymacro(Hello World);

Returns

8239   %macro test(a);
8240   %put Test says &a;
8241   %mend;
8242
8243   %let mymacro = test;
8244
8245   %&mymacro(Hello World);
Test says Hello World
1
votes

There might be another way, but you could use CALL EXECUTE after a null data step like:

data _null_;
    CodeToRun = cats('%',"&MyMacroName");
    Call Execute (CodeToRun);
run;

Some background and examples on CALL EXECUTE here.