Hi,
I need to calculate days admitted to hospital for the first 30 days after surgery. I do not want to include the actual day of surgery. Maximum stay is hence 30 days. The dataset comprises a little more than 1 million patients. I have provided a dataex with a few problematic example patients.
ID is patient-id.
SurgeryDate is date of surgery.
InDate is date of admission to a hospital or ward within the same hospital
OutDate is date of discharge from hospital or from a ward.
Each ID could have several hospital/ward stays, so I need to sum these for each ID. My problem is that patients are often moved between wards (or hospitals) so the discharge date is often the same as the next observations admission date (for example ID 4, discharged 20apr2020, admitted 20apr2020). Another problem is that hospital stays are sometimes overlapping each other (ID 6 is a horrible example of this). Sometimes the day of surgery is not included in a hospital stay but is performed as day-care-surgery (ID 5).
So for example, ID 7 should have a total of five days admitted: First observation 0 days - Surgery date, excluded. Second obs 1 day - 13 feb. Third obs 1 day - 14 feb. Fourth obs 3 days - 15-17 feb.
I can sum the days of all hospital admissions, and subtract a day for the surgery date. But I am struggling to find a way that deals with combinations of overlapping stays and repeated admission dates. Any ideas?
I need to calculate days admitted to hospital for the first 30 days after surgery. I do not want to include the actual day of surgery. Maximum stay is hence 30 days. The dataset comprises a little more than 1 million patients. I have provided a dataex with a few problematic example patients.
ID is patient-id.
SurgeryDate is date of surgery.
InDate is date of admission to a hospital or ward within the same hospital
OutDate is date of discharge from hospital or from a ward.
Each ID could have several hospital/ward stays, so I need to sum these for each ID. My problem is that patients are often moved between wards (or hospitals) so the discharge date is often the same as the next observations admission date (for example ID 4, discharged 20apr2020, admitted 20apr2020). Another problem is that hospital stays are sometimes overlapping each other (ID 6 is a horrible example of this). Sometimes the day of surgery is not included in a hospital stay but is performed as day-care-surgery (ID 5).
So for example, ID 7 should have a total of five days admitted: First observation 0 days - Surgery date, excluded. Second obs 1 day - 13 feb. Third obs 1 day - 14 feb. Fourth obs 3 days - 15-17 feb.
I can sum the days of all hospital admissions, and subtract a day for the surgery date. But I am struggling to find a way that deals with combinations of overlapping stays and repeated admission dates. Any ideas?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float ID int(SurgeryDate InDate OutDate) 1 22261 22261 22261 1 22261 22262 22263 2 22597 22595 22601 3 22806 22779 22806 3 22806 22805 22812 3 22806 22813 22827 4 22025 22024 22025 4 22025 22025 22028 4 22025 22031 22040 4 22025 22042 22042 4 22025 22047 22047 5 21671 21672 21672 5 21671 21672 21674 5 21671 21673 21673 5 21671 21680 21687 5 21671 21698 21701 6 22151 22151 22152 6 22151 22151 22153 6 22151 22153 22154 6 22151 22154 22159 6 22151 22174 22175 6 22151 22175 22178 6 22151 22179 22181 6 22151 22181 22181 7 22688 22688 22688 7 22688 22688 22689 7 22688 22688 22690 7 22688 22690 22693 end format %td SurgeryDate format %td InDate format %td OutDate
Comment