Hi,
I have tried to solve this problem by modifying similar codes I found from this forum but so far without success. I need to calculate the time each patient (A1=Patient id) have had medication in each year 2011-2017. Unfortunately the data is not perfect and there are overlapping dates (even though there should not be) and quite many cases are missing the end date.
It is not possible for me to know for sure if the missing end date is there on purpose (=the medication is on) or if they forgot to enter the end date to the medical records. For now, I will assume that the mediation is still on if there is no end date and new mediation phase has not been started for the patient. Additionally, the last medication phase should end at time the person dies (D1=Time of death).
I have managed to calculate the time in days for each year (2011_days_sum, 2012_sum, etc.), but the overlapping dates were causing issues. I have manually fixed this sample data to look somewhat how it should look, though there may be mistakes.
Best regards
Teppo
Bookmarks