Remove observations after observed event

Regular Contributor
Posts: 150

Remove observations after observed event

I am conducting a discreet time survival analysis using cloglog. I have 4 visits of data and I am trying to come up with a good way to remove observations after an event happens. For example, if the person get the event at time point 2, then their data should be deleted or missing for time points 3 and 4. Otherwise, their data will remain until the end of the study or until they experience the event. Any suggestions would be greatly appreciated. The outcome is a yes no variables, for example smoking: Yes No. If they initiated smoking at visit 2 then that participants data would be removed at subsequent visits.  

Super User
Posts: 6,788

Re: Remove observations after observed event

Posted in reply to rfarmenta

Here's one idea:


data want;

set have;

by person;

if first.person then remove_the_rest='N';

retain remove_the_rest;

if remove_the_rest='Y' then delete;

if smoking='Yes' then remove_the_rest='Y';



Of course, this assumes that your observations are sorted by PERSON ... logically you may need to sort by PERSON VISIT.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation