ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 51

A raw data file is listed below:
--------10-------20-------30
squash 1.10
apples 2.25
juice 1.69
The following SAS program is submitted using the raw data file above:
data groceries;
infile 'file-specification';
input item $ cost;

run;
Which one of the following completes the program and produces a grand total for all COST values?
A. grandtot = sum cost;
B. grandtot = sum(grandtot,cost);
C. retain grandtot 0;
grandtot = sum(grandtot,cost);
D. grandtot = sum(grandtot,cost);
output grandtot;
Click Comment link to get answer

47 comments:

  1. Anonymous12:26 PM

    sorry ans is C

    ReplyDelete
  2. Anonymous10:51 AM

    Answer is A

    ReplyDelete
  3. Anonymous10:45 PM

    Can Those FUkin stupid guys who are not sure about their answers stop stupidly answering??? Those shabi answers really confused me a big lot!!!!

    ReplyDelete
    Replies
    1. Anonymous12:25 PM

      Those ppl don't know they are wrong until they know what is actually right. So you Mr. Asshole keep ur mouth and ass shut and type for your own self and not for others or about others. If ur problem is solved , good for you. If not, go to some other blog. We are not here for you. Infact, you are here for us seeking our help! Bingo !

      Delete
    2. Anonymous4:53 AM

      U r so rude. Shame on u.

      Delete
    3. Anonymous4:25 PM

      Shame on you... Others are here for help, but not owe.

      Delete
    4. This comment has been removed by the author.

      Delete
    5. Bro, calm down... and are you sure they neng kan ming bai what shabi is?(huaji~)

      Delete
  4. Anonymous8:07 PM

    lol shabi

    ReplyDelete
  5. Anonymous3:52 PM

    Can some one please explain which one is correct. thanks

    ReplyDelete
  6. Anonymous4:57 PM

    sum is a function which means it will need brackets () so A is not the correct answer.

    There no such variable as grandtot, so program will give syntax error, so option B and D is not the correct answer.

    C is the correct option because retain statement is creating a new variable and initializing it with zero. Sum function will add cost to grandtot for each observation and as grandtot is retained it will carry forward the added value.

    Hope this helps.

    ReplyDelete
    Replies
    1. Anonymous4:51 PM

      Nice Explanation..!! It really helpful.

      Delete
    2. Anonymous4:26 PM

      Thanks a lot

      Delete
    3. Anonymous11:22 AM



      Sum Statement

      Adds the result of an expression to an accumulator variable.


      Syntax
      variable+expression;




      variable

      specifies the name of the accumulator variable, which contains a numeric value.
      Tip: The variable is automatically set to 0 before SAS reads the first observation. The variable's value is retained from one iteration to the next, as if it had appeared in a RETAIN statement.
      Tip: To initialize a sum variable to a value other than 0, include it in a RETAIN statement with an initial value.
      expression

      is any SAS expression.
      Tip: The expression is evaluated and the result added to the accumulator variable.
      Tip: SAS treats an expression that produces a missing value as zero.

      Comparisons

      The sum statement is equivalent to using the SUM function and the RETAIN statement, as shown here:

      retain variable 0;
      variable=sum(variable,expression);

      Examples

      Here are examples of sum statements that illustrate various expressions:

      balance+(-debit);

      sumxsq+x*x;

      nx+(x ne .);

      if status='ready' then OK+1;




      SO BRACKETS () ARE NOT ALWAYS A NECESSITY O SUM STATEMENT

      Delete
    4. Anonymous11:49 AM

      Thank you.

      Delete
  7. Anonymous8:55 AM

    just stay wid yr basics......
    would u get d sas software in d xam?
    no ...........

    to get the answer use d method of elimintaio-----
    >> option B is rejected due to wrong SUM() syntax.....
    >> option C is rejected due to wrong SUM() syntax also....
    >>in option D totquantity is a accumulator varible, The accumulator variable starts giving missing value , when its adds up eith a missing value, so d desirerd ouptput we coulds nt get......so option D rejected....

    >>option A is correct bcoz its itself creates d variable totquantity , initialises wid 0, retains its valueas after iterations , ignores miising values.......

    >>> joydeep786@gmail.com

    ReplyDelete
    Replies
    1. dude ... do you even SAS ??? this is the silliest explanation ... why dont you try running the code with all the answer options and then be this definitive ... the answer is C .. (btw .. the only WRONG sum syntax is in option A)

      Delete
  8. Anonymous3:20 PM

    Referring to 'the basics' here, I could not find difference between the syntax of SUM() function in option C and D. So, option C can not be rejected !
    D is wrong bcz output statement is not needed and also it is wrong syntax.
    Answer is C according to basics even if we dnt use SAS.

    ReplyDelete
  9. Anonymous1:33 PM

    data groceries;
    input item $ cost;
    retain grandtot 0;
    grandtot = sum(grandtot,cost);
    datalines;
    squash 1.10
    apples 2.25
    juice 1.69
    ;
    run;

    its c

    ReplyDelete
  10. It is C, but I'd like to point out in this line of code:

    retain grandtot 0;

    The '0' sets the initial value of grandtot to 0. This is not necessary, since gradtot doesn't already have a value assigned to it, and SAS isn't so sassy as to think you're adding to a missing value.

    ReplyDelete
  11. Anonymous10:49 AM

    Answer is A, Does not make sense to have sum (grandtot cost) , it will sum grandtot and sum.

    Is it not enough sum cost? Conformed the answer is A. Do not get distracted who ever said A got the right answer.

    ReplyDelete
    Replies
    1. Anonymous2:44 AM

      correct. Because The SUM statement prints sums for the variables in the list. It cannot be C, because we do not want cumulative figures for each obs. We just want the one grand total.

      Delete
    2. Anonymous11:03 PM

      There is not cumulative figures for each obs. That would require an explicit output; to be added.

      Delete
    3. Anonymous7:32 AM

      A is the correct answer because we just want the grand total.C would give us the accumulated total.

      Delete
  12. Anonymous5:47 PM

    Damn work on your logic and that will help in the exam to pass. Yeah you are right if not sure start eliminating and you will find one or two.

    Use your brain and memory to eliminate the wrong one.

    ReplyDelete
  13. midwesterner2:21 PM

    Clayton Roche,

    If you are correct, then both B and C are correct.

    ReplyDelete
    Replies
    1. He said that '0' is not necessary, not retain statement.

      Delete
  14. sab sale paglu hain...
    answer is "c"

    ReplyDelete
  15. Anonymous9:05 AM

    I can't agree more with baba45! lol Paglu

    ReplyDelete
  16. Anonymous10:09 AM

    i am agree with baba45: sab paglu hain... answer is C

    ReplyDelete
  17. Anonymous3:04 PM

    Answer: C

    My thoughts:

    A has incorrect syntax and will not compile. The idea of "sum cost" has some merit in the context of a proc print situation, but used in an assignment statement like this, it's just garbage.

    B will actually perform sum(.,cost) for each iteration... assigns this result (=cost) to grandtot, so the result is that grandtot equals the newly read value of cost each time... because for each iteration grandtot is reset to missing, in the absence of a 'retain' SAS has no memory of the previous value. It compiles alright, but it doesn't produce the goods.

    C works just as intended, try it and see.

    D output grandtot; does NOT mean output the value of grandtot to the groceries dataset. It means send the output to a particular dataset called "grandtot". Since this dataset doesn't in fact exist, as it wasn't declared in the data statement at the top, this is a compile time error.

    Nigel

    ReplyDelete
  18. Anonymous4:41 AM

    baba45 zinda baad... sab paglu hain :D

    ReplyDelete
  19. Anonymous9:49 AM

    C is correct PLease run these codes;

    C)data groceries;
    input item $ cost;
    retain grandtot 0;
    grandtot = sum(grandtot,cost);
    cards;
    squash 1.10
    apples 2.25
    juice 1.69
    run;

    D)data groceries;
    input item $ cost;
    grandtot = sum(grandtot,cost);
    output grandtot;
    cards;
    squash 1.10
    apples 2.25
    juice 1.69
    run;

    There will be zero observation for D while C gives you the correct sums.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  20. Anonymous3:46 AM

    this is A
    C) retain does not accept o

    SUM statement does not require ( ) \
    general form is sum variable; in this case the variable is costs
    and grandtot is defined by the statement, it will write the output at the end of the column costs ...

    ReplyDelete
  21. Anonymous6:56 PM

    The answer is C I tested all choices.

    data test;
    infile datalines;
    input item $ cost;
    grandtot = sum cost;
    datalines;
    squash 1.10
    apples 2.25
    juice 1.69
    ;

    data test;
    infile datalines;
    input item $ cost;
    grandtot = sum(grandtot,cost);
    datalines;
    squash 1.10
    apples 2.25
    juice 1.69
    ;

    data test;
    infile datalines;
    input item $ cost;
    retain grandtot 0;
    grandtot = sum(grandtot,cost);
    datalines;
    squash 1.10
    apples 2.25
    juice 1.69
    ;

    data test;
    infile datalines;
    input item $ cost;
    grandtot = sum(grandtot,cost);
    output grandtot;
    datalines;
    squash 1.10
    apples 2.25
    juice 1.69
    ;

    ReplyDelete
  22. Is the answer B...

    ReplyDelete
  23. Anonymous2:25 PM

    How about if there is a missing variable in the list? what would happen with the sum statement and/or the sum function?

    ReplyDelete