LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext 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 11:02:31 -0700
Reply-To:   "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Subject:   Re: RETAIN Statement --> strange behavior
Comments:   To: "dc353@hotmail.com" <dc353@HOTMAIL.COM>
In-Reply-To:   <1c61b0ea-3153-42fa-8db8-83dc64b749fa@f63g2000hsf.googlegroups.com>
Content-Type:   text/plain; charset=iso-8859-1

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of dc353@hotmail.com > Sent: Wednesday, March 26, 2008 9:50 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: RETAIN Statement --> strange behavior > > Here's the same example with the difference all in one line of code: > If you run this with startshare=startshare+ cash it works as expected > but if you comment out that line of code and replace with > startshare=startshare+endshare you get different results. This just > doesn't make any sense. In the second line the retained value of > endshare isn't coming through. But when you set cash = endshare the > retained value of cash is used. What's going on? > > 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; > * startshare=startshare+endshare; > endshare= startshare + trade; > cash = endshare; > mv = endshare*price; > cost=endshare*price; > avecost=1; > end; > run; >

The problem is probably that you think RETAIN does something that it doesn't do. All the RETAIN does is prevent endshare from being reset to missing at the beginning of each loop through the data step. You still need to add the increments you want to endshare. Instead of

* startshare=startshare+endshare; endshare= startshare + trade;

Maybe you want (remove the commented statement)

endshare + (startshare + trade);

Hope this is helpful,

Dan

Daniel J. Nordlund Research and Data Analysis Washington State Department of Social and Health Services Olympia, WA 98504-5204


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