Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Rounding a Number

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-12-2020 05:29 AM
(758 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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,

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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. |

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The code is long but basically, below is calculation.

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

How to Concatenate Values

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.