Was not aware of you have done it yesterday ago, was still waiting on your new post. anyway, here is my suggested solution: data have; infile cards dlm='09'x truncover; input patient:$10. (Visit_date Max_date) (:ddmmyy10.) Trt_at_visit$; format visit_date Max_date ddmmyy10.; cards; Patient1 01/12/00 30/05/01 Drug_x Patient1 31/12/00 29/06/01 Drug_x Patient1 24/03/01 20/09/01 Drug_e Patient1 22/07/01 18/01/02 Drug_x Patient1 02/12/00 31/05/01 Drug_x Patient1 01/01/01 30/06/01 Drug_x Patient1 25/03/01 21/09/01 Drug_x Patient1 23/07/01 19/01/02 Drug_x Patient1 20/11/01 19/05/02 Drug_a Patient1 20/12/01 18/06/02 Drug_x Patient1 13/03/02 09/09/02 Drug_x Patient1 11/07/02 07/01/03 Drug_x Patient1 08/11/02 07/05/03 Drug_x Patient1 08/12/02 06/06/03 Drug_x Patient1 01/03/03 28/08/03 Drug_x Patient2 29/06/03 26/12/03 Drug_x Patient2 27/10/03 24/04/04 Drug_e Patient2 26/11/03 24/05/04 Drug_x Patient2 17/02/04 15/08/04 Drug_x Patient2 16/06/04 13/12/04 Drug_x Patient2 14/10/04 12/04/05 Drug_e Patient2 13/11/04 12/05/05 Drug_x Patient2 04/02/05 03/08/05 Drug_x Patient2 04/06/05 01/12/05 Drug_x Patient2 02/10/05 31/03/06 Drug_x Patient2 01/11/05 30/04/06 Drug_x Patient2 23/01/06 22/07/06 Drug_x Patient2 23/05/06 19/11/06 Drug_x ; proc sql; create table want as select *, exists(select * from have where patient=a.patient and a.visit_date <= visit_date <= a.visit_date+180 and Trt_at_visit ne a.Trt_at_visit ) as Concurrent_flag from have a ; quit; Good luck, Haikuo
... View more