Im sure this might be an easy question that we cant see right now being in the midst of problem, but we are summing a numeric variable using a number of methods (sum function sql, proc means, data step with retain) by an id.
Looking at the raw data there appears to be nothing beyond two decimal places in the data. We confirm this after getting it in sas by taking the difference of the variable round to 2 places and the variable without rounding and get no differences between the two.
However after we sum by any of the methods and we take the difference between the rounded sum and the actual sum we are getting differences.
We cant figure out why this is happening or if we are causing it somehow.
Thanks
EJ
http://support.sas.com/techsup/technote/ts654.pdf
Eric, not sure if this is your case, but it has been long known that there could be some precision issue if 'minus' operation or summary with negative numbers involves. Please see the following example:
data _null_;
a=2.16;b=-1.17;
raw_c=sum(a,b);
round_c=round(raw_c,0.01);
put raw_c= round_c=;
if raw_c=round_c then put "equal" ; else put "not equal";
run;
They are indeed not equal to SAS if you put hex20. to check it out. The safe way to deal with it is to use round() to maintain the precision level.
Haikuo
Another approach to dealing with the problem:
Multiply all values by 100. Round to the nearest integer. Sum. Divide the sum by 100.
Precision issues are nearly nonexistent when dealing with integers.
http://support.sas.com/techsup/technote/ts654.pdf
Bingo!
Thanks everyone ... I thought it was something like that but I couldnt explain it very well but the technote was perfect
EJ
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!
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.