ID_ X_Var1_Var2 ...
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.
Using PROC MEANS/SUMMARY, build a file with MAX(X) BY ID, then MERGE that file back onto the (sorted) original file so you can detect the "at least one" X=1 condition, then use IF / THEN logic to perform the conditional logic. As suggested before, break down your overall "task" into individual requirements, program for each, then combine into a single SAS program.
If the values of X are only 1 and 0, then why not approach it differently. If you sort you data by id and descending X, then you could use a simple data step to separate the records into two groups. e.g.:
data atleastone1 (drop=group) allzeros (drop=group);
if first.id then do;
if x eq 1 then group=1;
if group eq 1 then output atleastone1;
else output allzeros;
Then you will have two different datasets that you can sort and analyze as you describe.