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?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 358 views
  • 4 likes
  • 2 in conversation