In reply to Bocheng Jing. Hi Bocheng,the problem you are facing is quite different. It seems to be rather complex combinatorial problem. In a simplified example, to check if three medications are overlapping, I would make sure that the END of each medication interval is GREATER OR EQUAL than the BEGINNINGs of the other two medications. Consider the following code:

data A;
input B1 E1 B2 E2 B3 E3 @;
informat B1--E3 mmddyy10.;
format B1--E3 mmddyy10.;
datalines;
05/02/2022 05/20/2022
05/15/2022 05/20/2022
05/14/2022 05/19/2022
05/02/2022 05/14/2022
05/15/2022 05/20/2022
05/14/2022 05/19/2022
;

data B;
set A;
FLAG = (B1<=E1>=B2 & B1<=E2>=B3 & B1<=E3>=B2);
run;