BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Vimal_SAS
Calcite | Level 5

*** Test macro ***;

%macro test;

%if (%sysevalf(&a*1) <= %sysevalf(&b*1)) %then %do;

%put %sysevalf(&a*1) IS LESS THAN OR EQUAL TO %sysevalf(&b*1);

%end;

%else %do;

%put %sysevalf(&a*1) GREATER THAN %sysevalf(&b*1);

%end;

%mend test;

%let a=10.6;

%let b=9.9;

%test;

%let a=9.9;

%let b=10.6;

%test;


These two macro calls give me a wrong answer. Can anyone help me out from this?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Also note, once you have the proper number of %sysevalf functions,  you do not need to multiply by 1.

%if 9.9 < 10.6 is false because decimal points force a character comparison, but

%if %syseval(9.9 < 10.6) returns 1, a true comparison.

View solution in original post

4 REPLIES 4
Reeza
Super User

Your comparison is also a function, so add one more %sysevalf:

%macro test;

%if (%sysevalf(%sysevalf(&a*1) <= %sysevalf(&b*1))) %then %do;

%put %sysevalf(&a*1) IS LESS THAN OR EQUAL TO %sysevalf(&b*1);

%end;

%else %do;

%put %sysevalf(&a*1) GREATER THAN %sysevalf(&b*1);

%end;

%mend test;

%let a=10.6;

%let b=9.9;

%test;

%let a=9.9;

%let b=10.6;

%test;

data_null__
Jade | Level 19

Actually you have too many %SYSEVALs

%macro test;
  
%let rc = %sysevalf(&a*1 <= &b*1,boolean);
   %put NOTE: &=rc;
   %let tf = %scan(False True,%eval(&rc+1));
   %put NOTE: Expression &a*1 <= &b*1 is &tf;
   %mend test;

%let a=10.6;
%let b=9.9;
%test;

%let a=9.9;
%let b=10.6;
%test;

40         %let a=10.6;
41         %let b=9.9;
42         %test;
NOTE: RC=
0
NOTE: Expression
10.6*1 <= 9.9*1 is False
43        
44         %let a=9.9;
45         %let b=10.6;
46         %test;
NOTE: RC=
1
NOTE: Expression
9.9*1 <= 10.6*1 is True
Astounding
PROC Star

Also note, once you have the proper number of %sysevalf functions,  you do not need to multiply by 1.

%if 9.9 < 10.6 is false because decimal points force a character comparison, but

%if %syseval(9.9 < 10.6) returns 1, a true comparison.

data_null__
Jade | Level 19

I'n not the one who wrote the expression.  I don't care if the OP multiplies by 1 or not.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 836 views
  • 3 likes
  • 4 in conversation