LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (March 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: sas-l@uga.edu
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.


Back to: Top of message | Previous page | Main SAS-L page