LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 20 Jul 2010 17:05:21 -0400
Reply-To:   Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject:   Re: How to code to calculate continuous 12 month period
Comments:   To: Dave Brewer <david.brewer@UC.EDU>

On Tue, 20 Jul 2010 16:49:16 -0400, Dave Brewer <david.brewer@UC.EDU> wrote: ... >I have been trying to come up with code to calculate if a patient has been >enrolled in Medicaid for 12 continuous months, but to no avail. ... >I would like the code to be dynamic; in other words, I might need to check >for 24 continuous months the next time. ... Hi, Dave, Here is one way. hth. Cheers, Chang

/* test data */ data one; input id mon :anydtdte.; format mon mmddyys10.; cards; 1 01/01/2009 1 02/01/2009 1 03/01/2009 1 06/01/2009 1 07/01/2009 1 08/01/2009 1 09/01/2009 1 10/01/2009 1 11/01/2009 1 12/01/2009 1 04/01/2010 2 05/01/2009 2 08/01/2009 2 09/01/2009 2 10/01/2009 2 11/01/2009 2 12/01/2009 2 01/01/2010 2 02/01/2010 2 03/01/2010 2 04/01/2010 2 05/01/2010 2 06/01/2010 2 07/01/2010 ; run;

/* flag if at least 12 continous months */ %let THRESHOLD = 12;

proc sort data=one; by id mon; run;

data two; n = 0; do until (last.id); set one; by id mon; last = ifn(first.id, ., lag(mon)); n = ifn(mon = intnx('mon', last, 1), n+1, 1); end; flag = (&THRESHOLD <= n); keep id flag; run;

/* check */ proc print data=two noobs; run; /* on lst id flag 1 0 2 1 */


Back to: Top of message | Previous page | Main SAS-L page