Date: Mon, 27 Dec 2010 15:33:25 +0800
Reply-To: Murphy Choy <goladin@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Murphy Choy <goladin@GMAIL.COM>
Subject: Re: Identify multiple births
In-Reply-To: <AANLkTimdNkxeMqTVheDUCp9HYddyU2=dy_vSc55WLzm1@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi Lily,
Apologies. I noted some errors in my solution. Can you try this solution
instead?
DATA HAVE2;
SET HAVE;
T = LAG(ID);
OLD = LAG(DOB);
IF ID ^= T THEN OLD = .;
FORMAT OLD DDMMYY10.;
RUN;
PROC SORT DATA = HAVE2 OUT = HAVE3; BY ID DESCENDING DOB DESCENDING OLD;RUN;
DATA HAVE3;
SET HAVE3;
T = LAG(ID);
NEX = LAG(DOB);
IF ID ^= T THEN NEX = .;
FORMAT NEX DDMMYY10.;
RUN;
PROC SORT DATA = HAVE3; BY ID DOB OLD NEX;RUN;
DATA HAVE4;
SET HAVE3;
BY ID DOB;
RETAIN NOOFBIRTH SINGLE TWIN TRIPLET QUINTET DT;
IF FIRST.ID THEN DO;
NOOFBIRTH = 0;
SINGLE = 0;
TWIN = 0;
TRIPLET = 0;
QUINTET = 0;
DT = 0;
END;
IF first.dob and missing(old) then do;
noofbirth = 1;dt = 1;
end;
else IF first.dob and ABS(DATDIF(DOB,OLD,'ACT/ACT')) > 1 then do;
noofbirth = noofbirth + 1;dt = 1;
end;
else do;
dt = dt + 1;
end;
if last.dob AND (MISSING(NEX) OR ABS(DATDIF(DOB,NEX,'ACT/ACT')) > 1) then
do;
IF DT = 1 THEN SINGLE = SINGLE + 1;
ELSE IF DT = 2 THEN TWIN = TWIN + 1;
ELSE IF DT = 3 THEN TRIPLET = TRIPLET + 1;
ELSE IF DT = 4 THEN QUINTET = QUINTET + 1;
dt = 0;
end;
IF LAST.ID THEN DO;
OUTPUT;
END;
DROP T DT OLD NEX;
RUN;
On Mon, Dec 27, 2010 at 3:22 PM, Chua Lily <chloegal04@gmail.com> wrote:
> Hi Murphy,
> thanks for yr program. But i encountered some errors. The problem lies with
> the LAG function.
>
> Hi Nat,
> thanks...how can i know whether each baby is a twin birth or triplet etc.
>
> On Tue, Dec 21, 2010 at 10:38 PM, Nat Wooding <nathani@verizon.net>
> wrote:
>
> > I think that your basic solution can be a little simpler than the one
> that
> > Art offered if you 1) assume that there will not be two separate
> > pregnancies
> > in same year or in January of the following year.
> >
> > For grins, I added an new mother ID, 7500, and gave her quints born on
> two
> > different days in December plus one on New Years Day.
> >
> > Nat Wooding
> >
> > data have;
> > informat Birth_Child_DOB ddmmyy10.;
> > format Birth_Child_DOB ddmmyy10.;
> > input Birth_Child_DOB Mother_ID @@;
> >
> > Year = Year( Birth_Child_DOB ) ;
> >
> > If Month(Birth_Child_Dob) = 1 then Year = Year-1;
> >
> > cards;
> > 13/2/1993 7477 3/11/1993 7478 3/1/1993 7479 14/10/1993 7480 21/1/1993
> > 7481 15/5/1993 7499 15/5/1993 7499 25/12/1994 7500 25/12/1994 7500
> > 02/01/1995 7500 25/12/1994 7500 06/12/1998 7500 26/12/1994 7500
> >
> > proc sort data=have;
> > by Mother_ID Year;
> > run;
> > ;
> > Data Births;
> >
> > do until( last.Year);
> > set have;
> > by Mother_ID Year;
> > Deliveries+1;
> > end;
> > output;
> > Deliveries = 0;
> > run;
> >
> >
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Chua
> > Lily
> > Sent: Monday, December 20, 2010 10:07 PM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: Re: Identify multiple births
> >
> > Hi,
> > sample data as follows. Multiple births refer to babies delivered at the
> > same time, eg twins, triplets.
> > Eg ID 7499 gave birth to twins. My objective is to find out the type of
> > births - single, twins, triplet etc.
> >
> > Birth_Child_DOB Mother_ID
> > 13/2/1993 7477 3/11/1993 7478 3/1/1993 7479 14/10/1993 7480 21/1/1993
> > 7481 15/5/1993 7499 15/5/1993 7499
> >
> >
> >
> > On Tue, Dec 21, 2010 at 9:41 AM, Murphy Choy <goladin@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > I think what you can do is to first sort by mother's ID and DOB.
> > >
> > > Typically using a retain statement, you can construct a baby ID for
> each
> > > birth by the mother.
> > >
> > > Using the mother's ID and baby's ID, you can than aggregate the
> results.
> > >
> > > As Dan mentioned, please remember to set up a date difference of at
> least
> > > 90 days between birth or whatever is the best!
> > >
> > >
> > > On Tue, Dec 21, 2010 at 9:16 AM, LC <chloegal04@gmail.com> wrote:
> > >
> > >> Hi,
> > >> I've some got some birth data. I would to identify twins, triplets etc
> > >> from the data. I have the mothers' unique identifier and baby date of
> > >> birth. Appreciate any inputs. Thanks!
> > >>
> > >
> > >
> > >
> > > --
> > > Regards,
> > > Murphy Choy
> > >
> > > Certified Advanced Programmer for SAS V9
> > > Certified Basic Programmer for SAS V9
> > > DataShaping Certified SAS Professional
> > >
> >
> >
>
--
Regards,
Murphy Choy
Certified Advanced Programmer for SAS V9
Certified Basic Programmer for SAS V9
DataShaping Certified SAS Professional
|