Hi @Justin9 , Please see the code below : data test1 test2; set test; by acct ; if first.acct then n =1; else n+1; if type = '136' then f=1; output test1 ; if f=1 then output test2; run; data test3; merge test1(in=a) test2(in=b keep=acct n rename=(n=n_) ); by acct; if a and b and n le n_ ; drop n n_ f; run;
... View more