The data step is not going to do this type of many-to-many merge properly (without a lot of extra programing).
Better to use SQL.
Looks like you just want to categorize the combinations.
proc sql ;
create table want as
select case when (not missing(one.id) and not missing(two.id)) then 1
when (not missing(one.id)) then 2
else 3 end as group
, coalesce(one.id,two.id) as id
, one.datex
, two.dateint1
, two.dateint2
from one full join two
on one.id=two.id and one.datex between two.dateint1 and two.dateint2
order by group,id,datex,dateint1
;
quit;
Obs group id datex dateint1 dateint2
1 1 1 2021-10-10 2021-10-03 2021-10-17
2 1 1 2022-08-15 2022-08-08 2022-08-22
3 2 1 2022-03-22 . .
4 2 2 2020-05-06 . .
5 3 1 . 2022-04-01 2022-04-14
6 3 1 . 2022-12-02 2022-12-17
... View more