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 (August 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 25 Aug 2011 14:19:34 -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: Lag values
In-Reply-To:  <941871A13165C2418EC144ACB212BDB00205D838@dshsmxoly1504g.dshs.wa.lcl>
Content-Type: text/plain; charset=utf-8

Unfortunately, I had a cut ana paste accident here. :-) Just ignore the beginning, and go straight the end of the post

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Nordlund, Dan (DSHS/RDA) > Sent: Thursday, August 25, 2011 2:04 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: Lag values > <<<snip>>> > > > -----Original Message----- > > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > > sas8832@HOTMAIL.CO.UK > > Sent: Thursday, August 25, 2011 1:30 PM > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: Re: Lag values > > > > panel dataset > > > > id year quarter variablex lag_variablex > > 1 2000 1 10 . > > 1 2000 2 5 10 > > 1 2000 3 . 5 > > 1 2000 4 20 . > > > > When variablex is missing for the previous quarter, i want > > lag_variablex=. > > rather than equal to the previous available value for variable x. I > > have > > already filled holes (ie missing quarters). > > > > Thanks > > Here is one possibility: > > data have; > input id year quarter variablex ; > cards; > 1 2000 1 10 > 1 2000 2 5 > 1 2000 3 . > 1 2000 4 20 > 2 2000 1 10 > 2 2000 2 5 > 2 2000 3 . > 2 2000 4 20 > ; > run; > > data want; > set have ; > by id; > lag_variablex = lag(variablex); > if first.id then lag_variablex = .; > run; > > proc print; > run; > > I added some data for another id and set the lagged value to missing > when first.id = 1. If you don't want that, just delete the if > statement. > > > Hope this is helpful, > > Dan > > Daniel J. Nordlund > Washington State Department of Social and Health Services > Planning, Performance, and Accountability > Research and Data Analysis Division > Olympia, WA 98504-5204


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