I am new to SAS and I am trying to remove groups if they fulfil two conditions. I currently have this data set:
ID ID_2 ID_3;
A 1 1;
A 1 1;
A 1 1;
A 2 0;
A 2 1;
B 3 0;
B 3 0;
I am grouping by ID
then by ID_2
.
I want to remove ALL entries in the by groups as long as (1) there exists duplication across all three variables - I don't just want to remove the duplicates, I would like to remove the entire group AND (2) this duplication involves value '1' in ID_3 across all rows in each by group.
In other words, the outcome I want is:
ID ID_2 ID_3;
A 2 0;
A 2 1;
B 3 0;
B 3 0;
I have spent at least 5 hours on this and I have tried various methods:
first. and last. (this does not guarantee that all observations in the by group match)
nodup (this method only removes the duplicates - I would like to remove even the first row of the group)
lag (again, the first row of the group stays which is not what I want)
I am open to using proc sql as well. Would really appreciate any input at all, thank you in advance!