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.
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:
4761
vs
4761.000000000000001
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.
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:
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.
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.
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.