Let's see if I've got this right . . . . If REC1 = REC2 then keep the record (e.g. 3rd record in your sample input data). If REC2 is missing, then combine the record with the next sequential record (e.g. first two records of your input data become one row, with REC1, ORDERREC1 from the first row and REC2, ORDERREC2 from the second row). Assuming I understand this correctly, here's a PROC SQL approach: proc sql; create table want as /* get records that already have matches */ ( select * from temp where rec1 = rec2 ) UNION /* merge non-matches */ ( select t1.*, t2.rec2, t2.orderrec2 from temp t1 /* get the missing values from the next obs */ inner join ( select t2.* from temp t2 where t2.rec1 is missing and t2.rec2 is not missing ) r2 on r2.id = t1.id and r2.recno = t1.recno + 1 where t1.rec1 is not missing and t1.rec2 is missing ) ; quit;
... View more