Date: Mon, 8 Jan 2007 06:50:46 -0800
Reply-To: xiangyang.ye@GMAIL.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Xiangyang Ye <xiangyang.ye@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Another algorithm to capture number of EPISODES of event
Content-Type: text/plain; charset="us-ascii"
Hi SK,
As for the missing values, I assume for now that they took the value of
'0'. To get what you expected,
>SK wrote:
> Hi there; thanks for the help. Here is the data structure I have (child
> So for example this algorithm would produce a flat (one childid per
> row) output dataset like so:
> childid dieps
> 104701 0
> 104841 0
> 104901 0
> 104921 2
> 104991 1
> 105011 2
> 105041 2
You can try this:
data temp;
input childid $ Day di;
cards;
104701 1 0
104701 2 0
104701 3 0
104701 4 0
104701 5 0
104701 6 0
104701 7 0
104841 1 0
104841 2 0
104841 3 0
104841 4 0
104841 5 0
104841 6 0
104841 7 0
104901 1 0
104901 2 0
104901 3 0
104901 4 0
104901 5 0
104901 6 0
104901 7 0
104921 1 0
104921 2 1
104921 3 1
104921 4 0
104921 5 0
104921 6 0
104921 7 1
104991 1 1
104991 2 1
104991 3 1
104991 4 1
104991 5 1
104991 6 1
104991 7 1
105011 1 1
105011 2 1
105011 3 .
105011 4 .
105011 5 .
105011 6 1
105011 7 1
105041 1 1
105041 2 0
105041 3 1
105041 4 0
105041 5 0
105041 6 0
105041 7 1
;
run;
data temp2;
set temp;
if di in (0,.) then delete;
run;
data temp3;
set temp2;
by childid;
lag1=lag(day);
if first.childid then lag1=0;
dif=day-lag1;
run;
proc sql;
create table want as
select childid, max(dif) as dieps from temp3 group by childid;
quit;
data want;
set want;
if dieps>2 then dieps=2;
run;
proc sql;
create table nodeps as
select distinct childid, 0 as dieps
from temp where childid not in (select childid from want);
quit;
proc append base=want data=nodeps;run;
proc sort; by childid; run;
proc print; run;
The output
Obs childid
dieps
1 104701
0
2 104841
0
3 104901
0
4 104921
2
5 104991
1
6 105011
2
7 105041
2
HTH,
Sean