I have a code gives me last services Proc sql; Create table temp as select A.id, A.seq, A.day, B.date1 as date2, Abs(a day-b.date1) as diff From paper as a Left join dep1 as b On a.id=b.id Group by a.id Order by id seq, diff Proc sql; Create table want As select id,day,date2, seq From temp Group by id , seq Having min(diff) ;quit; Data want; Set temp; By id seq If first.seq; Run; It works 80%of time Id. Seq. Day. Date2. Diff A1. 9401. 05/18/2018. 05/25/2018. 7 What i expect was Id. Seq. Day. Date2. Diff A1. 9401. 05/18/2018. 04/27/2018. 21 What im looking for last day there was a service from 5/18/2018. Whichj is 04/27/2018
... View more