|
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
*/
|