Date: Wed, 3 Nov 2010 21:31:16 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: retain statement
In-Reply-To: <002901cb7b98$b9bc6c50$2d3544f0$@com>
Content-Type: text/plain; charset="iso-8859-1"
Max,
One can break down the Data Step code into either compile or execution time code.
Retain and the set statement are compile time. A little Data Step theory tells
us that before the execution code is executed the PDV is set up. Furthermore if a compile
time statment like a drop, keep, rename, retain, array statements are present they
are used at compile time to help set the PDV. Now to further our discussion along if we
think about the Data Step implied loop and how it operates we can say that a well placed
Put statement to dump the PDV to the log, after the compile statements and before the execution
statements are executed, we can see what the values are. So if you place a Put _All_
statement before the Set statement add a Stop statement to stop the Data Step from reading
any observations in we can see what is in the PDV after the compile Statements are
finished setting up the PDV and before any execution statements are executed.
13 Data _Null_ ;
14 Put _All_ ;
15 Stop ;
16 Set SASHELP.Class ;
17 Retain X 1000 ;
18 Run ;
Name= Sex= Age=. Height=. Weight=. X=1000 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
So to answer your question, variables values set in a retain statement are
set to the predefined value before the execution statements are executed.
Toby Dunn
"I'm a hell bent 100% Texan til I die"
"Don't touch my Willie, I don't know you that well"
> Date: Wed, 3 Nov 2010 16:50:17 -0400
> From: bbser2009@GMAIL.COM
> Subject: Re: retain statement
> To: SAS-L@LISTSERV.UGA.EDU
>
> Chang,
> How to examine x? I tried x?; x=;
> Neither worked.
> Thanks.
> Max
>
> -----Original Message-----
> From: Chang Chung [mailto:chang_y_chung@HOTMAIL.COM]
> Sent: November-03-10 3:42 PM
> To: SAS-L@LISTSERV.UGA.EDU; Bbser 2009
> Subject: Re: retain statement
>
> On Wed, 3 Nov 2010 12:31:56 -0400, bbser2009 <bbser2009@GMAIL.COM> wrote:
>
> >Suppose we a code like this:
> >...
> >retain x=1000; *first occurrence of x;
> >...
> >
> >Just after the compilation and before the execution,
> >what's the value of x in the programme data vector?
> ...
> Hi, Max,
> I am not sure, but retain is a declarative statement, taking effect at
> compile time. Thus, even though I am not sure when exactly the retained
> variables are initialized with the given initial values, but I am quite
> sure that when the execution starts, they should be initialized already.
> The latter can be easily shown by running the data step debugger on a data
> step like below:
> data one/debug;
> stop;
> set sashelp.class;
> retain x 1000;
> run;
> Examine x as soon as the debugger starts. You will find that x is already
> assigned 1000.
> Cheers,
> Chang
|