ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 43

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

18 comments:

  1. Anonymous10:11 AM

    mean(of num1 - num4);

    ReplyDelete
  2. Anonymous6:04 AM

    what is wrong with D

    ReplyDelete
    Replies
    1. you should have comma between each numeric variables. ie. average=mean(num1,num2,num3,num4)

      Delete
  3. good question ....D is incorrect as commas or OF is missing ...correct forms could be

    average = mean(num1, num2, num3 ,num4);

    Or

    average = mean(OF num1 num2 num3 num4);

    ReplyDelete
  4. Anonymous3:54 PM

    Function mean Syntax is

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

    ReplyDelete
  5. Anonymous10:18 PM

    SAS 9.3, Running program below returns both B and C with correct answer.

    data 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;

    ReplyDelete
    Replies
    1. Option C wont give the desired o/p,

      averageC = 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)

      Delete
  6. Anonymous10:32 PM

    SAS 9.3, I made an error above. "B" is the only correct answer

    The 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'

    ReplyDelete
  7. Anonymous10:34 PM

    FYI. this also also fixes "D"

    ...
    also_fixed_averageD = mean(of var1 var2 var3 var4); /* added of, no commas */
    ...

    ReplyDelete
  8. It can be either mean (of var1, var2, var 3, var4)
    or mean (var1, var2, var 3, var4) or mean (of var1-var4) but can not be mean (of var1 to var4) or mean (var1-var4)

    ReplyDelete