| Date: | Thu, 22 Oct 2009 21:38:01 -0400 |
| Reply-To: | Muthia Kachirayan <muthia.kachirayan@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Muthia Kachirayan <muthia.kachirayan@GMAIL.COM> |
| Subject: | Re: difference |
| In-Reply-To: | <085c1cd8-66d8-4917-aa65-7e91dd1169dc@l35g2000vba.googlegroups.com> |
| Content-Type: | text/plain; charset=ISO-8859-1 |
|---|
A one data step approach will be
data have;
input id cycle $ date :ddmmyy.;
format date ddmmyy10.;
cards;
1 c1 11/01/2008
1 c1 12/01/2008
1 c1 13/01/2008
1 c2 15/02/2008
1 c2 16/02/2008
1 c2 17/02/2008
1 c2 19/02/2008
1 c3 11/03/2008
1 c3 20/03/2008
1 c4 15/04/2008
1 c4 20/04/2008
;
run;
data want;
retain prev .;
do until(last.cycle);
set have end = eof;
by cycle;
if first.cycle then do;
if prev = . then prev = date;
else do;
gap = date - prev;
output;
prev = date;
end;
end;
if eof then do;
gap = date - prev;
output;
end;
end;
drop prev;
run;
Kind regards,
Muthia Kachirayan
On Thu, Oct 22, 2009 at 5:20 PM, gkk <gayakrup@gmail.com> wrote:
> Hi ,
>
> I have a condition where the subjects are treated in cycles some can
> have just one cycle whereas others can have upto 10 cycles.
>
> I have to calculate the duration of the cycle which will be first date
> of first cycle - first date of second cycle which will be the duration
> for first cycle .similarly for second its first day of second cycle -
> first date of third .If its the last cycle then its first date of last
> cycle - last date of last cycle.
>
> eg:
>
> id cycle date
> 1 c1 11/01/2008
> 1 c1 12/01/2008
> 1 c1 13/01/2008
> 1 c2 15/02/2008
> 1 c2 16/02/2008
> 1 c2 17/02/2008
> 1 c2 19/02/2008
> 1 c3 11/03/2008
> 1 c3 20/03/2008
> 1 c4 15/04/2008
> 1 c4 20/04/2008
>
>
>
>
> Thanks in advance.
>
|