Hi all, I have the data like this: data have; infile datalines delimiter=','; attrib id length=$1 visit_date format=date9. informat=date9. death_date format=date9. informat=date9. ; input id $ visit_date death death_date disease; *format id best. visit_date death_date date9.; datalines; 1,24oct2012,0,.,0 1,24oct2013,0,.,0 1,23oct2014,0,.,0 1,26oct2015,0,.,0 1,23oct2016,0,.,1 1,28oct2017,0,.,1 2,20dec2007,1,15jun2018,0 2,17sep2008,1,15jun2018,0 2,20dec2009,1,15jun2018,0 2,16sep2010,1,15jun2018,1 2,20dec2011,1,15jun2018,1 2,22sep2012,1,15jun2018,1 ; run; From this longitudinal dataset, I want to generate the dataset to run Cox model with competing risk. More specifically, I want to create the dataset that satisfy the following: - if from the first visit to the last visit, subject does not have the event (disease=0), then time_to_event= duration from the first visit to the last visit and create variable called censor_status=0. - if from the first visit to the last visit, subject has the event in between (diease=1), then time_to_event =duration from first visit to the visit_date when even happen (aka disease from 0 to 1) and censor_status=1. - if death_date occurs before the event happens then time_to_event = duration from first visit to death date, and censor_status=2. Any insight is greatly appreciated. Thanks
... View more