Dear all, I want to calculate the regular use of drug. The defination is that regular users was the regular use of drug for "more than a year" and "the interval between successive prescription drug records cannot exceed 120 days". I wish the the data was presented as "Category (Correct)". When the date between two prescriptions were within 120 days (Dif_Days), they belonged the same group. If the date long than 120 days (Dif_Days), the next prescriptions was categorized as new group. At one of steps, I cannot run the the correct category. How cou;d I modify the syntax? DATA Final; SET data; by ID Drug_start if first.ID then Category=1; if Dif_Days<=120 then Category=1; else Category+1; run; The data was shown as below. Drug_start: the first date for this prescription Drug_end: the end date for this prescription Drug_day: how long for this prescription Dif_Days: the difference between the Drug_start and last Drug_end ID Drug_start Drug_end Drug_day Dif_Days Category Category (Correct) AAA 20091011 20091109 30 1 1 AAA 20091109 20091208 30 0 1 1 AAA 20110317 20110415 30 464 2 2 AAA 20110523 20110621 30 38 1 2 AAA 20110810 20110908 30 50 1 2 AAA 20110909 20111008 30 1 1 2 AAA 20111005 20111103 30 -3 1 2 AAA 20130217 20130318 30 472 2 3 AAA 20130313 20130411 30 -5 1 3 BBB 1 1 BBB 1 1 CCC 20080605 20080618 14 1 1 CCC 20100311 20100317 7 631 2 2 CCC 20100318 20100331 14 1 1 2 CCC 20110616 20110713 28 442 2 3 CCC 20111124 20111221 28 134 3 4 CCC 20121115 20121212 28 330 4 5 CCC 20121207 20130103 28 -5 1 5 CCC 20130110 20130206 28 7 1 5 CCC 20130418 20130515 28 71 1 5 CCC 20130530 20130626 28 15 1 5 CCC 20130706 20130802 28 10 1 5 CCC 20130727 20130823 28 -6 1 5
... View more