Date: Mon, 28 Apr 2008 15:02:39 -0400
Reply-To: Jack Clark <JClark@CHPDM.UMBC.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Clark <JClark@CHPDM.UMBC.EDU>
Subject: Re: Length of stay by month
Content-Type: text/plain; charset="utf-8"
Here is one approach. It creates a format for the month numbers (1-88). The data you have with admit and discharge dates is used to create a data set with one observation for each day of the stay. Then, that data set is summarized with PROC SUMMARY at the ID and Month level - using the PRELOADFMT and COMPLETETYPES options to include all months for each ID.
Hope this helps.
* create data set with month and corresponding numbers ;
data monfmt (drop=months i);
retain months '01NOV1999'd fmtname '$monnum' ;
do i = 1 to 88;
start = put(months,monyy.);
label = put(i,2.);
months = intnx('month', months, 1);
* create format of month numbers ;
proc format cntlin=monfmt;
* print format for audit (optional);
proc format library=work fmtlib;
* test data ;
id=1; admit='29JAN2003'd; discharge='30JAN2003'd; output;
id=1; admit='12MAR2003'd; discharge='03APR2003'd; output;
id=2; admit='01JAN2005'd; discharge='30JAN2005'd; output;
* create 1 obs per day for stay ;
data need1 (keep=id month);
do i=admit to discharge;
month = put(i,monyy.);
* summarize days/month per id and apply formatting ;
proc summary data = need1 nway order=formatted completetypes;
class month / preloadfmt;
format month $monnum.;
output out = need2 (rename=(_freq_=los) drop=_type_);
proc print data = need2;
Center for Health Program Development and Management
University of Maryland, Baltimore County
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Richard Van Dorn
Sent: Monday, April 28, 2008 1:18 PM
Subject: Length of stay by month
I have a question about calculating length of stay (LOS) by month. Iâ€™ve
searched the Listâ€™s Archives and havenâ€™t found a solution that meets my
needs; however, I apologize in advance if Iâ€™ve missed an already discussed
solution. Currently, my data are currently structured as:
ID admit discharge
1 29JAN2003 30JAN2003
1 12MAR2003 03APR2003
From these data I would like to create a variable for LOS for each month (in
these data there are a total of 88 months, which start on 01NOV1999 and end
on 28FEB2007). For example, for the month of January 2003 subject ID 1 was
in the hospital for 2 days that month (I am counting both the admit and
discharge dates as separate days). However, for the month of March this
person was in the hospital from the 12th through the end of the month (31st)
for a total of 20 days; this particular visit, however, spanned 2 months so
there are an additional 3 days for April.
Eventually, I would like for the data to look like this (in this example
January 2003 is equal to the 39th month [of 88 total] in the data; month 40
is equal to February 2003, which had no hospitalization days; month 41 is
equal to March 2003 and month 42 is equal to April 2003):
ID Month LOS
1 1 0
1 2 0
. . .
. . .
. . .
1 39 2
1 40 0
1 41 20
1 42 3
1 . .
1 . .
1 . .
1 88 0
Thank you for giving this some thought and I certainly appreciate any help
you can provide!