Hi there,
I am creating a macro and the apply a condition. The macro variable is correctly calculated it is not well evaluated in the condition. See below a piece of the code and the log.
*Calculating the ratio E/U2;
data _null_;
set data;
call symputx ('E',a_var_e);
call symputx ('U2',a_var_u2);
run;
%let ratio = %sysevalf(&E/&U2);
%if &ratio > 0.0001 and &ratio <= 10 %then %put NOTE: Ratio in [0,10] ;
%else %put ERROR: Ratio not in [0,10], consider removing extreme observations;
The log.
MLOGIC(ROOT_ESTIMATES): %LET (variable name is RATIO)
SYMBOLGEN: Macro variable E resolves to 0.1937225404
SYMBOLGEN: Macro variable U2 resolves to 0.0813614747
SYMBOLGEN: Macro variable RATIO resolves to 2.3810106824428
SYMBOLGEN: Macro variable RATIO resolves to 2.3810106824428
MLOGIC(ROOT_ESTIMATES): %IF condition &ratio > 0.0001 and &ratio <= 10 is FALSE
MLOGIC(ROOT_ESTIMATES): %PUT ERROR: Ratio not in [0,10], consider removing extreme observations
ERROR: Ratio not in [0,10], consider removing extreme observations
Any idea how to solve this issue?
Thanks a lot.
You need to keep using %SYSEVALF() if you want to compare floating point values.
%let ratio = %sysevalf(&E/&U2);
%if %sysevalf(&ratio > 0.0001) and %sysevalf(&ratio <= 10) %then %put NOTE: Ratio in [0,10] ;
%else %put ERROR: Ratio not in [0,10], consider removing extreme observations;
%if %sysevalf(&ratio > 0.0001 and &ratio <= 10) %then %put NOTE: Ratio in [0,10] ;
I didn't try this, but it's very similar to what Tom suggested. I'm assuming it'd work too.
Many thanks,
You need to keep using %SYSEVALF() if you want to compare floating point values.
%let ratio = %sysevalf(&E/&U2);
%if %sysevalf(&ratio > 0.0001) and %sysevalf(&ratio <= 10) %then %put NOTE: Ratio in [0,10] ;
%else %put ERROR: Ratio not in [0,10], consider removing extreme observations;
Thanks a lot Tom, it worked :).
If the only purpose of the test of the value is place a note in the log then do it in the data step.
data _null_;
set data;
call symputx ('E',a_var_e);
call symputx ('U2',a_var_u2);
if not ( 0.000 1< a_var_e / a_var_u2 le 10) then put " NOTE: Ratio in [0,10] ";
else put " ERROR: Ratio not in [0,10], consider removing extreme observations";
run;
If you are not using the macro variables E and U2 for anything else then don't create them and just use the PUT in the data _null_.
If you have other uses for the comparison then you would be better off creating a flag or status macro variable with values of 1 or 0 (true/ false) from the ratio.
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 lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.