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?
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 ...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.