ID_ X_Var1_Var2 ...
1 _0
1_1
2_0
2_0
2_0
.
.
For each ID, one and only one record should be kept. When there is at least one record with X=1 one selection rule applies. When X=0 in every record another selection rule applies. (The different selection rules use the other variables; Var1, Var2, ..., in different ways.)
There could be situations when the data set contains only one type of records, so I can't split the the data into two sets and use the different rules for each set, and then join them.
The program should be general.
Any idea on how to solve this, would be much appreciated.