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 (August 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 22 Aug 2011 17:09:56 -0600
Reply-To:     Emily Sim <emilyssim@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Emily Sim <emilyssim@GMAIL.COM>
Subject:      Re: Counting Number of Obs with changing
Comments: To: Søren Lassen <s.lassen@post.tele.dk>
In-Reply-To:  <201108150951.p7F5LPqm024899@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

Thank you! That works beautifully. -Emily

On Mon, Aug 15, 2011 at 3:51 AM, Søren Lassen <s.lassen@post.tele.dk>wrote:

> Emily, > Here is a relatively simple and fast solution, that uses SET with > POINT=: > > proc sort data=admissions; > by id admit_date; > run; > > data want; > set admissions; > by id; > if first.id then > p_year_back=_N_; > retain p_year_back; > if admit_date>='01jan2010'd then do; > do p_year_back=p_year_back to _N_ > until(d_start>=intnx('year',admit_date,-1,'SAMEDAY')); > set admissions(keep=admit_date rename=(admit_date=d_start)) > point=p_year_back; > end; > prev_admit=_N_-p_year_back; > end; > drop d_start; > run; > > Just make sure that your input table does not contain deleted observations, > as that may will destroy the correlation between the pointer and _N_ > - adding the FORCE option to PROC SORT will make absolutely sure. > > Regards, > Søren > > On Fri, 12 Aug 2011 18:50:13 -0400, Emily Sim <emilyssim@GMAIL.COM> wrote: > > >Hi All, > >I have 2009 and 2010 hospital admissions for a set of patients. For each > >of the admissions in 2010 only, I need to calculate how many previous > >admissions that patient had within 365 days of that admission. Any ideas > >how to do this? More explanation and dataset below. Thank you! > > > >For example, for the dataset below, patient 1's first obs in 2010 is the > >1/1/2010 admit for which there were 2 previous admits within 365 days. > >The next obs for that patient (admit date 3/15/2010) has 3 previous admits > >in 365 days. Because the other admits for that patient are greater than > >365 days from some of the previous admits, the remaining admits only have > >4 previous admits each (within the 365 day criteria). > > > > > > > >My dataset looks like this: > > > >data admissions; > > input ID $ 1 > > @2 ADMIT_DATE MMDDYY10. > > @12 DISCH_DATE MMDDYY10. > > ; > >format ADMIT_DATE DISCH_DATE mmddyy10.; > > > > cards; > >109/10/200909/13/2009 > >111/01/200911/03/2009 > >101/01/201001/05/2010 > >103/15/201003/17/2010 > >104/01/201004/03/2010 > >109/25/201009/27/2010 > >112/29/201012/30/2010 > >201/25/200901/27/2009 > >211/15/200911/17/2009 > >212/25/200912/27/2009 > >201/10/201001/12/2010 > >206/12/201006/15/2010 > >212/01/201012/03/2010 > >; > >run; >


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