Date: Mon, 17 Jun 1996 09:44:56 -0700
Reply-To: Bruce Rogers <gxx18300@GGR.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Bruce Rogers <gxx18300@GGR.CO.UK>
Organization: Glaxo Wellcome
Subject: Re: Retain statement
gaylen fraley wrote:
>
>
> Bruce Rogers wrote:
> >
> > No, It makes no difference where you put the RETAIN statement. It is
> > non-procedural, retaining values of any specified variables, whatever
> > position it is placed in.
<snipped>
>
> This is NOT correct. The placement of the RETAIN statement IS important. The
> following example illustrates this:
>
> data ONE;
> do i = 1 to 10;
> output;
> end;
> run;
>
> data TWO;
> retain _all_;
> set ONE;
> if I = 1 then X = 1;
> run;
>
> /* According to your statement, all 10 records should retain the value of X=1. */
> /* You will discover that X=1 is only in the first record. If, however, you */
> /* move the RETAIN staement AFTER the IF i=1 statement, THEN all 10 records will */
> /* retain the value for X. */
>
Gaylen,
Your results are correct, but your conclusion is not. The reason your code does not retain
the value of X is not the position of the RETAIN statement, but the fact that you have used
_ALL_ instead of naming the variables required. The variable X is not known at the point you
specify _ALL_ (over-simplifying things a bit, I know), so it is not retained at all. If you
replace the _ALL_ with the variable names I and X, the predicted results (i.e. X always = 1 )
will be given.
Bruce
p.s. Don't be so quick to knock other people's ideas. :-)
|