Sum function statement generating exponential values

Reply
Regular Contributor
Posts: 155

Sum function statement generating exponential values

Hi,

 

proc sql;
create table snp as
select sum(Amount) as amt
from tbl
group by prdct
quit;

 

When i am summing the amount when the sum value is zero it's generating exponential value. what's causing the problem

 

I have amounts like below

Amount

208990.99
547244.6
91914.11
-208990.99
-91914.11
-547244.6

 

I used round function to overcome the problem but curious what caused the problem and using the round function appropriate solution?

 

This is what i used

 

proc sql;
create table snp as
select round(sum(Amount),0.01)  as amt
from tbl
group by prdct
quit;

Esteemed Advisor
Posts: 7,302

Re: Sum function statement generating exponential values

My guess is that you're not getting Exponential values but, rather, large numbers being shown using scientific notation.

 

If so, rather than outputing the sums, output sum(amount)/1000000 and that way you wil get the sum of number of millions.

 

Art, CEO, AnalystFinder.com

Grand Advisor
Posts: 17,464

Re: Sum function statement generating exponential values

What @art297 said, but you're getting really small numbers - ie 2.4X10^-13 or something like that? This has to do with numerical precision and how SAS can store numbers. It's a common issue in programming across all languages and more of a binary computer issue. Until we get quantam Smiley Happy

Grand Advisor
Posts: 10,251

Re: Sum function statement generating exponential values

And it may just be that the format is too small to display well.

data _null_;
   x=12345678;
   put x= best4.;
run;

Displays x as 12E6 because I told it display with only 4 columns. So the closest value SAS can display with 4 columns is the exponential.

 

Ask a Question
Discussion stats
  • 3 replies
  • 96 views
  • 2 likes
  • 4 in conversation