Number of days in hospital by calendar month across multiple years?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Number of days in hospital by calendar month across multiple years?

Eugene Wang
Hi,

I am new to the list, and am trying to find a way to generalize the syntax that Raynald Levesque has on his website that computes number of days in hospital by calendar month.  The current syntax only computes within the same calendar year, and I would like to find a way to generalize the code so that it will work with any set of beginning and ending dates.


*(A) Posted to SPSSX-L by [hidden email] on 2001/11/20.

* Note: The following syntax is not completely general. 
*       It assumes that all dates are in the same calendar year.

DATA LIST LIST /id(F8) datein(ADATE) dateout(ADATE).
BEGIN DATA
1 1/5/01 2/5/01
2 2/7/01 3/7/01
3 4/3/01 5/25/01
4 2/1/01 4/4/01
5 1/31/01 4/1/01
6 7/1/01 9/29/01
7 9/10/01 12/30/01
END DATA.
LIST.

VECTOR month(12F8).
COMPUTE #oneday=24*60*60.
LOOP mth=1 TO 12.
COMPUTE beg1=MAX(datein , DATE.DMY(1,mth,XDATE.YEAR(datein))).
COMPUTE end1=MIN(dateout + #oneday, DATE.DMY(1,mth+1,XDATE.YEAR(datein))).
COMPUTE month(mth)=max(0, CTIME.DAYS(end1 - beg1)).
END LOOP.
EXECUTE.

Thanks in advance,


-- 
Eugene Wang, Ph.D.
Assistant Professor
Educational Psychology
Texas Tech University

Reply | Threaded
Open this post in threaded view
|

Re: Number of days in hospital by calendar month across multiple years?

Maguin, Eugene
Eugene

It seems like this your question has very simple answer but it apparently
doesn't. Ray's syntax is (or seems to be) to complex for that. Maybe it
would be helpful to define 'days in hospital' or 'hospital days', which is
the term that Ray uses on his website.



I am new to the list, and am trying to find a way to generalize the syntax
that Raynald Levesque has on his website that computes number of days in
hospital by calendar month.  The current syntax only computes within the
same calendar year, and I would like to find a way to generalize the code so
that it will work with any set of beginning and ending dates.

Here is the link, and below is the code from his website:
http://www.spsstools.net/Syntax/DatesTime/BreakDownNumberOfDaysInHospitalByC
alendarMonth.txt

*(A) Posted to SPSSX-L by [hidden email] on 2001/11/20.
* Note: The following syntax is not completely general.
*       It assumes that all dates are in the same calendar year.

DATA LIST LIST /id(F8) datein(ADATE) dateout(ADATE).
BEGIN DATA
1 1/5/01 2/5/01
2 2/7/01 3/7/01
3 4/3/01 5/25/01
4 2/1/01 4/4/01
5 1/31/01 4/1/01
6 7/1/01 9/29/01
7 9/10/01 12/30/01
END DATA.
LIST.

VECTOR month(12F8).
COMPUTE #oneday=24*60*60.
LOOP mth=1 TO 12.
COMPUTE beg1=MAX(datein , DATE.DMY(1,mth,XDATE.YEAR(datein))).
COMPUTE end1=MIN(dateout + #oneday, DATE.DMY(1,mth+1,XDATE.YEAR(datein))).
COMPUTE month(mth)=max(0, CTIME.DAYS(end1 - beg1)).
END LOOP.
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Number of days in hospital by calendar month across multiple years?

Eugene Wang
Thanks--it basically could be any number of days in a setting (hospital, school etc.).  Actually, in my case I want to know the number of days per month kids are in juvenile detention.  I have 2 dates--admission and discharge--that go back to 1999 and continue through 2010.


Eugene



-------------------------------

Eugene Wang, Ph.D.
Assistant Professor
Educational Psychology
Texas Tech University


On Mon, Jan 31, 2011 at 9:45 AM, Gene Maguin <[hidden email]> wrote:
Eugene

It seems like this your question has very simple answer but it apparently
doesn't. Ray's syntax is (or seems to be) to complex for that. Maybe it
would be helpful to define 'days in hospital' or 'hospital days', which is
the term that Ray uses on his website.



I am new to the list, and am trying to find a way to generalize the syntax
that Raynald Levesque has on his website that computes number of days in
hospital by calendar month.  The current syntax only computes within the
same calendar year, and I would like to find a way to generalize the code so
that it will work with any set of beginning and ending dates.

Here is the link, and below is the code from his website:
<a href="http://www.spsstools.net/Syntax/DatesTime/BreakDownNumberOfDaysInHospitalByC alendarMonth.txt" target="_blank">http://www.spsstools.net/Syntax/DatesTime/BreakDownNumberOfDaysInHospitalByC
alendarMonth.txt

*(A) Posted to SPSSX-L by [hidden email] on 2001/11/20.
* Note: The following syntax is not completely general.
*       It assumes that all dates are in the same calendar year.

DATA LIST LIST /id(F8) datein(ADATE) dateout(ADATE).
BEGIN DATA
1 1/5/01 2/5/01
2 2/7/01 3/7/01
3 4/3/01 5/25/01
4 2/1/01 4/4/01
5 1/31/01 4/1/01
6 7/1/01 9/29/01
7 9/10/01 12/30/01
END DATA.
LIST.

VECTOR month(12F8).
COMPUTE #oneday=24*60*60.
LOOP mth=1 TO 12.
COMPUTE beg1=MAX(datein , DATE.DMY(1,mth,XDATE.YEAR(datein))).
COMPUTE end1=MIN(dateout + #oneday, DATE.DMY(1,mth+1,XDATE.YEAR(datein))).
COMPUTE month(mth)=max(0, CTIME.DAYS(end1 - beg1)).
END LOOP.
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Number of days in hospital by calendar month across multiple years?

Marks, Jim
In reply to this post by Eugene Wang
Not tested, but if you know the total months in the sample, you can edit the loop to go from 1 to n.

You also will need to edit the month calculation to somerthing like

month - 12*(XDATE.YEAR(date) - 1999)

to produce a value of 12 for the second year, 24 for year three and so on

Jim


From: SPSSX(r) Discussion <[hidden email]>
To: [hidden email] <[hidden email]>
Sent: Mon Jan 31 10:34:10 2011
Subject: Re: Number of days in hospital by calendar month across multiple years?

Thanks--it basically could be any number of days in a setting (hospital, school etc.).  Actually, in my case I want to know the number of days per month kids are in juvenile detention.  I have 2 dates--admission and discharge--that go back to 1999 and continue through 2010.


Eugene



-------------------------------

Eugene Wang, Ph.D.
Assistant Professor
Educational Psychology
Texas Tech University


On Mon, Jan 31, 2011 at 9:45 AM, Gene Maguin <[hidden email]> wrote:
Eugene

It seems like this your question has very simple answer but it apparently
doesn't. Ray's syntax is (or seems to be) to complex for that. Maybe it
would be helpful to define 'days in hospital' or 'hospital days', which is
the term that Ray uses on his website.



I am new to the list, and am trying to find a way to generalize the syntax
that Raynald Levesque has on his website that computes number of days in
hospital by calendar month.  The current syntax only computes within the
same calendar year, and I would like to find a way to generalize the code so
that it will work with any set of beginning and ending dates.

Here is the link, and below is the code from his website:
<a href="http://www.spsstools.net/Syntax/DatesTime/BreakDownNumberOfDaysInHospitalByC alendarMonth.txt" target="_blank">http://www.spsstools.net/Syntax/DatesTime/BreakDownNumberOfDaysInHospitalByC
alendarMonth.txt

*(A) Posted to SPSSX-L by [hidden email] on 2001/11/20.
* Note: The following syntax is not completely general.
*       It assumes that all dates are in the same calendar year.

DATA LIST LIST /id(F8) datein(ADATE) dateout(ADATE).
BEGIN DATA
1 1/5/01 2/5/01
2 2/7/01 3/7/01
3 4/3/01 5/25/01
4 2/1/01 4/4/01
5 1/31/01 4/1/01
6 7/1/01 9/29/01
7 9/10/01 12/30/01
END DATA.
LIST.

VECTOR month(12F8).
COMPUTE #oneday=24*60*60.
LOOP mth=1 TO 12.
COMPUTE beg1=MAX(datein , DATE.DMY(1,mth,XDATE.YEAR(datein))).
COMPUTE end1=MIN(dateout + #oneday, DATE.DMY(1,mth+1,XDATE.YEAR(datein))).
COMPUTE month(mth)=max(0, CTIME.DAYS(end1 - beg1)).
END LOOP.
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Number of days in hospital by calendar month across multiple years?

Maguin, Eugene
In reply to this post by Eugene Wang
Eugene,
 
Have you looked at the DateDiff function? Would that do what you want?
 
Eugene


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Eugene Wang
Sent: Monday, January 31, 2011 11:34 AM
To: [hidden email]
Subject: Re: Number of days in hospital by calendar month across multiple years?

Thanks--it basically could be any number of days in a setting (hospital, school etc.).  Actually, in my case I want to know the number of days per month kids are in juvenile detention.  I have 2 dates--admission and discharge--that go back to 1999 and continue through 2010.


Eugene



-------------------------------

Eugene Wang, Ph.D.
Assistant Professor
Educational Psychology
Texas Tech University


On Mon, Jan 31, 2011 at 9:45 AM, Gene Maguin <[hidden email]> wrote:
Eugene

It seems like this your question has very simple answer but it apparently
doesn't. Ray's syntax is (or seems to be) to complex for that. Maybe it
would be helpful to define 'days in hospital' or 'hospital days', which is
the term that Ray uses on his website.



I am new to the list, and am trying to find a way to generalize the syntax
that Raynald Levesque has on his website that computes number of days in
hospital by calendar month.  The current syntax only computes within the
same calendar year, and I would like to find a way to generalize the code so
that it will work with any set of beginning and ending dates.

Here is the link, and below is the code from his website:
http://www.spsstools.net/Syntax/DatesTime/BreakDownNumberOfDaysInHospitalByC
alendarMonth.txt


*(A) Posted to SPSSX-L by [hidden email] on 2001/11/20.
* Note: The following syntax is not completely general.
*       It assumes that all dates are in the same calendar year.

DATA LIST LIST /id(F8) datein(ADATE) dateout(ADATE).
BEGIN DATA
1 1/5/01 2/5/01
2 2/7/01 3/7/01
3 4/3/01 5/25/01
4 2/1/01 4/4/01
5 1/31/01 4/1/01
6 7/1/01 9/29/01
7 9/10/01 12/30/01
END DATA.
LIST.

VECTOR month(12F8).
COMPUTE #oneday=24*60*60.
LOOP mth=1 TO 12.
COMPUTE beg1=MAX(datein , DATE.DMY(1,mth,XDATE.YEAR(datein))).
COMPUTE end1=MIN(dateout + #oneday, DATE.DMY(1,mth+1,XDATE.YEAR(datein))).
COMPUTE month(mth)=max(0, CTIME.DAYS(end1 - beg1)).
END LOOP.
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Number of days in hospital by calendar month across multiple years?

ariel barak
In reply to this post by Eugene Wang
Hi Eugene,

I worked with juvenile detention center data too. Here is Richard Ristow's solution, which worked perfectly for me - http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0807&L=spssx-l&P=R26170

I always wanted census days, so I had to be sure to set missing values (1/1/1900) in my case for youth who had not yet been released to today's date and flag those records and not having been released yet. This creates a record for each day between the admit date and the end date. If you had one person who entered juvenile detention on 1/2/2011 and left on 1/5/2011, you would have 4 records in the unrolled file.

Here is the syntax I used:


COMPUTE Released=1.
IF (End__Date = DATE.MDY(1,1,1900)) Released=0.
EXE.

*Enters todays date for the purposes of doing Census Days/ADP.
IF End__Date = DATE.MDY(1,1,1900) End__Date=NUMBER($date11,date11).
EXE.

NUMERIC Today            (DATE11)
   /AdmitToday DischToday (F2).
VAR LABEL
    Today      "Date, within patient's hospital stay"
    AdmitToday "Flag: Patient admitted this date"
    DischToday "Flag: Patient discharged this date".

LOOP  Today = Statrt_Date TO End__Date BY TIME.DAYS(1).
.  COMPUTE AdmitToday = (Today EQ Statrt_Date).
.  COMPUTE DischToday = (Today EQ End__Date).
.  XSAVE OUTFILE='H:\Syntax Files\Census Days - unroll.sav'
    /KEEP=Patient_Number Admission_Number Program_Code Statrt_Date End__Date  RACE_CODE race Sex Birth_Date
Today AdmitToday DischToday.
END LOOP.
EXECUTE  /* this one is needed */.

GET FILE='H:\Syntax Files\Census Days - unroll.sav'.
DATASET NAME CensusDaysCreated WINDOW=FRONT.

COMPUTE Month=XDATE.MONTH(Today).
COMPUTE Year=XDATE.YEAR(Today).
EXE.


After you have this, I used Aggregate and CasesToVars (Data>Restructure>Restructure Selected Cases into Variables) to restructure the data for Average Daily Population and admissions by month by year by race by age by sex...however you want to slice it. Just modify the Keep command above for the variable that you want to keep and rename the location where you will save the unrolled data - in the XSAVE and the GET FILE commands. Also, make sure to change the names of your start and end dates to match your dataset.

Good luck!

-Ariel Barak


On Mon, Jan 31, 2011 at 10:34 AM, Eugene Wang <[hidden email]> wrote:
Thanks--it basically could be any number of days in a setting (hospital, school etc.).  Actually, in my case I want to know the number of days per month kids are in juvenile detention.  I have 2 dates--admission and discharge--that go back to 1999 and continue through 2010.


Eugene



-------------------------------


Eugene Wang, Ph.D.
Assistant Professor
Educational Psychology
Texas Tech University


On Mon, Jan 31, 2011 at 9:45 AM, Gene Maguin <[hidden email]> wrote:
Eugene

It seems like this your question has very simple answer but it apparently
doesn't. Ray's syntax is (or seems to be) to complex for that. Maybe it
would be helpful to define 'days in hospital' or 'hospital days', which is
the term that Ray uses on his website.



I am new to the list, and am trying to find a way to generalize the syntax
that Raynald Levesque has on his website that computes number of days in
hospital by calendar month.  The current syntax only computes within the
same calendar year, and I would like to find a way to generalize the code so
that it will work with any set of beginning and ending dates.

Here is the link, and below is the code from his website:
http://www.spsstools.net/Syntax/DatesTime/BreakDownNumberOfDaysInHospitalByC
alendarMonth.txt


*(A) Posted to SPSSX-L by [hidden email] on 2001/11/20.
* Note: The following syntax is not completely general.
*       It assumes that all dates are in the same calendar year.

DATA LIST LIST /id(F8) datein(ADATE) dateout(ADATE).
BEGIN DATA
1 1/5/01 2/5/01
2 2/7/01 3/7/01
3 4/3/01 5/25/01
4 2/1/01 4/4/01
5 1/31/01 4/1/01
6 7/1/01 9/29/01
7 9/10/01 12/30/01
END DATA.
LIST.

VECTOR month(12F8).
COMPUTE #oneday=24*60*60.
LOOP mth=1 TO 12.
COMPUTE beg1=MAX(datein , DATE.DMY(1,mth,XDATE.YEAR(datein))).
COMPUTE end1=MIN(dateout + #oneday, DATE.DMY(1,mth+1,XDATE.YEAR(datein))).
COMPUTE month(mth)=max(0, CTIME.DAYS(end1 - beg1)).
END LOOP.
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


Reply | Threaded
Open this post in threaded view
|

Re: Number of days in hospital by calendar month across multiple years?

Eugene Wang
Thanks Ariel -- worked exactly as I needed it to.


Eugene


-- 
Eugene Wang, Ph.D.
Assistant Professor
Educational Psychology
Texas Tech University

On Monday, January 31, 2011 at 11:30 AM, Ariel Barak wrote:

Hi Eugene,

I worked with juvenile detention center data too. Here is Richard Ristow's solution, which worked perfectly for me - http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0807&L=spssx-l&P=R26170

I always wanted census days, so I had to be sure to set missing values (1/1/1900) in my case for youth who had not yet been released to today's date and flag those records and not having been released yet. This creates a record for each day between the admit date and the end date. If you had one person who entered juvenile detention on 1/2/2011 and left on 1/5/2011, you would have 4 records in the unrolled file.

Here is the syntax I used:


COMPUTE Released=1.
IF (End__Date = DATE.MDY(1,1,1900)) Released=0.
EXE.

*Enters todays date for the purposes of doing Census Days/ADP.
IF End__Date = DATE.MDY(1,1,1900) End__Date=NUMBER($date11,date11).
EXE.

NUMERIC Today            (DATE11)
   /AdmitToday DischToday (F2).
VAR LABEL
    Today      "Date, within patient's hospital stay"
    AdmitToday "Flag: Patient admitted this date"
    DischToday "Flag: Patient discharged this date".

LOOP  Today = Statrt_Date TO End__Date BY TIME.DAYS(1).
.  COMPUTE AdmitToday = (Today EQ Statrt_Date).
.  COMPUTE DischToday = (Today EQ End__Date).
.  XSAVE OUTFILE='H:\Syntax Files\Census Days - unroll.sav'
    /KEEP=Patient_Number Admission_Number Program_Code Statrt_Date End__Date  RACE_CODE race Sex Birth_Date
Today AdmitToday DischToday.
END LOOP.
EXECUTE  /* this one is needed */.

GET FILE='H:\Syntax Files\Census Days - unroll.sav'.
DATASET NAME CensusDaysCreated WINDOW=FRONT.

COMPUTE Month=XDATE.MONTH(Today).
COMPUTE Year=XDATE.YEAR(Today).
EXE.


After you have this, I used Aggregate and CasesToVars (Data>Restructure>Restructure Selected Cases into Variables) to restructure the data for Average Daily Population and admissions by month by year by race by age by sex...however you want to slice it. Just modify the Keep command above for the variable that you want to keep and rename the location where you will save the unrolled data - in the XSAVE and the GET FILE commands. Also, make sure to change the names of your start and end dates to match your dataset.

Good luck!

-Ariel Barak


On Mon, Jan 31, 2011 at 10:34 AM, Eugene Wang <[hidden email]> wrote:
Thanks--it basically could be any number of days in a setting (hospital, school etc.).  Actually, in my case I want to know the number of days per month kids are in juvenile detention.  I have 2 dates--admission and discharge--that go back to 1999 and continue through 2010.


Eugene



-------------------------------


Eugene Wang, Ph.D.
Assistant Professor
Educational Psychology
Texas Tech University


On Mon, Jan 31, 2011 at 9:45 AM, Gene Maguin <[hidden email]> wrote:
Eugene

It seems like this your question has very simple answer but it apparently
doesn't. Ray's syntax is (or seems to be) to complex for that. Maybe it
would be helpful to define 'days in hospital' or 'hospital days', which is
the term that Ray uses on his website.



I am new to the list, and am trying to find a way to generalize the syntax
that Raynald Levesque has on his website that computes number of days in
hospital by calendar month.  The current syntax only computes within the
same calendar year, and I would like to find a way to generalize the code so
that it will work with any set of beginning and ending dates.

Here is the link, and below is the code from his website:
http://www.spsstools.net/Syntax/DatesTime/BreakDownNumberOfDaysInHospitalByC
alendarMonth.txt


*(A) Posted to SPSSX-L by [hidden email] on 2001/11/20.
* Note: The following syntax is not completely general.
*       It assumes that all dates are in the same calendar year.

DATA LIST LIST /id(F8) datein(ADATE) dateout(ADATE).
BEGIN DATA
1 1/5/01 2/5/01
2 2/7/01 3/7/01
3 4/3/01 5/25/01
4 2/1/01 4/4/01
5 1/31/01 4/1/01
6 7/1/01 9/29/01
7 9/10/01 12/30/01
END DATA.
LIST.

VECTOR month(12F8).
COMPUTE #oneday=24*60*60.
LOOP mth=1 TO 12.
COMPUTE beg1=MAX(datein , DATE.DMY(1,mth,XDATE.YEAR(datein))).
COMPUTE end1=MIN(dateout + #oneday, DATE.DMY(1,mth+1,XDATE.YEAR(datein))).
COMPUTE month(mth)=max(0, CTIME.DAYS(end1 - beg1)).
END LOOP.
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD