- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- 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
- 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