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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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