data a; input id x1 x2 @@; cards; 1 11 12 2 21 22 4 41 42 4 411 422 5 51 52 ;run; data b; input id x3 @@; cards; 1 13 3 33 4 43 5 53 5 533 5 5333 ;run; proc sort data=a; by id; run; proc sort data=b; by id; run; data aa; set a; if first.id and last.id then delete; by id; run; data bb; set b; if first.id and last.id then delete; by id; run; data cc; merge aa bb; by id; run; proc print data=cc; run;