*** 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?
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.
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;
Actually you have too many %SYSEVALs
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.
I'n not the one who wrote the expression. I don't care if the OP multiplies by 1 or not.
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.