Which one of the following SAS statements correctly computes the average of four numerical values?
A. average = mean(num1 - num4);
B. average = mean(of num1 - num4);
C. average = mean(of num1 to num4);
D. average = mean(num1 num2 num3 num4);
Click Comment link to get answer
B
ReplyDeleteB
ReplyDeletemean(of num1 - num4);
ReplyDeletewhat is wrong with D
ReplyDeleteyou should have comma between each numeric variables. ie. average=mean(num1,num2,num3,num4)
Deletegood question ....D is incorrect as commas or OF is missing ...correct forms could be
ReplyDeleteaverage = mean(num1, num2, num3 ,num4);
Or
average = mean(OF num1 num2 num3 num4);
thanks for explanation
Deletenice one
Deletethanks
DeleteFunction mean Syntax is
ReplyDeleteavg=Mean(x, y, z);
avg=Mean(of x1-x10);
avg=Mean(of x y z);
Answer B. average = mean(of num1 - num4);
The problem with the D is the coma between the variable.
SAS 9.3, Running program below returns both B and C with correct answer.
ReplyDeletedata work.sasbase43;
var1 = 1;
var2 = 2;
var3 = 3;
var4 = 4;
averageA = mean(var1 - var4);
averageB = mean(of var1 - var4);
averageC = mean (of var1 to var4);
/*averageD = mean(var1 var2 var3 var4); **error** */
run;
Option C wont give the desired o/p,
DeleteaverageC = mean (of var1 to var4);
Here, SAS considers
Var1 as 1stVAR
to as 2ndVAR with missing values (Hence, not included in statistic)
Var4 as 3rdVAR
Gives mean of 1+4/2 = 2.5 (as per your values)
change var1=10;
than mean of 10+4/2 = 7 (as per new value)
SAS 9.3, I made an error above. "B" is the only correct answer
ReplyDeleteThe problem with "C" is that "to" variable is created with "." no data; and because of my choice of test values, the error was obscured.
Please see this program instead:
data work.sasbase43;
var1 = 5;
var2 = 5;
var3 = 5;
var4 = 100;
averageA = mean(var1 - var4);
averageB = mean(of var1 - var4);
averageC = mean (of var1 to var4); /* creates empty var named "to" */
/*averageD = mean(var1 var2 var3 var4); **error missing commas** */
fixed_averageD = mean(var1, var2, var3, var4); /* added commas*/
run;
Again, The correct answer is 'B'
FYI. this also also fixes "D"
ReplyDelete...
also_fixed_averageD = mean(of var1 var2 var3 var4); /* added of, no commas */
...
It can be either mean (of var1, var2, var 3, var4)
ReplyDeleteor mean (var1, var2, var 3, var4) or mean (of var1-var4) but can not be mean (of var1 to var4) or mean (var1-var4)
B
ReplyDeleteB
ReplyDeleteB
ReplyDelete