- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
just for my edification....Do you do this for programming efficiencies?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What is the "this" you're referring to above? The suppression of the warning or the use of environment variables?
Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
that's what I was missing...these are environment variables...not macro variables...sorry for the confusion