@lichee I'm still struggling to understand your selection logic. Like: If WITHIN 30 days means Before and After.
Given that record selection and collapsing records are two different problems and that record selection needs resolution first, I suggest that you provide us with a HAVE data set that marks all the records that you want selected.
I also suggest that you use date format in the data and your explanations that's international. MDY formats are really hard to read for most non-US people.
Below the sample data structure I'd suggest. You will need to amend the data for the last column select_desired_flg
data have;
infile datalines truncover dsd;
input Person_ID $ Begin_Date :date9. End_Date :date9. Eligible select_desired_flg;
format Begin_Date End_Date date9.;
datalines;
111111,13MAR2018,15MAR2018,0,0
111111,24APR2018,26APR2018,0,0
111111,13JUL2018,14JUL2018,0,0
111111,14JUL2018,19JUL2018,1,1
111111,26JUL2018,30JUL2018,1,1
111111,17NOV2018,26NOV2018,1,1
222222,01MAY2018,04MAY2018,0,0
222222,17MAY2018,19MAY2018,1,1
333333,08MAR2018,09MAR2018,0,0
333333,17APR2018,26APR2018,0,0
333333,16JUN2018,20JUN2018,0,0
333333,03JUL2018,04JUL2018,0,0
333333,23JUL2018,24JUL2018,0,0
333333,09AUG2018,10AUG2018,0,0
333333,08SEP2018,11SEP2018,1,0
333333,11SEP2018,14SEP2018,1,0
333333,23SEP2018,26SEP2018,0,0
444444,05JUL2018,07JUL2018,0,0
444444,21DEC2018,28DEC2018,1,1
555555,28APR2018,03MAY2018,1,1
555555,06MAY2018,10MAY2018,1,0
555555,26NOV2018,29NOV2018,1,1
666666,14JAN2018,24JAN2018,1,0
666666,29JAN2018,31JAN2018,1,0
666666,04FEB2018,05FEB2018,1,0
666666,07FEB2018,12FEB2018,1,0
666666,18AUG2018,23AUG2018,1,0
666666,24AUG2018,25AUG2018,1,0
666666,28AUG2018,03SEP2018,1,0
666666,06SEP2018,11SEP2018,1,0
666666,13SEP2018,16SEP2018,1,0
666666,22SEP2018,23SEP2018,0,0
666666,03OCT2018,16OCT2018,1,0
666666,04NOV2018,05NOV2018,1,0
666666,05NOV2018,12NOV2018,1,0
666666,25DEC2018,28DEC2018,1,0
666666,30DEC2018,31DEC2018,0,0
;
run;
I also suggest that you provide us with a re-formulated set of your selection logic. Given the answers you've got so far I assume that I'm not the only one struggling with your narrative.
... View more