SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Jumboshrimps
Quartz | Level 8

Have two servers - PROD & TEST.  I often flip between developing on TEST, and running production code on PROD on PC SAS 9.4

Signon is done at the top of the code as below.                                                                                                                                                                                                                                                                           

OPTIONS netencralg=SASProprietary;                                                                                                                                              
OPTIONS COMAMID= tcp remote                                                                                                                                                                                    

Enter my credentials  - same for PROD and TEST                                                                                                               

I can alter data all day long on TEST, but not PROD, of course. Should I mix those two up, that would a problem.  Lib names are exactly the same for both.

I decided to write a short macro and place it in the SAS startup directory. thinking I would run the macro before any long code that updates data sets.                                                                                                                                                 

 

%macro server;

%if &mynode = 'longstringofletters_numbers'
%then

%put ' TEST Server';
%else
%put ' PROD Server';

%mend;

 

I use %put &mynode, which displays the server name.  I then cut-and-paste that into the macro.

Result always defaults to PROD, even though the string for the server is TEST.

                                                                                                                                                                                

I tried to use like instead of "=", but I get the following error:

 A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required.

 

There are no special characters in server name.  Used the "%" in the beginning and end of the server name, did not  help.

Where did I go wrong?

 

1 REPLY 1
Quentin
Super User

If the value of &mynote is a lon string of letters and numbers without quotation marks around them, then you don't want quotation marks around the value on your %IF statement.  The macro language does not use quotation marks to indicate text values, because every value is a text value in the macro language.  Similarly, you don't need quotation marks on your %PUT statements.  Try:

 

%macro server;

  %if &mynode = longstringofletters_numbers
  %then
  %put TEST Server;
  %else
  %put PROD Server;

%mend;
The Boston Area SAS Users Group is hosting free webinars!
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1 reply
  • 299 views
  • 0 likes
  • 2 in conversation