OK - misread the requirement. Struggling to understand the context ( you want treatments that span at least 2 months but the treatment cycle must cross the (arbitrary) 3 month boundaries??) Well, if you insist /* create indicator for 6 monthly periods */ Data periods ; Set have ; By Id Dates_of_Visit ; Period = intck(‘semiyear.3’, ‘01mar2011’d, dates_of_visit) + 1 ; Run ; /* Screen for inter-period durations */ /* init is the first visit in the current period, start is the first visit in the previous period */ Data screen ; Set Periods ; Retain init start ; By Id Period Dates_of_Visit ; If first.Period then init = Dates_of_Visit ; If last.Period then do ; duration = Dates_of_Visit - start ; /* Values should be missing for the first period */ if duration >= 60 then output ; start = init ; /* Set start ready for the next period */ end ; Run ; /* Select qualifying Ids */ Proc SQL ; Create table want as Select Id From Screen Having (Count(*) = 3) Group By Id ; Quit ; [NB untested] Richard
... View more