And here a SQL way using the source data created by @SASJedi
The proposed data step with formats will perform better so I'd certainly be using this approach for any bigger data volumes.
The advantage of pure SQL is that it could execute in-database (with a few amendments to the current SAS SQL flavor) if both of your source tables are in a database.
proc sql;
select
h1.quarter
,h1.key
,h2.group
from have1 h1 left join have2 h2
on h1.quarter=h2.quarter
and h1.key <= h2.Cutoff
group by h1.quarter, h1.key
having h2.Cutoff-h1.key = min(h2.Cutoff-h1.key)
;
quit;
... View more