In a macro program, if, then statement, you have to use %if %then
but following macro program it says:
ERROR: Required operator not found in expression: symlocal('c')
ERROR: The macro TEST will stop executing.
Rather, if, then statement works,
I can't wrap my head around it.
%let c=yes;
%macro test;
%let d=yes;
data _null_;
%if symlocal('c') %then %put '**** c a is local';
%else %put '**** c is global';
if symlocal ('d') then put '**** d is local';
else put '**** d is global';
run;
%mend test;
%test
Macro is a text processing facility and so you don't quote character strings. Plus it need not run in a data step. See:
%let c=yes;
%macro test;
%let d=yes;
%if %symlocal(c) %then %put **** c a is local;
%else %put **** c is global;
run;
%mend test;
%test
Also note that sumlocal is both a macro function and not a data step function. So you need to use %symlocal when running it as macro code.
If you are new to macro I would suggest that you do a Google search for any papers by Ian Whitlock on the macro facility. His papers do a great job of explaining the background behind why what you tried did not work.
Well, it confuses me because I don't know how to tell if it is macro variable or data step variable.
The example in my question is from: http://www2.sas.com/proceedings/sugi31/107-31.pdf
originally it is written like this:
%let c=yes;
%macro test;
%let d=yes;
data _null_;
if symlocal('c') then put '**** c a is local';
else put '**** c is global';
if symlocal ('d') then put '**** d is local';
else put '**** d is global';
run;
%mend test;
%test
so, you see, c and d are quoted in the symlocal function, and in the macro, %if %then statement are not used but only if then, it confuses me.
Can someone help explain?
Actually, unless you changed the original, you had them mixed (i.e., used symlocal once and %symlocal once.
I agree with Don that Ian's papers would be a good way to start. If you are serious about wanting to learn, I have a spreadsheet that contains links to all of his SAS-L posts.
In the meantime, here is a different mixture that all work:
%let c=yes;
%macro test;
%let d=yes;
%if %symlocal(c) %then %put '**** c a is local';
%else %put '**** c is global';
data _null_;
%if %symlocal(c) %then %put '**** c a is local';
%else %put '**** c is global';
if symlocal ('d') then put '**** d is local';
else put '**** d is global';
run;
%mend test;
%test
Hi, Art297,
Can you please share the links you have? I really love to check it out.
Send me an email at atabachneck at gmail dot com. I can't post it here because Ian never gave me permission to post it on the web. I wish he would, because there are numerous gold nuggets in those posts.
Are you going to email me too if I ask for it? Thanks - Linlin
Sure, just send me an email. I don't have any problem sharing the spreadsheet, I just don't feel comfortable putting it on the web without Ian's permission.
Thank you! I just emailed you. - Linlin
Fantastic, I just sent an email to you, really appreciate your help, Art
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.