DATA Step, Macro, Functions and more

Compare Numbers between variable MACRO

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

Compare Numbers between variable MACRO

Hi all,

I'm trying to compare two variables macro (price_trd vs max_price) however as the example below that's not happening....

Please someone could give me a little help ?

TK'S IN ADVANCED!

########## CODE BELOW #########

options mlogic mprint;

%let price_trd = 93.68;

%put &price_trd.;

%let max_price = 100.94;

%put &max_price.;

%macro test;

  %if  &price_trd. < &max_price %then %do;

  %put Pass HERE;

  %end;

%mend;

%test;


Accepted Solutions
Solution
‎02-18-2014 04:17 PM
Super User
Super User
Posts: 7,080

Re: Compare Numbers between variable MACRO

Need to use %SYSEVALF() to do floating point calculations, otherwise macro will attempt to use %EVAL() which only does integer math.

View solution in original post


All Replies
Solution
‎02-18-2014 04:17 PM
Super User
Super User
Posts: 7,080

Re: Compare Numbers between variable MACRO

Need to use %SYSEVALF() to do floating point calculations, otherwise macro will attempt to use %EVAL() which only does integer math.

Super User
Posts: 19,877

Re: Compare Numbers between variable MACRO

Wrap the comparison in %sysevalf

E.G.

  %if  %sysevalf(&price_trd. LT &max_price) %then %do;

As always in the fine print (floating point arithmetic vs integer for %eval).

SAS(R) 9.2 Macro Language: Reference

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 301 views
  • 5 likes
  • 3 in conversation