DATA Step, Macro, Functions and more

Executing %sysget without generating an error?

Accepted Solution Solved
Reply
Super Contributor
Posts: 387
Accepted Solution

Executing %sysget without generating an error?

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


Accepted Solutions
Solution
‎02-07-2013 12:06 PM
Super User
Super User
Posts: 7,076

Re: Executing %sysget without generating an error?

Posted in reply to ScottBass

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


All Replies
Super Contributor
Posts: 578

Re: Executing %sysget without generating an error?

Posted in reply to ScottBass

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;

Solution
‎02-07-2013 12:06 PM
Super User
Super User
Posts: 7,076

Re: Executing %sysget without generating an error?

Posted in reply to ScottBass

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;

Super Contributor
Posts: 387

Re: Executing %sysget without generating an error?

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.

Super Contributor
Posts: 578

Re: Executing %sysget without generating an error?

Posted in reply to ScottBass

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

Super Contributor
Posts: 387

Re: Executing %sysget without generating an error?

What is the "this" you're referring to above?  The suppression of the warning or the use of environment variables?

Super Contributor
Posts: 578

Re: Executing %sysget without generating an error?

Posted in reply to ScottBass

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 608 views
  • 0 likes
  • 3 in conversation