04-24-2018 04:40 AM
Hi everyone, I got a question about proc compare. Why two same integer values are seen different in my compared datasets ?
|| Base Compare
Obs || Tab1 Tab2 Diff. % Diff
____________ || _________ _________ _________ _________
710779 || 4761 4761 -9.09E-13 -1.91E-14
Thanks in advance.
04-24-2018 04:50 AM
This has been covered many times. SAS stores numbers in 8 bits. I can't remember the exact maths about it, but sometimes a number gets stored which has a very small tiny fraction part due to calculations, so your raw number maybe:
Utilise the round, int, floor etc. functions on it - in general in any calculation I round or otherwise fix the result to make sure. You can use the fuzz option:
But in general I would recommend fixing the number.
04-24-2018 05:55 AM
As @RW9 says this comes up all the time and there are many reference to the issue of numeric precision in the documentation including this:
Because SAS stores numerics in 8 bytes of memory / disk it can only accurately represent any number for the first 15 digits (reading left to right). PROC COMPARE is quite accurately reporting differences beyond the first 15 digits. You can control what PROC COMPARE reports as "numerically equal" by tweaking the CRITERION = and METHOD = options:
04-24-2018 12:56 PM - edited 04-26-2018 11:42 AM
One or both of those values in not an integer. The Proc compare output shows values using a default format that apparently does not want to show 12 decimal places for them.
If you think that variable should be an integer round or truncate it before use/compare.
If you don't think that a difference like 0.000000000909 will not cause problems for further use you could also run your proc compare code with the FUZZ= numericvalue option to ignore very small results.
Example fuzz= 1E-8 would treat any absolute difference lest than 0.00000001 as "good enough" and not report as a difference in the comparison.