Hi,
Is there a way to either conditionally execute %sysget, or unconditionally execute it without causing a warning message?
For example, with macro variables:
%macro foo;
%if (%symexist(foo)) %then %do;
%if (&foo eq BAR) %then
%put BAR;
%else
%put BLAH;
%end;
%end;
%mend;
Also, NOSERROR can come in handy sometimes to suppress warnings about unresolved macro variables.
So, analogously:
%macro foo;
%if %sysexist(foo) %then %do; * the mythical %sysexist function ;
%let foo=%sysget(foo);
%if (&foo eq BAR) %then
%put BAR;
%else
%put BLAH;
%end;
%end;
%mend;
I'd kinda think a %sysexist function, paired with %sysget, would be a no-brainer for SAS by now???
Cheers,
Scott
Are you running SAS 9.3 ? Use SYSEXIST function
SAS(R) 9.3 Functions and CALL Routines: Reference
%macro foo;
%if %sysfunc(sysexist(foo)) %then %do; * the mythical %sysexist function ;
%let foo=%sysget(foo);
%if (&foo eq BAR) %then
%put BAR;
%else
%put BLAH;
%end;
%end;
%mend foo;
not to be too simplistic...but if you've set NOSERROR, then doesn't this work?
%if "&foo"="BAR" %then %put BAR;
%else %put BLAH;
Are you running SAS 9.3 ? Use SYSEXIST function
SAS(R) 9.3 Functions and CALL Routines: Reference
%macro foo;
%if %sysfunc(sysexist(foo)) %then %do; * the mythical %sysexist function ;
%let foo=%sysget(foo);
%if (&foo eq BAR) %then
%put BAR;
%else
%put BLAH;
%end;
%end;
%mend foo;
Doh! I guess I should read the "What's New in SAS 9.3" documentation! I was looking under the macro documentation for %sysexist to pair up with %sysget.
To SAS: I do think %sysexist would be useful, to add "symmetry" to these functions:
Data Step:
symexist --> symget
sysexist --> sysget
Macro:
%symexist --> %symget doesn't make sense here, just reference the ¯ovariable
%sysexist --> %sysget
Thanks a lot Tom, I always appreciate your insights.
just for my edification....Do you do this for programming efficiencies?
What is the "this" you're referring to above? The suppression of the warning or the use of environment variables?
that's what I was missing...these are environment variables...not macro variables...sorry for the confusion
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.