|Date: ||Thu, 3 Mar 2005 05:15:21 +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: SUSPECT: Re: Retain|
|Content-Type: ||text/plain; format=flowed|
Default DATA Step Behavior
Without a RETAIN statement, SAS automatically sets variables that are
assigned values by an INPUT or assignment statement to missing before each
iteration of the DATA step.
Assigning Initial Values
Use a RETAIN statement to specify initial values for individual variables, a
list of variables, or members of an array. If a value appears in a RETAIN
statement, variables that appear before it in the list are set to that value
initially. (If you assign different initial values to the same variable by
naming it more than once in a RETAIN statement, SAS uses the last value.)
You can also use RETAIN to assign an initial value other than the default
value of 0 to a variable whose value is assigned by a sum statement.
It is redundant to name any of these items in a RETAIN statement, because
their values are automatically retained from one iteration of the DATA step
to the next:
variables that are read with a SET, MERGE, MODIFY or UPDATE statement
a variable whose value is assigned in a sum statement
the automatic variables _N_, _ERROR_, _I_, _CMD_, and _MSG_
variables that are created by the END= or IN= option in the SET, MERGE,
MODIFY, or UPDATE statement or by options that create variables in the FILE
and INFILE statements
data elements that are specified in a temporary array
array elements that are initialized in the ARRAY statement
elements of an array that have assigned initial values to any or all of the
elements on the ARRAY statement.
You can, however, use a RETAIN statement to assign an initial value to any
of the previous items, with the exception of _N_ and _ERROR_.
From: John McQuown <John.McQuown@OTNNET.COM>
Reply-To: John McQuown <John.McQuown@OTNNET.COM>
Subject: Re: SUSPECT: Re: Retain
Date: Wed, 2 Mar 2005 20:15:00 -0800
Strange that no one has mentioned that arrays, when initialized or
temporary, are automatically retained... A stealth RETAIN.
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Sent: Wednesday, March 02, 2005 7:35 PM
Subject: SUSPECT: Re: Retain
Okay I have but my tongue long enough on where this thread is going:
The retain statement does not, cannot, and will not (as long as the
underlying code is written currently) retain a thing. Nor will it
counter or accumulator variable, nor will it create a lag variable. The
retain function will stop the SAS supervisor from resetting certain
variables stated in the retain statement from being reset to missing
each iteratoin of the data step. Now one can use the retain statement
other coding techniques or functions to create variables that
act like a accumulator, count, or lag variable.
The lag function doesn't even perform a true lag, it merely creates teh
illusion of a lag variable.
Why is this so important to get straight, well not knowing what the
statement or lag function does has lead more programmers down the path
insanity and baldness than probrably any other topic in SAS other than
Ian's macro design or Pauls hash programs. once one knows how they do
they do, then one can use them to their advantage.
From: Frank Berger <frank.d.berger@DAL.FRB.ORG>
Reply-To: Frank Berger <frank.d.berger@DAL.FRB.ORG>
Subject: Re: Retain
Date: Wed, 2 Mar 2005 16:41:31 -0600
"Grado" <firstname.lastname@example.org> wrote in message
> "Stat" <email@example.com> ha scritto nel messaggio
> > Hi,
> > What are your top 5 reasons for using the RETAIN function?
> > - SH
> 1) to count or cumulate something in a datastep
> 2) to arrange variables order in a dataset
> are you carrying out a market research on the topic?
3. To create a constant.
4. To create a lag variable without using the lag function. As in:
set temp1 (keep=x);
if _n_ ne 1 then
if x ne lx then output;