@Quentin Thank you. I was having some formatting issues when copying and pasting code for some reason... Here is a recent example that resulted in increasing the number of observations in set 2.
proc sql;
create table best_matches as
select
s2.id,
s2.eventstart,
s1.physcat,
s1.a,
s1.b,
s1.c,
s1.d,
s1.e,
s1.d_end
from set2 as s2
inner join set1 as s1
on s1.id = s2.id
and s2.eventstart between s1.d_start and s1.d_end
group by s2.id, s2.eventstart
having s1.d_end = min(s1.d_end)
;
create table merged as
select
s2.*,
bm.physcat,
bm.a, bm.b, bm.c, bm.d, bm.e
from set2 as s2
left join best_matches as bm
on s2.id = bm.id
and s2.eventstart = bm.eventstart
;
quit;
... View more