Date: Wed, 30 Jul 2008 12:48:12 -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 ... some editing ... the DO UNTIL stuff remained from the trail-and-error phase ... to make the
format, all that is needed is the following, making the whole job even shorter ...
* write rules for the formats;
data fmx / view=fmx;
retain label 'OK';
set have;
by id;
where doa ne .;
fmtname = catt('fmt',id,'_');
start = doa;
end = dod;
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;
--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
> 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
>
|