LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) 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:   Wed, 21 Jul 2010 08:41:00 -0400
Reply-To:   Dave Brewer <david.brewer@UC.EDU>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Dave Brewer <david.brewer@UC.EDU>
Subject:   Re: How to code to calculate continuous 12 month period
Comments:   To: Chang Chung <chang_y_chung@HOTMAIL.COM>

Chang,

Thanks much for your suggestion, but I have a problem with your code when checking for 24 continuous months.

Here is the log: 270 data two; 271 n = 0; 272 do until (last.id); 273 set one; 274 by id mon; 275 last = ifn(first.id, ., lag(mon)); 276 n = ifn(mon = intnx('mon', last, 1), n+1, 1); 277 end; 278 flag = (&THRESHOLD <= n); 279 keep id flag; 280 run;

NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 2 at 276:19

My code: data one; input id mon :anydtdte.; format mon mmddyys10.; cards; 1 7/1/2008 1 8/1/2008 1 9/1/2008 1 10/1/2008 1 11/1/2008 1 12/1/2008 1 1/1/2009 1 2/1/2009 1 3/1/2009 1 4/1/2009 1 5/1/2009 1 6/1/2009 1 7/1/2009 1 8/1/2009 1 9/1/2009 1 10/1/2009 1 11/1/2009 1 12/1/2009 1 1/1/2010 1 2/1/2010 1 3/1/2010 1 4/1/2010 2 7/1/2008 2 8/1/2008 2 9/1/2008 2 10/1/2008 2 11/1/2008 2 12/1/2008 2 1/1/2009 2 2/1/2009 2 3/1/2009 2 4/1/2009 2 5/1/2009 2 6/1/2009 2 7/1/2009 2 8/1/2009 2 9/1/2009 2 10/1/2009 2 11/1/2009 2 12/1/2009 2 1/1/2010 2 2/1/2010 2 3/1/2010 2 4/1/2010 2 5/1/2010 2 6/1/2010 ; run;

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

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;

What is causing the missing values and how can it be corrected?

Thanks again for your help. Dave

On Tue, 20 Jul 2010 17:05:21 -0400, Chang Chung <chang_y_chung@HOTMAIL.COM> wrote:

>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