BookmarkSubscribeRSS Feed
Fluorite | Level 6

## Rounding a Number

I have three numeric variables that I am multiplying. I get different results when I multiply them by a calculator and by SAS. Below are three variables and an example of values.

A = 4345

B = .0057

C = .40

a * b * c = x

by calculator: 4345 * 0057 *.40 = 9.9066

by SAS: 4345 * 0057 * .40 = 9.831

I believe the culprit it '0057' number. I am thinking that may be it has to with rounding so I tried but did not work. May be I am not rounding it correctly?

How would I get 9.9066 from SAS?

Thanks in advance

7 REPLIES 7
Meteorite | Level 14

## Re: Rounding a Number

Hi @SASMom2

When I run the following code, I get the result 9.9066

``````data have;
input A B C;
x = A*B*C;
datalines;
4345 .0057 .40
;
run;
``````

Could you please run a proc contents on your table to visualize the type of B and also its format?

``````proc contents data=have;
run;``````

Best,

Fluorite | Level 6

## Re: Rounding a Number

Below is the result from the Proc Content.

 1 a Num 8 2 b Num 8 F12.4 BEST12. 3 c Num 8 F12.2 BEST12.

Pyrite | Level 9

## Re: Rounding a Number

Can you post your code please, I am getting the same output as the calculator.
Fluorite | Level 6

## Re: Rounding a Number

The code is long but basically, below is calculation.

(c.avg_mship*a.acp*a.capture_rate) as Annual_Target

Meteorite | Level 14

## Re: Rounding a Number

As others have already remarked, SAS should give the same result as your calculator. There are a couple of exceptions: If your numeric variables have a length shorter than 8, which will reduce precision of the numeric variables, or if your numeric variables are not really the values displayed, but shown rounded as you see them, because a format applied to them.

So take a look at the variables in your input data: what lengths do the variables have, and what formats?

Tourmaline | Level 20

## Re: Rounding a Number

Your code does not do what you say.

``````data HAVE;
input A B C;
X = A*B*C;
putlog X=;
datalines;
4345 .0057 .40
;
run;
``````

X=9.9066

Tourmaline | Level 20

## Re: Rounding a Number

``````proc sql;
select A*B*C 'P' from  HAVE;
quit;
``````
P
9.9066
Discussion stats
• 7 replies
• 759 views
• 0 likes
• 5 in conversation