Date: Wed, 26 Mar 2008 09:26:36 -0700
Reply-To: "dc353@hotmail.com" <dc353@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "dc353@hotmail.com" <dc353@HOTMAIL.COM>
Organization: http://groups.google.com
Subject: Re: RETAIN Statement --> strange behavior
Content-Type: text/plain; charset=ISO-8859-1
On Mar 26, 6:36 pm, Nord...@DSHS.WA.GOV ("Nordlund, Dan (DSHS/RDA)")
wrote:
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SA...@LISTSERV.UGA.EDU] On
> > Behalf Of dc...@hotmail.com
> > Sent: Wednesday, March 26, 2008 8:04 AM
> > To: SA...@LISTSERV.UGA.EDU
> > Subject: RETAIN Statement --> strange behavior
>
> > Hi,
>
> > Could someone explain why the first set of code here works with the
> > retain statement but the second example does not?
>
> > First Example:
>
> > data d9;
> > set d8;
> > retain endshare;
> > retain cash;
> > by ticker;
>
> > if first.ticker then do;
> > if ticker = '*$$$' then do;
> > startshare=9617604;
> > endshare=startshare+trade;
> > cash=endshare;
> > mv=endshare*price;
> > cost = endshare*price;
> > avecost=1;
> > end;
> > end;
> > else
> > if ticker = '*$$$' then do;
> > startshare=startshare+cash;
> > endshare= startshare + trade;
> > cash = endshare;
> > mv = endshare*price;
> > cost=endshare*price;
> > avecost=1;
> > end;
> > run;
>
> > SECOND EXAMPLE:*****************************************
>
> > data d9;
> > set d8;
> > retain endshare;
>
> > by ticker;
>
> > if first.ticker then do;
> > if ticker = '*$$$' then do;
> > startshare=9617604;
> > endshare=startshare+trade;
>
> > mv=endshare*price;
> > cost = endshare*price;
> > avecost=1;
> > end;
> > end;
> > else
> > if ticker = '*$$$' then do;
> > startshare=startshare+endshare;
> > endshare= startshare + trade;
>
> > mv = endshare*price;
> > cost=endshare*price;
> > avecost=1;
> > end;
> > run;
>
> What does "doesn't work" mean?
>
> Dan
>
> Daniel J. Nordlund
> Research and Data Analysis
> Washington State Department of Social and Health Services
> Olympia, WA 98504-5204
Dan,
In the second example the retain statement doesn't retain the value of
endshare. Since startshare =0 , endshare is set to trade. I need
startshare to equal the previous value of endshare and then have
endshare increased by the trade amount.
|