Hello, I am trying to figure out the best way to program in SAS a way to do a "look-back" where I can apply a patient's history of different health conditions to more recent visits, in particular in the event the patient has missing diagnosis data for some visits. I would like to implement a 1-year "look-back" period to see if a patient has had a history of different diseases and indicate that in a new 0/1 or Yes/No variable. The term lookback may be a misnomer where I believe the best way to program this in SAS would to be to sort by patient ID and visit date use a RETAIN statement in a data step and then retain this value for a year if Hypertension=1. But if there is a better way to program this in SAS then that would be great too. I am working with medical visit data where I have unique patient ID, data of visit, and a dummy variable indicator for presence of hypertension recorded at that visit. I have provided some example data below, and included the desired outcome in the column Hypertension_Lookback for a 1-year lookback period. In this example Patient 1 would have more recent visits where Hypertension_Lookback=1, as would Patient 2 for their most recent visit, but not their earlier visit before their first recorded instance of hypertension. Additionally, if I am using a 1-year cutoff, patient 5 would not have a history of hypertension indicated as the most recent visit was more than 1 year from the last visit with an indicator of Hypertension. PatientId VisitDate Hypertension Hypertension_Lookback 1 1/1/2023 1 1 1 2/1/2023 0 1 1 3/1/2023 0 1 2 1/1/2023 0 0 2 2/1/2023 1 1 2 3/1/2023 0 1 3 1/1/2023 1 1 3 2/1/2023 1 1 4 1/1/2023 0 0 4 2/1/2023 0 0 5 1/1/2023 1 1 5 2/1/2024 0 0
... View more