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

Dear Members,

 

I have encountered a problem while computing sum and mean in SAS for particularly a set of four numbers (0.3, -0.2, -0.1, 0). While I pass these numbers to Proc means the output gives sum as -2.77556E-17 and mean as -6.93889E-18. While actually the sum should be zero and hence the mean should be zero.

 

I have also tested with different order combination of above 4 numbers (there are 24 combination of arranging different order) where for some of the combination I am getting sum as -5.55112E-17 and mean as -1.38778E-17. The same problem occurs in Proc Summary, even tested with Proc GLM, PROC mixed, which gives different answers in LSmeans.

 

But Proc Univariate gives the correct result with mean and sum as zero.

 

If any one can give some insight what is happening with this four magic numbers. Also I have cross checked with Excel and R and facing the same problem for different order combination of above 4 numbers.

 

PS Attached PROC MEANS and PROC UNIVARIATE output for reference.

 

Kind Regards,

Rajesh kumar  

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I expect your hitting floating point storage issues as the resulting number is very small:

See Numerical Accuracy in SAS Numbers.

 

Just make sure you round values.

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I expect your hitting floating point storage issues as the resulting number is very small:

See Numerical Accuracy in SAS Numbers.

 

Just make sure you round values.

rajclin
Calcite | Level 5

Many thanks for your quick response!!!

rajclin
Calcite | Level 5
This link gives detailed information Thank you!!!
Kurt_Bremser
Super User

This is the typical artifact of the conversion of decimal fractions to binary. Do a google search for "SAS numerical precision", and you'll find ample information about what happens behind the scenes, and why it does.

 

Whenever you work with fractions in SAS, and you need to get a "clean" value for comparisons or such, use the round() function to get rid of the artifacts. Some procedures to that automatically (using "fuzz" factors), others need "manual" intervention.

 

Note that this is not specific to SAS, but happens in all software that uses real formats for numbers.

rajclin
Calcite | Level 5
Thank you for your detailed response!!!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1180 views
  • 1 like
  • 3 in conversation