Date: Thu, 30 Aug 2001 16:03:23 -0400
Reply-To: Quentin McMullen <QuentinMcMullen@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Quentin McMullen <QuentinMcMullen@WESTAT.COM>
Subject: Re: Automatically RETAINed ??
Content-Type: text/plain; charset="iso-8859-1"
Jonathan Goldberg Wrote:
> In response to a question form Peetie Wheatstraw about
> retained values,
> Quentin McMullen writes the following:
> -- 3a. Because set statement is reading from a new data set (B not A),
> initializes PDV**. So PDV is now once again id=. x1=. x2=.
> 3a is not quite right. SAS does not initialize the *PDV*; it
> the variables from that SET statement.
I don't think so. As I understand it, the entire PDV is getting initialized
(okay, not _n_, etc.). And as I mentioned (but maybe didn't emphasize
enough), my description was of the process of *interleaving* data sets,
rather than a property of the set statement alone.
[Pause to play in SAS]
OK, just changed my mind (I think). I played around a little with the below
structure, and it looks you are right, only the variables from the set
statement with the inter-leaving are initialized. In general, I'm too much
of a coward to use interleaving *and* multiple sets in a single data step. :
set a b;
> This difference becomes significant if there is more than one set
> statement. Consider the following log:
> 12 data two;
> 13 if _n_ = 1 then
> 14 do;
> 15 set a;
> 16 put _all_;
> 17 if (x1<=x<=x2) then output;
> 18 end;
> 19 else
> 20 do;
> 21 set b;
> 22 put _all_;
> 23 if (x1<=x<=x2) then output;
> 24 stop;
> 25 end;
> 26 run;
> id=1 x1=1 x2=4 x=. _ERROR_=0 _N_=1
> id=1 x1=1 x2=4 x=3 _ERROR_=0 _N_=2
> NOTE: There were 1 observations read from the data set WORK.A.
> This is, I think, the result Peetie was trying to bring about.
This is nifty code, but it's a different setup. As you say, here you are
not interleaving datasets but instead using two different set statements.
I think this example speaks to a different point. SAS creates the same PDV.
On first pass it reads id=1 x1=1 x2=4, so PDV is id=1 x1=1 x2=4 x=. At end
of data step it does not initialize any of the variables in the PDV. Why
not? Well, because as Peetie pointed out in his first post, variables
appearing on the set statement are automatically retained. So at the top of
the data step with _n_=2, the PDV still looks like id=1 x1=1 x2=4 x=. Now
it sets in the record from B (over-writing values in ID and x) and the PDV
is id=1 x1=1 x2=4 x=3.
Does that sound reasonable?
Kind Regahds [going back to Boston this weekend],