Date: Thu, 17 May 2001 13:59:00 -0700
Reply-To: "Huang, Ya" <ya.huang@AGOURON.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Huang, Ya" <ya.huang@AGOURON.COM>
Subject: Re: Lag fn ???
Content-Type: multipart/alternative;
Here is a one sql step solution, no need of lag(),
where flag=1 means that id meets all the criteria,
flag=0 dose not meet, for example, in subid=2,
d2-d0=4 days > 2, therefore subid=2 are flagged as 0:
data xx;
input subid $ visitid $ visitdt : mmddyy. results test $;
format visitdt date.;
cards;
1 s 5/06/99 2 a
1 s 5/06/99 7 b
1 s 5/06/99 9 c
1 d0 5/24/99 7 a
1 d0 5/24/99 2 b
1 d0 5/24/99 2 c
1 d2 5/26/99 3 a
1 d2 5/26/99 4 b
1 d2 5/26/99 5 c
1 w2 6/3/99 3 a
1 w2 6/3/99 4 b
1 w2 6/3/99 5 c
2 s 5/06/99 2 a
2 s 5/06/99 7 b
2 s 5/06/99 9 c
2 d0 6/4/99 7 a
2 d0 6/4/99 2 b
2 d0 6/4/99 2 c
2 d2 6/8/99 3 a
2 d2 6/8/99 4 b
2 d2 6/8/99 5 c
2 w2 6/13/99 3 a
2 w2 6/13/99 4 b
2 w2 6/13/99 5 c
;
options nocenter;
proc sql;
select *,
max((visitid='d0')*visitdt)-max((visitid='s')*visitdt) <=25 and
max((visitid='d2')*visitdt)-max((visitid='d0')*visitdt) <=2 and
max((visitid='w2')*visitdt)-max((visitid='d2')*visitdt) <=9 as flag
from xx
group by subid
order by subid, visitdt
;
quit;
------------------
The SAS System 13:33 Thursday, May 17, 2001 8
subid visitid visitdt results test flag
-----------------------------------------------------------
1 s 06MAY99 7 b 1
1 s 06MAY99 9 c 1
1 s 06MAY99 2 a 1
1 d0 24MAY99 7 a 1
1 d0 24MAY99 2 b 1
1 d0 24MAY99 2 c 1
1 d2 26MAY99 4 b 1
1 d2 26MAY99 5 c 1
1 d2 26MAY99 3 a 1
1 w2 03JUN99 4 b 1
1 w2 03JUN99 5 c 1
1 w2 03JUN99 3 a 1
2 s 06MAY99 2 a 0
2 s 06MAY99 7 b 0
2 s 06MAY99 9 c 0
2 d0 04JUN99 7 a 0
2 d0 04JUN99 2 c 0
2 d0 04JUN99 2 b 0
2 d2 08JUN99 3 a 0
2 d2 08JUN99 4 b 0
2 d2 08JUN99 5 c 0
2 w2 13JUN99 4 b 0
2 w2 13JUN99 3 a 0
2 w2 13JUN99 5 c 0
HTH
Ya Huang
-----Original Message-----
From: Peter Bond [mailto:b5fan2@HOTMAIL.COM]
Sent: Thursday, May 17, 2001 1:04 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Lag fn ???
Hi SAS users, I have the following problem and I guess I need to use the lag
function but am not sure exactly how to go about it.
Data structure:
subid visitid visitdt results test ....more vars
1 s 5/06/99 2 a
1 s 5/06/99 7 b
1 s 5/06/99 9 c
1 d0 5/24/99 7 a
1 d0 5/24/99 2 b
1 d0 5/24/99 2 c
1 d2 5/26/99 3 a
1 d2 5/26/99 4 b
1 d2 5/26/99 5 c
etc etc etc
2
2
2
2
What I need to do is calculate the the number of days between each visit and
identify the subid in which the days are not less than or equal to (1) for
D0
-S <= 25, (2) D2-D0 <=2 and W2 -D2 <=9 etc. There are multiple visitids as
you can see and I am not sure how to implement the lag function here and
even if it is the correct thing to do.
Any help is greatly appreciated.
Peter Bond.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
[text/html]