If you really want the first user and not the user with the lowest id then Linlin's SQL won't give you the correct result. Some code like below would do: data have; input ida $ idb $; datalines; b 1 b 1 b 2 a 2 a 2 a 1 a 1 a 1 a 3 a 3 ; run; data want(drop=_:); set have; by ida notsorted; retain _r_idb; if first.ida then _r_idb=idb; if idb=_r_idb then output; run;
... View more