I am relatively new to SAS. Currently I am taking survival analysis course, and I am really stuck on reformatting a data into 'counting process' (start, stop) form for fitting a Cox regression model with time-varying covariate (https://support.sas.com/resources/papers/proceedings12/168-2012.pdf). To keep the question short, below please find the much simplified version of the data I have now, and the format I want it to be:
data have;
input id site $ a1-a5 outcome $@@;
datalines;
1 a 1 1 0 1 1 y
1 b 0 0 1 0 0 n
2 b 1 1 0 0 0 n
2 c 0 0 1 0 1 n
2 d 0 0 0 1 0 n
3 a 1 0 0 1 0 y
;
run;
id: unique identification for each person
site: working site
a1-a5: attendance for week 1-5 (1=person works at the site in that week, 0 =otherwise)
outcome: binary outcome of interest (y/n, if the person has y, it means the event happens in his/her last attendance week)
There are actual dates for week 1-5, for example:
week 1: 2022/07/31 - 2022/08/06
week 2: 2022/08/07 - 2022/08/13
...
week 5: 2022/08/28 - 2022/09/03
Note that not everyone works every week, and some people work at different sites. I am not too sure if it is necessary but I would like to introduce a week indicator variable named 'week', as well as the start and stop variables so that the data format becomes:
data want;
input id site start $ stop $ week outcome @@;
datalines;
1 a 2022/07/31 2022/08/06 1 n
1 a 2022/08/07 2022/08/13 2 n
1 b 2022/08/14 2022/08/20 3 n
1 a 2022/08/21 2022/08/27 4 n
1 a 2022/08/28 2022/09/03 5 y
2 b 2022/07/31 2022/08/06 1 n
2 b 2022/08/07 2022/08/13 2 n
2 c 2022/08/14 2022/08/20 3 n
2 d 2022/08/21 2022/08/27 4 n
2 c 2022/08/28 2022/09/03 5 n
3 a 2022/07/31 2022/08/06 1 n
3 a 2022/08/21 2022/08/27 4 y
;
run;
My concern is that since some people stay in the same working site throughout the entire time, some switch sites, some switch sites multiple times, some switch back and forth, some don't show up in some weeks, I just could not find the proper logic that could apply to the data (over 1000 people). Might someone be willing to provide guidance?
Thank you