BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ScottBass
Rhodochrosite | Level 12

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.
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

6 REPLIES 6
DBailey
Lapis Lazuli | Level 10

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;

Tom
Super User Tom
Super User

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;

ScottBass
Rhodochrosite | Level 12

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 &macrovariable

%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.
DBailey
Lapis Lazuli | Level 10

just for my edification....Do you do this for programming efficiencies?

ScottBass
Rhodochrosite | Level 12

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.
DBailey
Lapis Lazuli | Level 10

that's what I was missing...these are environment variables...not macro variables...sorry for the confusion

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2500 views
  • 1 like
  • 3 in conversation