Hello all,
I have a somewhat complex conditional delete that I am trying to figure out, and it is based on repeated observations, and I have three different types of repeaters that need to be pruned. Essentially, I have a dataset with people who have been interviewed at 2 times.
I want to delete observations for all of these repeaters so that they only have one visit in the dataset, and I would like to do this conditionally on two variables (ACECAT, which is ACEs category, and INT_D, which is interview date). There are three types of repeaters that I need to remove one visit from. They can be identified as repeaters via the use of another variable, site_ID (though in this dataset I've actually restricted so that only repeaters are present).
The first type of repeater is missing ACECAT at BOTH visits - for these, it doesn't really matter which observation gets deleted, but for the sake of consistency I would like to delete the first observation and keep the last. INT_D is formatted in DDMMMYYYY format.
the second type of repeater has answered ACECAT at one visit and is missing ACECAT in the other visit - for these types of repeaters, I want to drop the observation where ACECAT is missing.
the third type of repeater has answered ACECAT at both visits. For these types of repeaters, I want to keep only the most recent observation and drop the last observation.
I've been trying to think of a data step (or multiple data steps if needed) that can solve this problem, but am drawing a blank. Can anyone help?
Can you provide us with some example data so that we can test out code? Thanks.
@zfusfeld wrote:
the third type of repeater has answered ACECAT at both visits. For these types of repeaters, I want to keep only the most recent observation and drop the last observation.
If your data are sorted by INT_D within each id/group, then isn't the most recent observation (to be kept) the same as the last observation (to be dropped)?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.