Date: Wed, 30 Nov 2005 10:39:55 -0600
Reply-To: baogong jiang <bgjiang@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: baogong jiang <bgjiang@GMAIL.COM>
Subject: help with LAG function
Content-Type: text/plain; charset=ISO-8859-1
hello, I have a dataset like following:
id serv_from_date supply
a 20041001 30
a 20041102 30
a 20050204 15
b 20041125 30
b 20050212 45
b 20050301 30
c 20050312 30
d 20050612 15
I want to calculate the gaps between the serv_from_date by each id;
data were sorted by id and serv_from_date
I used this:
data new;
set old;
by id:
if first.id then gap=.;
else gap=input(put (serv_from_date,8.),
yymmdd8.)-input(put(serv_from_date,8.),yymmdd8.);
run;
but code did not give me the right results.
what's wronge with the code?
anyone can give a sql solution?
thank you,
|