Date: Tue, 21 Dec 2004 14:41:37 -0600
Reply-To: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Subject: Re: What about a BYVAR option for the RETAIN statement?
Content-Type: text/plain; charset="iso-8859-1"
Actually Venky one can find a paper that has a section over the DoW, namely Paul's "Magnificent Do" paper.
Toby
________________________________
From: SAS(r) Discussion on behalf of Venky Chakravarthy
Sent: Tue 12/21/2004 12:19 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: What about a BYVAR option for the RETAIN statement?
Mark,
It is a nice thought and it would indeed be very useful. I have a sneaking
suspicion that something is in the works already. I am in the
Pharmaceutical business and the limitations (actually clumsiness) of the
RETAIN statement are frequently exposed.
We, on SAS-L, are fortunate to have many wizards on this list who have
tweaked the capabilities of the data step to their advantage. I have learnt
to eschew the RETAIN (not entirely but mostly) to achieve all the
functionality of the RETAIN without coding it in my data step. I would code
using the DOW to achieve the functionality that you are seeking without
using a RETAIN.
You will need to read up on the DOW. However, you can only read about it on
this list and will need to search the archives. Search for "DOW" and
Dorfman in the address. Also search for "do until (last.id)" , do until
(last.patient). You should generate some hits that are applicable to your
situation.
data new;
do until (last.b) ;
set old;
by b ;
*<do your business here> ;
output ;
end ;
run ;
On a shamelessly self-promoting note, I am working on a paper
titled "RETAIN or NOT? Is LAG far behind?" My objective is essentially the
same as yours .. to address the limitations of the RETAIN in its current
form.
Kind Regards,
Venky
On Tue, 21 Dec 2004 12:51:37 -0500, Keintz, H. Mark
<mkeintz@WHARTON.UPENN.EDU> wrote:
>I just finished submitting a SASware ballot
>(http://support.sas.com/techsup/feedback/sasware_ballot05/ballot.html#Ba
>se) which reminded me of a wishlist item that I'd like to see on the
>ballot. Before I send the idea to SAS, I'd like some opinions from
>SAS-L on the notion of a BYVAR option for the RETAIN statement. It
>would work as follows:
>
>
>data new;
> set old;
> by a b c d;
> retain NEW_W 0 NEW_X 0 / byvar=b ;
> retain NEW_Y 0 NEW_Z 0;
>run;
>
>The result would be every time a "first.b" condition is detected, the
>retained variables NEW_W and NEW_X would be reset to their initial
>values, unlike NEW_Y and NEW_Z.
>
>I've often needed to program this behavior, and I guess I'll write a
>RETAINBY, but I wonder if other SAS-L folks think it would be a valuable
>modification of the RETAIN statement.
>
>
>
>Mark Keintz
>Wharton Research Data Services