proc sql;
create table data1_data2 as
select
a.Reg_no
,a.collection_date
,b.Ud_COLLECTION_DATE
from data1 a left join data2_latest b on a.Reg_no = b.Reg_no
;
quit;
proc sort data =data1_data2 ;
by Reg_No descending collection_date descending Ud_COLLECTION_DATE;
run;
data data2_latest;
set =data1_data2 ;
by descending collection_date descending Ud_COLLECTION_DATE;
if first.Reg_No and Ud_COLLECTION_DATE > collection_date -86400 then output;
run;
proc sql;
create table data1_data3 as
select
a.Reg_no
,a.collection_date
,c.Um_COLLECTION_DATE
from data1 a left join data3_latest c on a.Reg_no = c.Reg_no
;
quit;
data data3_latest;
set =data1_data3 ;
by descending collection_date descending Um_COLLECTION_DATE
if first.Reg_No and Um_COLLECTION_DATE> collection_date -86400 then output;
run; If you are happy with data2_latest and data3_latest then merge these two dataset proc sql;
create table want as
select
a.Reg_no
,a.collection_date
,b.Ud_COLLECTION_DATE
,c.Um_COLLECTION_DATE
from data1 a left join data2_latest b on a.Reg_no = b.Reg_no
left join data3_latest c on a.Reg_no = c.Reg_no
;
quit;
... View more