I have the following data that lists each person's hospital admission dates during a pre-defined study period. patient_id admit_dt 1 1/3/2012 1 11/21/2017 1 10/2/2018 1 10/3/2018 1 11/12/2018 1 8/21/2019 1 3/13/2021 1 5/2/2021 I want to find if a person has at least 2 hospital admissions within 2 years of each other. So far, I have the following code, but it only compares each admission to the earliest admission date. data data_out;
set data_in;
retain first_admit_dt;
by patient_id;
if first.patient_id then do;
first_admit_dt=admit_dt;
end;
else do;
ddiff=admit_dt-first_admit_dt;
if ddiff<(365*2) then admit_flag=1;
end;
format first_admit_dt mmddyy10.;
drop first_admit_dt;
run; This is the output I'm getting: patient_id admit_dt ddiff admit_flag 1 1/3/2012 . . 1 11/21/2017 2149 . 1 10/2/2018 2464 . 1 10/3/2018 2465 . 1 11/12/2018 2505 . 1 8/21/2019 2787 . 1 3/13/2021 3357 . 1 5/2/2021 3407 . However, I want to see if any of the admission dates are within 2 years of each other, not just compared to the earliest admission date. From the example above, 11/21/2017 is not within 2 years from the first admit date of 1/3/2012. However, the admit date on 10/2/2018 is within 2 years of 11/21/2017, so this person would be considered to have at least 2 admissions within 2 year of each other. Thank you
... View more