LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 21 Jul 2009 10:33:09 -0700
Reply-To:     "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Subject:      Re: count time to an event and create event var-resent
In-Reply-To:  <8b1e307f0907210955r7e448106gbd5cbe4ba76c855@mail.gmail.com>
Content-Type: text/plain; charset=windows-1252

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > heidi shea > Sent: Tuesday, July 21, 2009 9:55 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: count time to an event and create event var-resent > > For the following data, I wanted to created two new variables, "time to > event" (count # of time periods from r0 until even happend) and "event" > (event happended or not). > t_to_event and event are two new variables I wanted to created. > > Rule1: count event happended if any number from r1 to r9 > 2 (after r0). > > Rule2: if event never happend (no value is greater than 2 after r0), > "t_to_event" shoule = time from r0 to the last data point each person had > (e.g., obs1 and obs5), and record event="n". > > Additional note to rule 2: if event never happend, and subjects drop out of > the study (missing all the way to the end, never come back, e.g., obs10 and > obs12), then record event="n", but "t_to_event" = number of time perods from > r0 to the last observation: e.g., "t_to_event " for obs10 = 2, and for > obs12=1). > > Thank you very much. > > Heidi > > > obs r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 t_to_event event > 1 2 2 1 3 3 1 1 1 1 3 y > 2 1.5 2.5 1.5 2 2 1 1 1 1 1 1 y > 3 1 2 2 2 2 2 2 2 2 2 9 n > 4 2 4 1 2 1 1 y > 5 1 1 1 1 2 1 1 1 1 1 9 n > 6 2 2 2.5 1 1 1 1 1 1 2 y > 7 2 3 2.5 3 2 2 2 2 1 y > 8 2 3 2 2 2 1 y > 9 1.5 2 2 2 2 3 1 1 1 5 y > 10 2 1 1 2 n > 11 2 4 4 4 1 1 1 1 1 y > 12 1 1 1 n

Here is one possible solution

data have; input r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 _t_to_event_ _event_ $; cards; 2 2 1 3 3 1 1 1 1 . 3 y 1.5 2.5 1.5 2 2 1 1 1 1 1 1 y 1 2 2 2 2 2 2 2 2 2 9 n 2 4 1 2 1 . . . . . 1 y 1 1 1 1 2 1 1 1 1 1 9 n 2 2 2.5 1 1 1 1 1 1 . 2 y 2 3 2.5 3 2 2 2 2 . . 1 y 2 3 2 2 2 . . . . . 1 y 1.5 2 2 2 2 3 1 1 1 . 5 y 2 1 1 . . . . . . . 2 n 2 4 4 4 1 1 1 1 . . 1 y 1 1 . . . . . . . . 1 n ; run; data want; set have ; array period[0:9] r0-r9; event = 'n'; do _n_= 1 to 9; if not missing(period[_n_]) then t_to_event = _n_; if period[_n_] > 2 then do; event='y'; leave; end; end; run; proc print data=want; run;

Hope this is helpful,

Dan

Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204


Back to: Top of message | Previous page | Main SAS-L page