BookmarkSubscribeRSS Feed
eagles_dare13
Obsidian | Level 7

   When I run this progrma:

data _null_;
   set info1;
   if compress(upcase(a),'','cops') eq 'abc' then call symputx('macro_var1',b,'g'); /*if condition evaluates to false*/
 
  run;

    %put Macro var1 is: &macro_var1;
   


I get Output:
Macro var1 is: &macro_var1

I was expecting output:
Macro var1 is:

i.e. the macro variable should be set to a null (blank) value. Why did the macro variable value get set to the name of the macro?
The dataset info1 looks like (2 by 2 matrix):

Name   user12
Salary 100

3 REPLIES 3
ballardw
Super User

I can't duplicate this. I suspect that at some point in testing this you accidentally set the value.

Try adding

%let macro_var1=;

before your data step and see if that still happens;

Tom
Super User Tom
Super User

Since the IF condition is false the CALL SYMPUT does not run so the macro variables value is not changed.

You are just seeing the value that it had before the data step ran.

SusanHaller
SAS Employee

Both responders above have hit the nail on the head.  As your if condition is false, the call symput code is never run and thus your code never initializes the new macro variable macro_var1.   Without initializing, it is an unknown macro variable when the put statement is run.  When this occurs, the put statement simply outputs the unknown macro variable name.

This can be quickly solved by first initializing the macro variable:

%let macro_var1=;

data _null_;

   set info1;

   if compress(upcase(a),'','cops') eq 'abc' then call symputx('macro_var1',b,'g'); /*if condition evaluates to false*/ 

run;

%put Macro var1 is: &macro_var1;

Or by setting the variable with another symput statement when the condition is true.

data _null_;

   set info1;

   if compress(upcase(a),'','cops') eq 'abc' then call symputx('macro_var1',b,'g'); /*if condition evaluates to false*/ 

   else call symputx('macro_var1','new value','g'); /*if condition evaluates to true*/

run;

%put Macro var1 is: &macro_var1;

In either case, the macro variable will always be a known variable.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 933 views
  • 2 likes
  • 4 in conversation