BookmarkSubscribeRSS Feed
SP_SAS
Obsidian | Level 7

Hi There,

If I run the below data step I see SAS behaving in strange manner. Variable y resolves to 1.2. SAS thinks x(1.2) is less than y. Any help will be appreciated.

Thanks,

Santosh

data aa;

x=1.2;
y=(1.1+1*0.1);
if x<y then Confused="Yes";
else Confused="No";
run;

4 REPLIES 4
PGStats
Opal | Level 21

SAS numbers are represented internally by floating point values. 1.2 doesn't have an exact representation as a floating point number, so its internal value is an approximation. That approximation will take different values depending on how it was arrived at. Add the following statements and see what happens

if round(x, 0.1) < round(y, 0.1) then RoundConfused="Yes";

else RoundConfused="No";

PG

PG
Tom
Super User Tom
Super User

Use the HEX16. format to look at how these two different numbers end up getting stored into the 8 byte IEEE floating point format.

data aa;

x=1.2;

y=(1.1+1*0.1);

put  (x y) (= hex16. /) ;

x=round(x,0.1);

y=round(y,0.1);

put / (x y) (= hex16. /) ;

run;

x=3FF3333333333333

y=3FF3333333333334

x=3FF3333333333333

y=3FF3333333333333

run;

SP_SAS
Obsidian | Level 7

Thanks to you all for your quick help.

Santosh

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1646 views
  • 4 likes
  • 4 in conversation