Date: Mon, 25 Feb 2008 02:56:40 -0800
Reply-To: Sylar <rifazrazeek@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sylar <rifazrazeek@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Calculating Days Since Last Visit
Content-Type: text/plain; charset=ISO-8859-1
Hi David,
Yes, LAG function would be an easy way to do it.
See some code below.
Hope it helps.
Rif
=======================================
data dset1;
input patient date date9.;
format date date9.;
datalines;
1 01JAN08
1 08JAN08
1 14JAN08
2 02JAN08
2 09JAN08
2 15JAN08
;
RUN;
proc sort data=dset1; by patient; run;
data dset2;
set dset1;
by patient;
last_visit=lag(date);
if first.patient then last_visit=.;
days_since_last_visit=date-last_visit;
format last_visit date9.;
run;
==============================================
On Feb 25, 9:06 am, harrypotter...@EARTHLINK.NET (David Friedman)
wrote:
> For a given patient visit I want to calculate the days since last visit. I
> have several visit records per patient. I want to get output something
> like this:
>
> Patient # Visit Date Days since last visit
> 1 1/1/2000 .
> 1/8/2000 7
> 2/1/2000 30
>
> What is the best way to do this? Lag function?