Contributor
Posts: 40

# Help calculating time from release to death

I have a file that has admission and release dates since Jan 1, 2011. I then created monthly dummy variables whether or not the patient was committed (see code below)

I merged this file with mortality data and now I want to create several variables examining how soon after release the patient dies.

Death data is for 2013 and 2014. Month of death in the death file is month_death and year of death is year_death. So since we do not have the actual date, we want to create variables looking at: death on same month of release, at 2 months after release, at 3 months after release, at 6 months after release, at 12 months after release, at 15 months, at 18 months, at 24 months, at 36 months, and at 48 months.

here is my code with the admission/release and monthly counts for being in hospital

data DOC_3;

set prelimdoc2;

array release (15) release1 release2 release3 release4 release5 release6 release7 release8

release9 release10 release11 release12 release13 release14 release15;

do i=1 to 15;

if admit(i)<18659 and release(i)>=18628 then DOC1=1; *Jan 2011;

if admit(i)<18687 and release(i)>=18659 then DOC2=1; *Feb 2011;

if admit(i)<18718 and release(i)>=18687 then DOC3=1; *March 2011;

if admit(i)<18748 and release(i)>=18718 then DOC4=1; *April 2011;

if admit(i)<18779 and release(i)>=18748 then DOC5=1; *May 2011;

if admit(i)<18809 and release(i)>=18779 then DOC6=1; *June 2011;

if admit(i)<18840 and release(i)>=18809 then DOC7=1; *July 2011;

if admit(i)<18871 and release(i)>=18840 then DOC8=1; *Aug 2011;

if admit(i)<18901 and release(i)>=18871 then DOC9=1; *Sept 2011;

if admit(i)<18932 and release(i)>=18901 then DOC10=1; *Oct 2011;

if admit(i)<18962 and release(i)>=18932 then DOC11=1; *Nov 2011;

if admit(i)<18993 and release(i)>=18962 then DOC12=1; *Dec 2011;

if admit(i)<19024 and release(i)>=18993 then DOC13=1; *Jan 2012;

if admit(i)<19053 and release(i)>=19024 then DOC14=1; *Feb 2012;

if admit(i)<19084 and release(i)>=19053 then DOC15=1; *March 2012;

if admit(i)<19114 and release(i)>=19084 then DOC16=1; *April 2012;

if admit(i)<19145 and release(i)>=19114 then DOC17=1; *May 2012;

if admit(i)<19175 and release(i)>=19145 then DOC18=1; *June 2012;

if admit(i)<19206 and release(i)>=19175 then DOC19=1; *July 2012;

if admit(i)<19237 and release(i)>=19206 then DOC20=1; *Aug 2012;

if admit(i)<19267 and release(i)>=19237 then DOC21=1; *Sept 2012;

if admit(i)<19298 and release(i)>=19267 then DOC22=1; *Oct 2012;

if admit(i)<19328 and release(i)>=19298 then DOC23=1; *Nov 2012;

if admit(i)<19359 and release(i)>=19328 then DOC24=1; *Dec 2012;

if admit(i)<19390 and release(i)>=19359 then DOC25=1; *Jan 2013;

if admit(i)<19418 and release(i)>=19390 then DOC26=1; *Feb 2013;

if admit(i)<19449 and release(i)>=19418 then DOC27=1; *March 2013;

if admit(i)<19479 and release(i)>=19449 then DOC28=1; *April 2013;

if admit(i)<19510 and release(i)>=19479 then DOC29=1; *May 2013;

if admit(i)<19540 and release(i)>=19510 then DOC30=1; *June 2013;

if admit(i)<19571 and release(i)>=19540 then DOC31=1; *July 2013;

if admit(i)<19602 and release(i)>=19571 then DOC32=1; *Aug 2013;

if admit(i)<19632 and release(i)>=19602 then DOC33=1; *Sept 2013;

if admit(i)<19663 and release(i)>=19632 then DOC34=1; *Oct 2013;

if admit(i)<19693 and release(i)>=19663 then DOC35=1; *Nov 2013;

if admit(i)<19724 and release(i)>=19693 then DOC36=1; *Dec 2013;

if admit(i)<19755 and release(i)>=19724 then DOC37=1; *Jan 2014;

if admit(i)<19783 and release(i)>=19755 then DOC38=1; *Feb 2014;

if admit(i)<19814 and release(i)>=19783 then DOC39=1; *March 2014;

if admit(i)<19844 and release(i)>=19814 then DOC40=1; *April 2014;

if admit(i)<19875 and release(i)>=19844 then DOC41=1; *May 2014;

if admit(i)<19905 and release(i)>=19875 then DOC42=1; *June 2014;

if admit(i)<19936 and release(i)>=19905 then DOC43=1; *July 2014;

if admit(i)<19967 and release(i)>=19936 then DOC44=1; *Aug 2014;

if admit(i)<19997 and release(i)>=19967 then DOC45=1; *Sept 2014;

if admit(i)<20028 and release(i)>=19997 then DOC46=1; *Oct 2014;

if admit(i)<20058 and release(i)>=20028 then DOC47=1; *Nov 2014;

if admit(i)<20089 and release(i)>=20058 then DOC48=1; *Dec 2014;

end;

if DOC1=. then DOC1=0;

if DOC2=. then DOC2=0;

if DOC3=. then DOC3=0;

if DOC4=. then DOC4=0;

if DOC5=. then DOC5=0;

if DOC6=. then DOC6=0;

if DOC7=. then DOC7=0;

if DOC8=. then DOC8=0;

if DOC9=. then DOC9=0;

if DOC10=. then DOC10=0;

if DOC11=. then DOC11=0;

if DOC12=. then DOC12=0;

if DOC13=. then DOC13=0;

if DOC14=. then DOC14=0;

if DOC15=. then DOC15=0;

if DOC16=. then DOC16=0;

if DOC17=. then DOC17=0;

if DOC18=. then DOC18=0;

if DOC19=. then DOC19=0;

if DOC20=. then DOC20=0;

if DOC21=. then DOC21=0;

if DOC22=. then DOC22 =0;

if DOC23=. then DOC23 =0;

if DOC24=. then DOC24 =0;

if DOC25=. then DOC25=0;

if DOC26=. then DOC26=0;

if DOC27=. then DOC27=0;

if DOC28=. then DOC28=0;

if DOC29=. then DOC29=0;

if DOC30=. then DOC30=0;

if DOC31=. then DOC31=0;

if DOC32=. then DOC32=0;

if DOC33=. then DOC33=0;

if DOC34=. then DOC34 =0;

if DOC35=. then DOC35 =0;

if DOC36=. then DOC36 =0;

if DOC13=. then DOC13=0;

if DOC14=. then DOC14=0;

if DOC15=. then DOC15=0;

if DOC16=. then DOC16=0;

if DOC17=. then DOC17=0;

if DOC18=. then DOC18=0;

if DOC19=. then DOC19=0;

if DOC20=. then DOC20=0;

if DOC21=. then DOC21=0;

if DOC22=. then DOC22 =0;

if DOC23=. then DOC23 =0;

if DOC24=. then DOC24 =0;

if DOC37=. then DOC37=0;

if DOC38=. then DOC38=0;

if DOC39=. then DOC39=0;

if DOC40=. then DOC40=0;

if DOC41=. then DOC41=0;

if DOC42=. then DOC42=0;

if DOC43=. then DOC43=0;

if DOC44=. then DOC44=0;

if DOC45=. then DOC45=0;

if DOC46=. then DOC46 =0;

if DOC47=. then DOC47 =0;

if DOC48=. then DOC48 =0;

run;

Super User
Posts: 23,776

## Re: Help calculating time from release to death

Please post sample input and output data. This code looks too complicated and I'm sure there's a way to simplify it.

Contributor
Posts: 40

## Re: Help calculating time from release to death

here is a sample data

Super User
Posts: 23,776

## Re: Help calculating time from release to death

Please simplify it, present a few cases that represent your data and include what you want as output.

## How to create a Minimal, Complete, and Verifiable example

http://stackoverflow.com/help/mcve

Discussion stats
• 3 replies
• 399 views
• 0 likes
• 2 in conversation