Reputation: 79
I'm trying to set a macro variable using an if then statement using SAS programming language but using WPS (World Programming System), which is basically a SAS clone, but for some reason it's not working.
%if 1=1 %then %do;
data test;
a=111;
run;
%let a=2;
%end;
%put &a.;
I get this message after the put statement:
WARNING: Macro variable "&a" was not resolved
However, the test dataset was successfully created. Is this just a WPS specific problem, or does the same error occur in SAS as well?
Update: I tried running the above code within a macro, but I still get the same error message:
%macro test_macro();
%if 1=1 %then %do;
data test;
a=111;
run;
%let a=2;
%end;
%mend;
%test_macro();
%put &a.;
Upvotes: 0
Views: 241
Reputation: 51581
If you don't tell the macro processor that you want A to be a global macro symbol it will be made in the local macro symbol table.
Either define A before calling the macro:
%let a=before macro call;
%test_macro();
%put &a.;
Or add a %GLOBAL statement inside the macro definition.
%macro test_macro();
%global a;
...
Upvotes: 2