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 (June 2004, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 29 Jun 2004 18:36:05 -0400
Reply-To:   "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Subject:   Re: FW: Lag Question
Comments:   To: Toby Dunn <tdunn@TEA.STATE.TX.US>

On Tue, 29 Jun 2004 15:46:02 -0500, Dunn, Toby <tdunn@TEA.STATE.TX.US> wrote:

>Brian, > >The problem with your solution is that it requires knowing how many >missing values in a row you have before you create your lags. Thus with >out a lead, interleaving a data set upon itself, or a DoW loop you >wouldn't know. > >Toby Dunn > >-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of >Brian Shilling >Sent: Tuesday, June 29, 2004 3:44 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: FW: Lag Question > >What about increasing the lag using an array, or multiple lag functions? > >LAG assumes LAG1 - one lag back. You could try z = lag(x) zz = lab2(x) >zzz = >lag3(x) and test the missing values that way.

Hi, Toby,

Good question.... IMHO, Brian meant something like below -- which is quite...hmmm... NOT pretty. :-)

Cheers, Chang

data one; input x $ @@; cards; 1 2 . 4 5 1 . . 4 5 1 . . . 5 . . . 4 5 1 2 3 . . ; run;

%macro ninetyNine; %local i; data two(drop=lag1_x--lag99_x); set one; %do i = 1 %to 99; lag&i._x = lag&i.(x); %end; new_x = x; if missing(x) then do; if not missing(lag1_x) then new_x = lag1_x; %do i = 2 %to 99; else if not missing(lag&i._x) then new_x = lag&i._x; %end; end; run; %mend; %ninetyNine

proc print data=two; var x new_x; run;

/* on log Obs x new_x 1 1 1 2 2 2 3 2 4 4 4 5 5 5 6 1 1 7 1 8 1 9 4 4 10 5 5 11 1 1 12 1 13 1 14 1 15 5 5 16 5 17 5 18 5 19 4 4 20 5 5 21 1 1 22 2 2 23 3 3 24 3 25 3 */


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