BookmarkSubscribeRSS Feed
gabonzo
Quartz | Level 8

Here's something interesting:

%macro test(a);
	
	%if &a. >= 0 %then %put LARGER;
	%else %put SMALLER;

%mend;

%test(.75);
MLOGIC(TEST): Beginning execution.
MLOGIC(TEST): Parameter A has value .75
SYMBOLGEN: Macro variable A resolves to .75
MLOGIC(TEST): %IF condition &a. >= 0 is FALSE
MLOGIC(TEST): %PUT SMALLER
SMALLER

 

 

%test(0.75);
MLOGIC(TEST): Beginning execution.
MLOGIC(TEST): Parameter A has value 0.75
SYMBOLGEN: Macro variable A resolves to 0.75
MLOGIC(TEST): %IF condition &a. >= 0 is TRUE
MLOGIC(TEST): %PUT LARGER
LARGER

 

How can this happen in a software that is supposedly world leader in statistics and data analysis, and whose license costs thousands of dollars? HOW?

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @gabonzo,

 

Since SAS software does have all these positive attributes, you can be (almost) sure that this behavior of the SAS macro language is not a bug, but that it is intended and well documented. Here: How the Macro Processor Evaluates Arithmetic Expressions and How the Macro Processor Evaluates Logical Expressions.

 

So, if you want to feed non-integers to a macro like this, use the %SYSEVALF function in the %IF condition:

%if %sysevalf(&a. >= 0) %then ...

 

gabonzo
Quartz | Level 8
Great! Maybe they should spend less money in documentation and more in useful stuff, like, I don't know, native functions?
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
  • 2 replies
  • 974 views
  • 4 likes
  • 2 in conversation