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

Dear all,

 

I have a table with two columns as listed below:

Col_1Col_2
0.2-0.2

 

I then use an extract field and I create a calculated field "Col_3", which has the following expression

Col_1 + Col_2

 

The result of the addition should be equal to zero (0).

Instead, the following value is produced: 2.6841454E21

 

I have already tried to round the value, but nothing is happening.

Furthermore, when I use format and informat (which is something that I do not want, but after trying to troubleshoot the problem), a negative zero value is displayed.

 

Does anyone have any clue about this?

 

Thanks in advance,

Vasileios

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

This is roundoff error, and there's really no way to avoid this using computers. The problem is the 0.2 cannot be represented exactly as a string of 0s and 1s (which is how computers represent numbers).

 

If you really want a zero there, you can use the FUZZ() function.

 

if fuzz(col_1+col_2)=0 then col_3=0;
else col_3=col_1+col_2;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

This is roundoff error, and there's really no way to avoid this using computers. The problem is the 0.2 cannot be represented exactly as a string of 0s and 1s (which is how computers represent numbers).

 

If you really want a zero there, you can use the FUZZ() function.

 

if fuzz(col_1+col_2)=0 then col_3=0;
else col_3=col_1+col_2;
--
Paige Miller
novinosrin
Tourmaline | Level 20

I was watching a documentary the other day that was about the same reason for Warren Buffet not to trust computers in general 🙂 

PaigeMiller
Diamond | Level 26

@novinosrin wrote:

I was watching a documentary the other day that was about the same reason for Warren Buffet not to trust computers in general 🙂 


According to Mr. Buffet, is there a method that does not contain the possibility of error, and would be preferable?

--
Paige Miller
ballardw
Super User

@PaigeMiller wrote:

@novinosrin wrote:

I was watching a documentary the other day that was about the same reason for Warren Buffet not to trust computers in general 🙂 


According to Mr. Buffet, is there a method that does not contain the possibility of error, and would be preferable?


I would add:

 

And can be done in an acceptable amount of time.

 

Pencil and paper with a properly trained person can do anything a computer can. It just takes time.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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