Here's my third attempt to get you to try this. Trust me. It works. I modified it to use the data structure of your last post, but the concept is the same as the other 2 times I offered this solution. data A; infile cards; input accountno meter_number finaldatecombined ddmmyy10. saleid $; format finaldatecombined ddmmyy10.; cards; 80000 55393810 11/06/2011 FX111 ; run; data B; infile cards; input accountno meter_number invoice_date ddmmyy10.; format invoice_date ddmmyy10.; cards; 31000 55393810 04/10/2011 39000 55393810 24/10/2011 ; run; proc sql; create table identifyaccno as select b.accountno, a.meter_number, a.finaldatecombined, b.invoice_date, a.saleid from a left join b on a.meter_number = b.meter_number and b.invoice_date = (select min( invoice_date ) from b where b.invoice_date > a.finaldatecombined ) ; quit;
... View more