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
Content-Type: text/plain; charset=ISO-8859-1
Thank you! That works beautifully.
On Mon, Aug 15, 2011 at 3:51 AM, Søren Lassen <email@example.com>wrote:
> Here is a relatively simple and fast solution, that uses SET with
> proc sort data=admissions;
> by id admit_date;
> data want;
> set admissions;
> by id;
> if first.id then
> retain p_year_back;
> if admit_date>='01jan2010'd then do;
> do p_year_back=p_year_back to _N_
> set admissions(keep=admit_date rename=(admit_date=d_start))
> drop d_start;
> 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.
> 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;