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 ...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.