BookmarkSubscribeRSS Feed
teja04
Calcite | Level 5
Hi All, I have two numeric variables A & B, each variable length is 8. For example, two variables have same values. When I was subtracting
2985014.3137841 - 2885014.3137841
I am getting the value -4.65661E-10. Does anyone
have any ideaa why it is showing such value instead of '0'.
8 REPLIES 8
novinosrin
Tourmaline | Level 20
data diff;
a=2985014.3137841 ;
b=2985014.3137841;
dif=a-b;
run;

proc print noobs;run;

SAS Output

The SAS System

a b dif
2985014.31 2985014.31 0
PGStats
Opal | Level 21

The two number are not equal, they are just displayed as equal. A -4E-10 difference is not visible when you display only 7 decimals. See @novinosrin's demonstration above.

PG
teja04
Calcite | Level 5
Thank you novinosrin and PGStats. I have tried this.. but the problem was other values have different decimals. Maximum decimals I am having is 8. I am not supposed to use ROUND function.
PGStats
Opal | Level 21

Why do you expect the difference to be zero?

PG
Kurt_Bremser
Super User

@teja04 wrote:
I am not supposed to use ROUND function.

Don't be an idiot. The tool for removing such artifacts of SAS numerical precision issues is the round() function, so use it. See Maxim 14.

teja04
Calcite | Level 5
Okay.. I got your point. Can't we display the numeric value other than -4E-10 value.
Reeza
Super User
Sure, just format it and it will look like a zero.

format diff 8.2;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 8 replies
  • 1724 views
  • 0 likes
  • 5 in conversation