BookmarkSubscribeRSS Feed
SASMom2
Fluorite | Level 6

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
ed_sas_member
Meteorite | Level 14

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,

 

SASMom2
Fluorite | Level 6

Below is the result from the Proc Content.

 

1aNum8  
2bNum8F12.4BEST12.
3cNum8F12.2BEST12.

 

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

The code is long but basically, below is calculation.

 

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

s_lassen
Meteorite | Level 14

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?

ChrisNZ
Tourmaline | Level 20

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

 

ChrisNZ
Tourmaline | Level 20
proc sql;
  select A*B*C 'P' from  HAVE;
quit;
P
9.9066

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1041 views
  • 0 likes
  • 5 in conversation