Date: Wed, 30 Jul 2008 12:39:46 -0400
Reply-To: msz03@albany.edu
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mike Zdeb <msz03@ALBANY.EDU>
Subject: Re: Help with excluding events between two dates
Content-Type: text/plain;charset=iso-8859-1
hi ... in the spirit of "there cannot be too many ways to answer a question" ... another approach
is to create a format for each unique ID that has an entry for start and end dates
then in a data step, use PUTN to pick the appropriate format to use (based on the ID) and screen
the data
in these data, ID = 3 has no start and end date, so there is no format created for ID = 3
however, since the WHERE statement looks for 'OK' and the absent format produces a missing value,
this still works (and with no nasty messages in the LOG caused by that missing format)
data have;
input ID SERVICE $ @9 DOS date9. @19 DOA date9. @29 DOD date9.;
format dos doa dod date9.;
cards;
1 Blood 07JAN1997
1 Blood 16JAN1997 16JAN1997 21JAN1997
1 Blood 19JAN1997
1 Fluid 19JAN1997
1 Blood 21JAN1997
1 Blood 08FEB1999
1 Blood 09FEB1999 09FEB1999 11FEB1999
1 Blood 10FEB1999
1 Blood 11FEB1999
2 Blood 07JAN1997
2 Blood 16JAN1997 16JAN1997 21JAN1997
2 Blood 19JAN1997
2 Fluid 19JAN1997
2 Blood 21JAN1997
2 Blood 21JAN1997
2 Blood 07FEB1999 07FEB1999 08FEB1999
2 Blood 09FEB1999 09FEB1999 11FEB1999
2 Blood 10FEB1999
2 Blood 11FEB1999
2 Blood 13FEB1999
3 Blood 13FEB1999
;
run;
* write rules for the formats;
data fmx / view=fmx;
retain label 'OK';
do until (last.id);
set have;
by id;
where doa ne .;
fmtname = catt('fmt',id,'_');
start = doa;
end = dod;
output;
end;
keep fmtname start end label;
run;
* create the format;
proc format cntlin=fmx;
run;
* screen the data;
data out_of_hosp;
set have;
where putn(dos,catt('fmt',id,'_10')) ne 'OK';
run;
proc print data=out_of_hosp;
var id service dos;
run;
--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
>>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>>> Richard Van Dorn
>>> Sent: Wednesday, July 30, 2008 7:33 AM
>>> To: SAS-L@LISTSERV.UGA.EDU
>>> Subject: Help with excluding events between two dates
>>>
>>> Hello all.
>>>
>>> I have data that look like the following:
>>>
>>> ID SERVICE DOS DOA DOD
>>> 1 Blood 08FEB1999 . .
>>> 1 Blood 09FEB1999 09FEB1999 11FEB1999
>>> 1 Blood 10FEB1999 . .
>>> 1 Blood 11FEB1999 . .
>>>
>>> Service is the service provided, DOS is the date of that service, DOA
> is
>>> the
>>> date of admission to the hospital and DOD is the date of discharge
> from
>>> the
>>> hospital.
>>>
>>> I need to retain all services that took place out the hospital. For
>>> example,
>>> in the data above, the only outpatient service was a blood draw on
>>> February
>>> 8, 1999. All other blood draws took place in the hospital.
>>>
>>> Thank you.
>>> Richard
>>>
>>>
>
>