I have a dataset that looks like this:
ID start_date end_date
1 01/01/2022 01/02/2022
1 01/02/2022 01/05/2022
1 01/06/2022 01/07/2022
2 01/09/2019 01/22/2022
2 06/07/2014 09/10/2015
3 11/10/2012 02/01/2013
I am trying to create a dummy indicator to show events that are back-to-back. So far, I have been able to do the following:
data df_1;
set df_2;
by ID end_date;
lag_epi_e = lag(end_date);
if not (first.ID) then do;
date_diff= start_date- lag(end_date);
end;
format lag_epi_e date9.;
run;
The issue with this code is that it will create an indicator to show that events are back to back but is does not create an indicator for the first event, only the follow up events. Here is an example of how it looks below:
ID start_date end_date b2b_ind
1 01/01/2022 01/02/2022 0
1 01/02/2022 01/05/2022 1
1 01/06/2022 01/07/2022 1
How can I rewrite the code so that all events take on an indicator of 1 when they are back-to-back?