I'm looking for a solution for following problem. I'm using SAS, therefore a basic SQL or Datastep approach is both welcomed. Maybe the solution is simple, but I'm kinda new to SAS and can't find a solution.
I got a dataset and want to remove a subgroup on second level by a condition. So for making it easier, let me explain on an example. The condition is: When any value in ColC is 1, then remove the subgroup in the maingroup. The main group is ColA and the subgroup is ColB
ColA | ColB | ColC
1 | a | 0
1 | a | 1
1 | b | 0
1 | b | 0
2 | a | 0
2 | a | 0
2 | b | 0
2 | b | 0
3 | a | 0
3 | a | 0
3 | b | 1
3 | b | 0
Expected output:
ColA | ColB | ColC
1 | b | 0
1 | b | 0
2 | a | 0
2 | a | 0
2 | b | 0
2 | b | 0
3 | a | 0
3 | a | 0
I tried approaches like:
select * from data
group by ColA, ColB having ColC <> 1
Which I thought, will group by the two columns and select all groups without ColC= 1. But it "removes" only the rows with ColC=1.
Another approach is something like this:
select * from data
where ColA in (select ColA from data where ColC <> 1)
But of course, I can't reach the subgroups with this. I also was thinking about a join, but not sure how to do it.