post reedited and asked in other post where it was solved - post to delete
CodePudding user response:
This could definitely be done more elegantly. But this should work just fine.
data have;
input VAL1 $2. ID VAL2 $1.;
datalines;
P1 123 P
P1 123 P
P1 123 S
S2 44 C
S2 44 S
GG 44 P
P1 58 S
P1 58 S
;
run;
proc sort data=have out=sorted nodupkey;
by ID descending VAL2;
run;
data want;
set sorted;
by ID;
if VAL2 in ('P' 'C') then output;
else if last.ID then output;
run;