Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
150 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...