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 (April 1996, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 29 Apr 1996 18:14:05 -0700
Reply-To:     Robin Way <robin@BCINC.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Robin Way <robin@BCINC.COM>
Organization: Barakat & Chamberlin, Inc.
Subject:      Re: Lags with BY variables

Michael Friendly wrote: > > I'm trying to generate lags of observations in a dataset with > a separate lagged series for each value of a BY variable (SEQ). > I tried this: > > data lags; > set codegen; > by seq; > if first.seq then do; > lag1 = ' '; > lag2 = ' '; > end; > else do; > lag1 = lag(code); > lag2 = lag2(code); > end; > > But this does not work for the second and subsequent value of the > by variable.

(snip) Michael: I remember consulting SI tech support about a similar problem. I liked Tim Berryhill's solution to your problem, because (here's the rationale): lags should not be invoked conditionally (i.e., should not be part of an IF statement or IF-based DO loop). The right way to handle them is to execute the lag statement up front, without any qualifications, (such as, xlag1 = lag(x);) and then reset the value of the dataset var later based on conditional logic (much like Tim suggested).

Robin Way Barakat & Chamberlin, Inc. Portland, Oregon

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