Date: Wed, 30 Nov 2005 11:50:34 -0500
Reply-To: diskin@alum.rpi.edu
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dennis Diskin <ddiskin@GMAIL.COM>
Subject: Re: help with LAG function
In-Reply-To: <cabe11870511300839l39eaf133ta49774d83a1842f3@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Add
RETAIN GAP;
to keep the preceding value.
HTH,
Dennis Diskin
On 11/30/05, baogong jiang <bgjiang@gmail.com> wrote:
>
> 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,
>
|