Date: Fri, 22 Oct 1999 14:04:00 -0400
Reply-To: Quentin McMullen <Quentin_McMullen@ABTASSOC.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Quentin McMullen <Quentin_McMullen@ABTASSOC.COM>
Subject: Re: scanning 1 variable against others
Content-Type: multipart/mixed;
There are probably better solutions, but I recently came up with the
following to handle a similar situation. Basically I transpose the
file with the start and stop dates for each range, then merge on the
event dates and run over arrays to check if the event is within *any*
range for each id. Worked for me cuz the max number of ranges for an
ID was seven. I don't know SQL, but I think you can merge in SQL with
multiple by values and have it produce one record for each possible
combination of by values (can't do this with merge, AFAIK). No doubt
SQL will handle something like this much better, and you'll probably
get better non-SQL solutions as well.
HTH,
--Q.
data range;
input id start stop;
cards;
1 2 5
1 6 7
1 8 10
2 1 3
2 5 9
2 10 14
;
run;
data event;
input id date;
cards;
1 1
1 3
1 6
2 2
2 4
2 5
2 7
;
run;
data a;
set range;
by id;
if first.id then period=0; *counter for number of time periods;
period+1;
run;
proc print data=a;run;
proc transpose data=a out=b;
var start stop;
by id period;
run;
proc print data=b;run;
data c;
set b;
_name_=compress(_name_||period);
run;
proc print data=c;run;
proc transpose data=c out=d;
var col1;
by id;
run;
proc print data=d;run;
data both;
merge event (keep=id date)
d (keep=id start1-start3 stop1-stop3)
;
by id;
array start{3};
array stop{3};
do i=1 to dim(start);
if start{i}<=date<=stop{i} then in=1;
end;
if in=. then in=0;
run;
proc print data=both;run;
______________________________ Reply Separator _________________________________
Subject: scanning 1 variable against others
Author: Mahboobeh Safaeian <msafaeia@JHSPH.EDU> at internet
Date: 10/22/1999 12:53 PM
can you please suggest how to take the datex variable, scan it against the
date-6m and date, if it falls within the range to get a 1 value, if none of
the datex fall within the date-6m & date range to return a 0 value?
thanks
mahboobeh
<html>
<font size=2>Dear list members:<br>
<br>
i have a data set as follows:<br>
<br>
<b>id
<x-tab> </x-tab>
date-6m date<br>
</b>10019 04/20/94
10/19/94 <br>
10019 10/11/94
04/11/95 <br>
10019 05/12/95
11/10/95 <br>
10019 10/12/95
04/11/96 <br>
10019 03/26/96
09/24/96<br>
<br>
i have another data set with the following<br>
<br>
<b>id<x-tab> </x-tab>
datex<br>
</font></b><font face="Arial, Helvetica" size=2>10019
09/20/94 <br>
10019 10/13/94 <br>
10019 11/03/94 <br>
10019 11/22/94 <br>
10019 12/09/94 <br>
10019 12/15/94 <br>
10019 03/24/95 <br>
10019 03/31/95 <br>
10019 04/07/95 <br>
10019 04/13/95 <br>
10019 04/21/95 <br>
10019 04/27/95 <br>
10019 05/04/95 <br>
10019 05/08/95 <br>
10019 07/06/95 <br>
10019 11/13/95 <br>
10019 11/20/95 <br>
10019 11/20/95 <br>
<br>
can you please suggest how to take the datex variable, scan it against
the date-6m and date, if it falls within the range to get a 1 value, if
none of the datex fall within the date-6m & date range to return a 0
value?<br>
<br>
thanks<br>
mahboobeh </font></html>