ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 49

Which one of the following is true of the RETAIN statement in a SAS DATA step program?
A. It can be used to assign an initial value to _N_ .
B. It is only valid in conjunction with a SUM function.
C. It has no effect on variables read with the SET, MERGE and UPDATE statements.
D. It adds the value of an expression to an accumulator variable and ignores missing values.
Click Comment link to get answer

33 comments:

  1. The answer is C

    ReplyDelete
  2. Anonymous2:19 PM

    The answer is C .It is redundant to name any of variables that are read with a SET, MERGE, MODIFY or UPDATE statement in a RETAIN statement because their values are automatically retained from one iteration of the DATA step to the next

    ReplyDelete
    Replies
    1. Anonymous1:22 PM

      Helpful! Thanks ~

      Delete
  3. the answer is C:
    ----------------
    The RETAIN statement has no effect on variables that are read with SET, MERGE,
    or UPDATE statements

    ReplyDelete
  4. Anonymous10:51 AM

    The answer is C.Though retain statement could initialize the accumulative value, it does not ignores the missing value.for example:a=a+b

    ReplyDelete
  5. Anonymous9:06 PM

    Anyone can explain me properly, because I didn't understand the concept of Retain Statement yet. If it doesn't go with set, merge, update than when we can use the retain statement and why?

    Thanks a lot

    ReplyDelete
  6. Anonymous10:14 AM

    D. It adds the value of an expression to an accumulator variable and ignores missing values.

    D is the riht Answer

    ReplyDelete
    Replies
    1. Wrong D is correct for SUM statement,
      Answer is C bcz Retain function is to retain the value.
      Syntax: Retain variable initial- value;
      And it doesn't have effect on SET,Merge and Update statements.

      Delete
  7. Anonymous5:15 AM

    The RETAIN statement
    - is a compile-time only statement that creates variables if they do not already exist
    - initializes the retained variable to missing before the first execution of the DATA step if you do not supply an initial value
    - has no effect on variables that are read with SET, MERGE, or UPDATE statements.

    ReplyDelete
  8. Anonymous3:45 PM

    Hey poeple,

    D is an explanation for the "sum statement"!!!
    Please pay attention ;-)

    cheers,
    ferrat

    ReplyDelete
  9. Anonymous6:42 AM

    From comparing RETAIN to SUM statement in SAS Help & Doc; for RETAIN:

    1. The expression is evaluated and the result added to the accumulator variable.

    2. SAS treats an expression that produces a missing value as zero.

    So, in terms of 'D', first one is true but second one is not (missing values evaluated as 0) so must be 'C'

    ReplyDelete
  10. ani.......5:15 AM

    ha ans is D . c properly....
    RETAIN variable 0;
    variable = SUM(variable, expression);
    variable is the one which is newly created...
    so in this case the valu of expression is added to variable and missing values are removed .. il give example

    Using RETAIN and sum statements to find most runs and total runs;
    DATA gamestats;
    INFILE 'c:\MyRawData\Games.dat';
    INPUT Month 1 Day 3-4 Team $ 6-25 Hits 27-28 Runs 30-31;
    RETAIN MaxRuns;
    MaxRuns = MAX(MaxRuns, Runs);
    RunsToDate + Runs;
    PROC PRINT DATA = gamestats;
    TITLE "Season's Record to Date";
    RUN;


    Season's Record to Date 1
    Max Runs
    Obs Month Day Team Hits Runs Runs ToDate
    1 6 19 Columbia Peaches 8 3 3 3
    2 6 20 Columbia Peaches 10 5 5 8
    3 6 23 Plains Peanuts 3 4 5 12
    4 6 24 Plains Peanuts 7 2 5 14
    5 6 25 Plains Peanuts 12 8 8 22
    6 6 30 Gilroy Garlics 4 4 8 26
    7 7 1 Gilroy Garlics 9 4 8 30
    8 7 4 Sacramento Tomatoes 15 9 9 39
    9 7 4 Sacramento Tomatoes 10 10 10 49
    10 7 5 Sacramento Tomatoes 2 3 10 52

    c this one proprely

    so ans is D...

    ReplyDelete
  11. my mail..
    lotlikar.aniket44@gmail.com

    ReplyDelete
  12. Anonymous6:33 AM

    answer is c. it has no effect on incoming variables only new variables...

    ReplyDelete
  13. Anonymous5:26 PM

    Who said B. got the point(As per my anwsersheet).

    ReplyDelete
  14. D is the right answer:

    No one will argue about the first part "It adds the value of an expression to an accumulator variable."

    For the second part of the answer,"ignores missing values", please refer to page 3 in this link for an example with explanation - http://support.sas.com/publishing/pubcat/chaps/58176.pdf


    "RETAIN variable
    specifies the name of the accumulator variable, which contains a numeric value.
    Tips: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.
    To initialize a sum variable to a value other than 0, include it in a RETAIN statement with an initial value.

    RETAIN expression
    is any SAS expression.
    Tips:The expression is evaluated and the result added to the accumulator variable.
    SAS treats an expression that produces a missing value as zero. " - Sas help and documentation

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. The answer is C! Page 307 SAS cert:

    Retain statement has no effect on variables that are read with SET, Merge, or UPDATE statements.

    ReplyDelete
  17. Anonymous8:00 AM

    c is the ans

    ReplyDelete
  18. Replies
    1. Anonymous5:50 AM

      Can you please explain?

      Delete
  19. C is the right answer because RETAIN does not affect SET and the other statements in anyway because values in the PDV, created with any of the four specified statements, are carried over across iterations. And D cannot be the answer because Retain statement retains a value until another value gets available and does not accumulate. Accumulating is the nature of SUM statement. A and B options are completely out of picture anyway.

    ReplyDelete
  20. If question ask "Which one of the follow is true of the SUM statement in a SAS DATA step program?" Then chose D. But for here should be C

    ReplyDelete
  21. Anonymous7:46 PM

    I knew that the other three options are false. So I choose C.

    ReplyDelete
  22. Anonymous9:54 AM

    hi all,

    can any one tell me why the below code is giving . value in "total" ::

    data new2;
    set new1;
    retain total;
    total=total+age;
    run;

    ReplyDelete
    Replies
    1. Anonymous10:54 PM

      Hi, the + operator gives an unknown result when one of the operangs is unknown.

      total will just keep adding numbers to an unknown and give an unknown amount.

      You need to initialize total with:

      retain total 0;

      Delete
  23. cordinist-ru Kayla Allen Here
    rellaynahal

    ReplyDelete