user3308222
user3308222

Reputation: 41

SAS Macro execution

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?

Upvotes: 4

Views: 99

Answers (2)

DomPazz
DomPazz

Reputation: 12465

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

Upvotes: 5

Tim Sands
Tim Sands

Reputation: 1068

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.

Upvotes: 1

Related Questions