DATA Step, Macro, Functions and more

Automatic Rounding

Reply
Contributor
Posts: 55

Automatic Rounding

Hi,

 

In the code below, the SAS base application in our office displays the values in 'displayed' column when a is divided by b, then multiplied to 100, even if we made the format best32. However, the calculator gives longer values. 

 

But when I tried doing the division in the "want" dataset in SAS Studio (SAS base on demand), the division works fine. 

 

Can the automatic rounding of SAS be fixed?

 

 

 

data have;
input a b displayed;
cards;
16854.17 197890.028 8.5169375
819368.85 369280 221.8828125
150914.35 255027.6243 59.1756875
226253.24 858790.6977 26.3455625
100876.91 363464.5669 27.7542625
14788.51 777104.3771 1.9030275
;
run;

data want;
set have;
d = (a/b)*100;
run;

 

 

Super User
Posts: 19,855

Re: Automatic Rounding

Posted in reply to angeliquec

Can you post the numbers you want to see?

What version of SAS are you working on?

 

Most likely it's related to numerical precision:

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t...

Contributor
Posts: 55

Re: Automatic Rounding

Posted in reply to angeliquec
Hi Reeza,

We're using 9.4. The numbers I want are those under column d in the want dataset, which have more precision
Respected Advisor
Posts: 4,930

Re: Automatic Rounding

Posted in reply to angeliquec

Try

 


proc print data=want;
format d 20.10;
run;
PG
Contributor
Posts: 55

Re: Automatic Rounding

Posted in reply to angeliquec
Hi Reeza

Apologies, we are using SAS 9.0.
Is there a way to address this precision issue?
Super User
Posts: 19,855

Re: Automatic Rounding

Posted in reply to angeliquec

I doubt you're using 9.0...that would be akin to using Windows XP version 1, not even SP4.

 

What do you get from:

%put &sysver;

 

 

Contributor
Posts: 55

Re: Automatic Rounding

Posted in reply to angeliquec
sorry, 9.4.

For the first row in the have data, SAS gives a quotient of 8.516937500000 when the actual answer is 8.5163749995668. SAS seems to do truncation there.
Super Contributor
Posts: 345

Re: Automatic Rounding

Posted in reply to angeliquec

Interesting, win7 calculator returns 8.5169374982351308778429199070102 for the first row.

 

With format 20.10 applyed to variable d, SAS returns 8.5169374982 - SAS on Windows and Linux uses up to 15 digits. I don't think that value can be increased by altering a config file or by setting a sas system option.

Ask a Question
Discussion stats
  • 7 replies
  • 455 views
  • 1 like
  • 4 in conversation