Hi Here are the steps: 1. Sort the data by id and yyyymm proc sort data = play; by id yyyymm; run; 2. Extract the rows containing 'A' in either class1 or class2 data playClassA; set play; if substr(class1,1,1)='A' | substr(class2,1,1)='A'; run; 3. Get the first record data dsOut1; set playClassA; by id; if first.id then output; run; 4. Extract the ids containing no 'A' in either class1 or class2 data playClassABar; merge play dsOut1 (in=a keep=id); by id; run; 5. Get the last record data dsOut2; set playClassA; by id; if last.id then output; run; 6. Combine the results data dsOut; set dsOut1 dsOut2; run; Hope this will help.
... View more