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
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,
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. |
The code is long but basically, below is calculation.
(c.avg_mship*a.acp*a.capture_rate) as Annual_Target
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?
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.