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
Ans: D
ReplyDeleteThe answer is C
ReplyDeleteThe 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
ReplyDeleteHelpful! Thanks ~
Deletethe answer is C:
ReplyDelete----------------
The RETAIN statement has no effect on variables that are read with SET, MERGE,
or UPDATE statements
C
ReplyDeleteThe answer is C.Though retain statement could initialize the accumulative value, it does not ignores the missing value.for example:a=a+b
ReplyDeleteAnyone 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?
ReplyDeleteThanks a lot
D. It adds the value of an expression to an accumulator variable and ignores missing values.
ReplyDeleteD is the riht Answer
Wrong D is correct for SUM statement,
DeleteAnswer 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.
The RETAIN statement
ReplyDelete- 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.
Hey poeple,
ReplyDeleteD is an explanation for the "sum statement"!!!
Please pay attention ;-)
cheers,
ferrat
From comparing RETAIN to SUM statement in SAS Help & Doc; for RETAIN:
ReplyDelete1. 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'
ha ans is D . c properly....
ReplyDeleteRETAIN 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...
my mail..
ReplyDeletelotlikar.aniket44@gmail.com
answer is c. it has no effect on incoming variables only new variables...
ReplyDeleteWho said B. got the point(As per my anwsersheet).
ReplyDeleteD is the right answer:
ReplyDeleteNo 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
This comment has been removed by the author.
ReplyDeleteThe answer is C! Page 307 SAS cert:
ReplyDeleteRetain statement has no effect on variables that are read with SET, Merge, or UPDATE statements.
c is the ans
ReplyDeleteB
ReplyDeleteCan you please explain?
DeleteC 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.
ReplyDeleteC
ReplyDeleteIf 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
ReplyDeleteI knew that the other three options are false. So I choose C.
ReplyDeleteD
ReplyDeletehi all,
ReplyDeletecan any one tell me why the below code is giving . value in "total" ::
data new2;
set new1;
retain total;
total=total+age;
run;
Hi, the + operator gives an unknown result when one of the operangs is unknown.
Deletetotal will just keep adding numbers to an unknown and give an unknown amount.
You need to initialize total with:
retain total 0;
C
ReplyDeletepuncquilig_pe Erika Lietzow https://marketplace.visualstudio.com/items?itemName=8lenniaemta.Descargar-One-Eyed-Lee-And-The-Dinner-Party-gratuita-2022
ReplyDeletelotirasinc
cordinist-ru Kayla Allen Here
ReplyDeleterellaynahal