create a macro only with macro variables creation

2019-09-19 18:53发布

问题:

Hi I was trying to create a macro that only contains macro variable creation but it failed. Here is an example:

%macro createvariable; 
    %let a = 5;
    %let b = 6;
%mend createvariable;
%createvariable; 

data test; 
    c = &a + &b;
run;

But it will work as:

%macro createvariable; 
    %let a = 5;
    %let b = 6;
data test; 
    c = &a + &b;
run;
%mend createvariable;
%createvariable; 

So I was wondering if SAS won't be able to create a macro with only macro variables creation in it? Or there is a way to solve this problem. Thanks.

回答1:

Try

%macro createvariable; 
%global a b;
    %let a = 5;
    %let b = 6;
%mend createvariable;
%createvariable; 

data test; 
    c = &a + &b;
run;


标签: macros sas