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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
%if %sysevalf(&ratio > 0.0001 and &ratio <= 10) %then %put NOTE: Ratio in [0,10] ;
--
Paige Miller
alexgonzalez
Quartz | Level 8

I didn't try this, but it's very similar to what Tom suggested. I'm assuming it'd work too.

Many thanks,

Tom
Super User Tom
Super User

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;

alexgonzalez
Quartz | Level 8

Thanks a lot Tom, it worked :).

ballardw
Super User

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.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 748 views
  • 1 like
  • 4 in conversation