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 (April 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 5 Apr 2007 03:00:48 -0400
Reply-To:   Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject:   Re: Lag command VS retain ?

... by the way: a RETAIN statement normally makes no sense for a dataset variable. How does it work? RETAIN prevents a variable to be set to missing at the end of the internal loop. After that, all variables are loaded with the values of the next obs. So you can prevent a variable from being initialized, anyway it gets a new value from the new obs. So define a new variable, not a existing one. This new variable you can use to save a value.

data ...; retain xx_dummy; set ...; if lag_xx ne . then do; xx_dummy=lag_xx; end; else do; lag_xx=xx_dummy; /* or whatever should be in there */ end; ... run;

With that you fill up lag_xx with the previous value if it's missing. However it is not clear to me, what you REALLY want to do. Is lag_xx really needed? Or do you want to treat with XX and do something like the above, maybe not only replace the missing, also add 30? Gerhard

On Thu, 5 Apr 2007 02:03:20 -0400, Yosef Sugiharto Adikusumo <YSAdikusumo@BANKBII.COM> wrote:

>Hi,I have a dataset with the following values. > >id date_1 date_2 XX lag_XX >1AA 08aug06 23aug06 54 . >1AA 08sep06 . . 54 >1AA 08oct06 . . . >1AA 08nov06 . . . >2BB 18aug06 3sep06 20 . >2BB 18sep06 . . 20 >2BB 18oct06 . . . >3CC 05aug06 18aug06 10 . >3CC 05sep06 . . 10 > >How can I change it to the following specification. >such that the output looks like this > >id date_1 date_2 XX lag_XX >1AA 08aug06 23aug06 54 . >1AA 08sep06 . 84 54 >1AA 08oct06 . 124 84 >1AA 08nov06 . 154 124 >2BB 18aug06 3sep06 20 . >2BB 18sep06 . 50 20 >2BB 18oct06 . 80 50 >3CC 05aug06 18aug06 10 . >3CC 05sep06 . 40 10 > >think I have to use a retain statement for lag_XX and update to XX >variable??? but I dont know how to proceed. > >Thanks you all for your help as always >YS


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