Enrollment in Pharmetrics
The following SAS code will build non-overlapping enrollment periods (start and end dates) from the ESTRING field in the Pharmetrics database using a 1-month buffer period:
*———————————————————;
* ENROLLMENT_PHARMETRICS.sas;
*———————————————————;
libname h ‘H:\’;
*———————————————————;
* Create MONTH periods from the ESTRING variable;
/*
proc sql; select count(distinct PAT_ID) from h.PATLEVEL; quit;
* 456,804 pts;
proc sql; select max(length(ESTRING)) from h.PATLEVEL; quit;
* 252 (21 years of data);
*/
data h.ENROLLMENT_MONTH;
set h.PATLEVEL (keep = PAT_ID ESTRING);
* 1995;
if substr(ESTRING,1,1) = ‘X’ then do;
MO_START = ‘01JAN1995′d;
MO_END = ‘31JAN1995′d; output;
end;
if substr(ESTRING,2,1) = ‘X’ then do;
MO_START = ‘01FEB1995′d;
MO_END = ‘28FEB1995′d; output;
end;
if substr(ESTRING,3,1) = ‘X’ then do;
MO_START = ‘01MAR1995′d;
MO_END = ‘31MAR1995′d; output;
end;
if substr(ESTRING,4,1) = ‘X’ then do;
MO_START = ‘01APR1995′d;
MO_END = ‘30APR1995′d; output; end;
if substr(ESTRING,5,1) = ‘X’ then do;
MO_START = ‘01MAY1995′d;
MO_END = ‘31MAY1995′d; output;
end;
if substr(ESTRING,6,1) = ‘X’ then do;
MO_START = ‘01JUN1995′d;
MO_END = ‘30JUN1995′d; output;
end;
if substr(ESTRING,7,1) = ‘X’ then do;
MO_START = ‘01JUL1995′d;
MO_END = ‘31JUL1995′d; output;
end;
if substr(ESTRING,8,1) = ‘X’ then do;
MO_START = ‘01AUG1995′d;
MO_END = ‘31AUG1995′d; output;
end;
if substr(ESTRING,9,1) = ‘X’ then do;
MO_START = ‘01SEP1995′d;
MO_END = ‘30SEP1995′d; output;
end;
if substr(ESTRING,10,1) = ‘X’ then do;
MO_START = ‘01OCT1995′d;
MO_END = ‘31OCT1995′d; output;
end;
if substr(ESTRING,11,1) = ‘X’ then do;
MO_START = ‘01NOV1995′d;
MO_END = ‘30NOV1995′d; output;
end;
if substr(ESTRING,12,1) = ‘X’ then do;
MO_START = ‘01DEC1995′d;
MO_END = ‘31DEC1995′d; output;
end;
* 1996;
if substr(ESTRING,13,1) = ‘X’ then do;
MO_START = ‘01JAN1996′d;
MO_END = ‘31JAN1996′d; output;
end;
if substr(ESTRING,14,1) = ‘X’ then do;
MO_START = ‘01FEB1996′d;
MO_END = ‘29FEB1996′d; output;
end;
if substr(ESTRING,15,1) = ‘X’ then do;
MO_START = ‘01MAR1996′d;
MO_END = ‘31MAR1996′d; output;
end;
if substr(ESTRING,16,1) = ‘X’ then do;
MO_START = ‘01APR1996′d;
MO_END = ‘30APR1996′d; output;
end;
if substr(ESTRING,17,1) = ‘X’ then do;
MO_START = ‘01MAY1996′d;
MO_END = ‘31MAY1996′d; output;
end;
if substr(ESTRING,18,1) = ‘X’ then do;
MO_START = ‘01JUN1996′d;
MO_END = ‘30JUN1996′d; output;
end;
if substr(ESTRING,19,1) = ‘X’ then do;
MO_START = ‘01JUL1996′d;
MO_END = ‘31JUL1996′d; output;
end;
if substr(ESTRING,20,1) = ‘X’ then do;
MO_START = ‘01AUG1996′d;
MO_END = ‘31AUG1996′d; output;
end;
if substr(ESTRING,21,1) = ‘X’ then do;
MO_START = ‘01SEP1996′d;
MO_END = ‘30SEP1996′d; output;
end;
if substr(ESTRING,22,1) = ‘X’ then do;
MO_START = ‘01OCT1996′d;
MO_END = ‘31OCT1996′d; output;
end;
if substr(ESTRING,23,1) = ‘X’ then do;
MO_START = ‘01NOV1996′d;
MO_END = ‘30NOV1996′d; output;
end;
if substr(ESTRING,24,1) = ‘X’ then do;
MO_START = ‘01DEC1996′d;
MO_END = ‘31DEC1996′d; output;
end;
* 1997;
if substr(ESTRING,25,1) = ‘X’ then do;
MO_START = ‘01JAN1997′d;
MO_END = ‘31JAN1997′d; output;
end;
if substr(ESTRING,26,1) = ‘X’ then do;
MO_START = ‘01FEB1997′d;
MO_END = ‘28FEB1997′d; output;
end;
if substr(ESTRING,27,1) = ‘X’ then do;
MO_START = ‘01MAR1997′d;
MO_END = ‘31MAR1997′d; output;
end;
if substr(ESTRING,28,1) = ‘X’ then do;
MO_START = ‘01APR1997′d;
MO_END = ‘30APR1997′d; output;
end;
if substr(ESTRING,29,1) = ‘X’ then do; MO_START = ‘01MAY1997′d; MO_END = ‘31MAY1997′d; output; end;
if substr(ESTRING,30,1) = ‘X’ then do; MO_START = ‘01JUN1997′d; MO_END = ‘30JUN1997′d; output; end;
if substr(ESTRING,31,1) = ‘X’ then do; MO_START = ‘01JUL1997′d; MO_END = ‘31JUL1997′d; output; end;
if substr(ESTRING,32,1) = ‘X’ then do; MO_START = ‘01AUG1997′d; MO_END = ‘31AUG1997′d; output; end;
if substr(ESTRING,33,1) = ‘X’ then do; MO_START = ‘01SEP1997′d; MO_END = ‘30SEP1997′d; output; end;
if substr(ESTRING,34,1) = ‘X’ then do; MO_START = ‘01OCT1997′d; MO_END = ‘31OCT1997′d; output; end;
if substr(ESTRING,35,1) = ‘X’ then do; MO_START = ‘01NOV1997′d; MO_END = ‘30NOV1997′d; output; end;
if substr(ESTRING,36,1) = ‘X’ then do; MO_START = ‘01DEC1997′d; MO_END = ‘31DEC1997′d; output; end;
* 1998;
if substr(ESTRING,37,1) = ‘X’ then do; MO_START = ‘01JAN1998′d; MO_END = ‘31JAN1998′d; output; end;
if substr(ESTRING,38,1) = ‘X’ then do; MO_START = ‘01FEB1998′d; MO_END = ‘28FEB1998′d; output; end;
if substr(ESTRING,39,1) = ‘X’ then do; MO_START = ‘01MAR1998′d; MO_END = ‘31MAR1998′d; output; end;
if substr(ESTRING,40,1) = ‘X’ then do; MO_START = ‘01APR1998′d; MO_END = ‘30APR1998′d; output; end;
if substr(ESTRING,41,1) = ‘X’ then do; MO_START = ‘01MAY1998′d; MO_END = ‘31MAY1998′d; output; end;
if substr(ESTRING,42,1) = ‘X’ then do; MO_START = ‘01JUN1998′d; MO_END = ‘30JUN1998′d; output; end;
if substr(ESTRING,43,1) = ‘X’ then do; MO_START = ‘01JUL1998′d; MO_END = ‘31JUL1998′d; output; end;
if substr(ESTRING,44,1) = ‘X’ then do; MO_START = ‘01AUG1998′d; MO_END = ‘31AUG1998′d; output; end;
if substr(ESTRING,45,1) = ‘X’ then do; MO_START = ‘01SEP1998′d; MO_END = ‘30SEP1998′d; output; end;
if substr(ESTRING,46,1) = ‘X’ then do; MO_START = ‘01OCT1998′d; MO_END = ‘31OCT1998′d; output; end;
if substr(ESTRING,47,1) = ‘X’ then do; MO_START = ‘01NOV1998′d; MO_END = ‘30NOV1998′d; output; end;
if substr(ESTRING,48,1) = ‘X’ then do; MO_START = ‘01DEC1998′d; MO_END = ‘31DEC1998′d; output; end;
* 1999;
if substr(ESTRING,49,1) = ‘X’ then do; MO_START = ‘01JAN1999′d; MO_END = ‘31JAN1999′d; output; end;
if substr(ESTRING,50,1) = ‘X’ then do; MO_START = ‘01FEB1999′d; MO_END = ‘28FEB1999′d; output; end;
if substr(ESTRING,51,1) = ‘X’ then do; MO_START = ‘01MAR1999′d; MO_END = ‘31MAR1999′d; output; end;
if substr(ESTRING,52,1) = ‘X’ then do; MO_START = ‘01APR1999′d; MO_END = ‘30APR1999′d; output; end;
if substr(ESTRING,53,1) = ‘X’ then do; MO_START = ‘01MAY1999′d; MO_END = ‘31MAY1999′d; output; end;
if substr(ESTRING,54,1) = ‘X’ then do; MO_START = ‘01JUN1999′d; MO_END = ‘30JUN1999′d; output; end;
if substr(ESTRING,55,1) = ‘X’ then do; MO_START = ‘01JUL1999′d; MO_END = ‘31JUL1999′d; output; end;
if substr(ESTRING,56,1) = ‘X’ then do; MO_START = ‘01AUG1999′d; MO_END = ‘31AUG1999′d; output; end;
if substr(ESTRING,57,1) = ‘X’ then do; MO_START = ‘01SEP1999′d; MO_END = ‘30SEP1999′d; output; end;
if substr(ESTRING,58,1) = ‘X’ then do; MO_START = ‘01OCT1999′d; MO_END = ‘31OCT1999′d; output; end;
if substr(ESTRING,59,1) = ‘X’ then do; MO_START = ‘01NOV1999′d; MO_END = ‘30NOV1999′d; output; end;
if substr(ESTRING,60,1) = ‘X’ then do; MO_START = ‘01DEC1999′d; MO_END = ‘31DEC1999′d; output; end;
* 2000;
if substr(ESTRING,61,1) = ‘X’ then do; MO_START = ‘01JAN2000′d; MO_END = ‘31JAN2000′d; output; end;
if substr(ESTRING,62,1) = ‘X’ then do; MO_START = ‘01FEB2000′d; MO_END = ‘29FEB2000′d; output; end;
if substr(ESTRING,63,1) = ‘X’ then do; MO_START = ‘01MAR2000′d; MO_END = ‘31MAR2000′d; output; end;
if substr(ESTRING,64,1) = ‘X’ then do; MO_START = ‘01APR2000′d; MO_END = ‘30APR2000′d; output; end;
if substr(ESTRING,65,1) = ‘X’ then do; MO_START = ‘01MAY2000′d; MO_END = ‘31MAY2000′d; output; end;
if substr(ESTRING,66,1) = ‘X’ then do; MO_START = ‘01JUN2000′d; MO_END = ‘30JUN2000′d; output; end;
if substr(ESTRING,67,1) = ‘X’ then do; MO_START = ‘01JUL2000′d; MO_END = ‘31JUL2000′d; output; end;
if substr(ESTRING,68,1) = ‘X’ then do; MO_START = ‘01AUG2000′d; MO_END = ‘31AUG2000′d; output; end;
if substr(ESTRING,69,1) = ‘X’ then do; MO_START = ‘01SEP2000′d; MO_END = ‘30SEP2000′d; output; end;
if substr(ESTRING,70,1) = ‘X’ then do; MO_START = ‘01OCT2000′d; MO_END = ‘31OCT2000′d; output; end;
if substr(ESTRING,71,1) = ‘X’ then do; MO_START = ‘01NOV2000′d; MO_END = ‘30NOV2000′d; output; end;
if substr(ESTRING,72,1) = ‘X’ then do; MO_START = ‘01DEC2000′d; MO_END = ‘31DEC2000′d; output; end;
* 2001;
if substr(ESTRING,73,1) = ‘X’ then do; MO_START = ‘01JAN2001′d; MO_END = ‘31JAN2001′d; output; end;
if substr(ESTRING,74,1) = ‘X’ then do; MO_START = ‘01FEB2001′d; MO_END = ‘28FEB2001′d; output; end;
if substr(ESTRING,75,1) = ‘X’ then do; MO_START = ‘01MAR2001′d; MO_END = ‘31MAR2001′d; output; end;
if substr(ESTRING,76,1) = ‘X’ then do; MO_START = ‘01APR2001′d; MO_END = ‘30APR2001′d; output; end;
if substr(ESTRING,77,1) = ‘X’ then do; MO_START = ‘01MAY2001′d; MO_END = ‘31MAY2001′d; output; end;
if substr(ESTRING,78,1) = ‘X’ then do; MO_START = ‘01JUN2001′d; MO_END = ‘30JUN2001′d; output; end;
if substr(ESTRING,79,1) = ‘X’ then do; MO_START = ‘01JUL2001′d; MO_END = ‘31JUL2001′d; output; end;
if substr(ESTRING,80,1) = ‘X’ then do; MO_START = ‘01AUG2001′d; MO_END = ‘31AUG2001′d; output; end;
if substr(ESTRING,81,1) = ‘X’ then do; MO_START = ‘01SEP2001′d; MO_END = ‘30SEP2001′d; output; end;
if substr(ESTRING,82,1) = ‘X’ then do; MO_START = ‘01OCT2001′d; MO_END = ‘31OCT2001′d; output; end;
if substr(ESTRING,83,1) = ‘X’ then do; MO_START = ‘01NOV2001′d; MO_END = ‘30NOV2001′d; output; end;
if substr(ESTRING,84,1) = ‘X’ then do; MO_START = ‘01DEC2001′d; MO_END = ‘31DEC2001′d; output; end;
* 2002;
if substr(ESTRING,85,1) = ‘X’ then do; MO_START = ‘01JAN2002′d; MO_END = ‘31JAN2002′d; output; end;
if substr(ESTRING,86,1) = ‘X’ then do; MO_START = ‘01FEB2002′d; MO_END = ‘28FEB2002′d; output; end;
if substr(ESTRING,87,1) = ‘X’ then do; MO_START = ‘01MAR2002′d; MO_END = ‘31MAR2002′d; output; end;
if substr(ESTRING,88,1) = ‘X’ then do; MO_START = ‘01APR2002′d; MO_END = ‘30APR2002′d; output; end;
if substr(ESTRING,89,1) = ‘X’ then do; MO_START = ‘01MAY2002′d; MO_END = ‘31MAY2002′d; output; end;
if substr(ESTRING,90,1) = ‘X’ then do; MO_START = ‘01JUN2002′d; MO_END = ‘30JUN2002′d; output; end;
if substr(ESTRING,91,1) = ‘X’ then do; MO_START = ‘01JUL2002′d; MO_END = ‘31JUL2002′d; output; end;
if substr(ESTRING,92,1) = ‘X’ then do; MO_START = ‘01AUG2002′d; MO_END = ‘31AUG2002′d; output; end;
if substr(ESTRING,93,1) = ‘X’ then do; MO_START = ‘01SEP2002′d; MO_END = ‘30SEP2002′d; output; end;
if substr(ESTRING,94,1) = ‘X’ then do; MO_START = ‘01OCT2002′d; MO_END = ‘31OCT2002′d; output; end;
if substr(ESTRING,95,1) = ‘X’ then do; MO_START = ‘01NOV2002′d; MO_END = ‘30NOV2002′d; output; end;
if substr(ESTRING,96,1) = ‘X’ then do; MO_START = ‘01DEC2002′d; MO_END = ‘31DEC2002′d; output; end;
* 2003;
if substr(ESTRING,97,1) = ‘X’ then do; MO_START = ‘01JAN2003′d; MO_END = ‘31JAN2003′d; output; end;
if substr(ESTRING,98,1) = ‘X’ then do; MO_START = ‘01FEB2003′d; MO_END = ‘28FEB2003′d; output; end;
if substr(ESTRING,99,1) = ‘X’ then do; MO_START = ‘01MAR2003′d; MO_END = ‘31MAR2003′d; output; end;
if substr(ESTRING,100,1) = ‘X’ then do; MO_START = ‘01APR2003′d; MO_END = ‘30APR2003′d; output; end;
if substr(ESTRING,101,1) = ‘X’ then do; MO_START = ‘01MAY2003′d; MO_END = ‘31MAY2003′d; output; end;
if substr(ESTRING,102,1) = ‘X’ then do; MO_START = ‘01JUN2003′d; MO_END = ‘30JUN2003′d; output; end;
if substr(ESTRING,103,1) = ‘X’ then do; MO_START = ‘01JUL2003′d; MO_END = ‘31JUL2003′d; output; end;
if substr(ESTRING,104,1) = ‘X’ then do; MO_START = ‘01AUG2003′d; MO_END = ‘31AUG2003′d; output; end;
if substr(ESTRING,105,1) = ‘X’ then do; MO_START = ‘01SEP2003′d; MO_END = ‘30SEP2003′d; output; end;
if substr(ESTRING,106,1) = ‘X’ then do; MO_START = ‘01OCT2003′d; MO_END = ‘31OCT2003′d; output; end;
if substr(ESTRING,107,1) = ‘X’ then do; MO_START = ‘01NOV2003′d; MO_END = ‘30NOV2003′d; output; end;
if substr(ESTRING,108,1) = ‘X’ then do; MO_START = ‘01DEC2003′d; MO_END = ‘31DEC2003′d; output; end;
* 2004;
if substr(ESTRING,109,1) = ‘X’ then do; MO_START = ‘01JAN2004′d; MO_END = ‘31JAN2004′d; output; end;
if substr(ESTRING,110,1) = ‘X’ then do; MO_START = ‘01FEB2004′d; MO_END = ‘29FEB2004′d; output; end;
if substr(ESTRING,111,1) = ‘X’ then do; MO_START = ‘01MAR2004′d; MO_END = ‘31MAR2004′d; output; end;
if substr(ESTRING,112,1) = ‘X’ then do; MO_START = ‘01APR2004′d; MO_END = ‘30APR2004′d; output; end;
if substr(ESTRING,113,1) = ‘X’ then do; MO_START = ‘01MAY2004′d; MO_END = ‘31MAY2004′d; output; end;
if substr(ESTRING,114,1) = ‘X’ then do; MO_START = ‘01JUN2004′d; MO_END = ‘30JUN2004′d; output; end;
if substr(ESTRING,115,1) = ‘X’ then do; MO_START = ‘01JUL2004′d; MO_END = ‘31JUL2004′d; output; end;
if substr(ESTRING,116,1) = ‘X’ then do; MO_START = ‘01AUG2004′d; MO_END = ‘31AUG2004′d; output; end;
if substr(ESTRING,117,1) = ‘X’ then do; MO_START = ‘01SEP2004′d; MO_END = ‘30SEP2004′d; output; end;
if substr(ESTRING,118,1) = ‘X’ then do; MO_START = ‘01OCT2004′d; MO_END = ‘31OCT2004′d; output; end;
if substr(ESTRING,119,1) = ‘X’ then do; MO_START = ‘01NOV2004′d; MO_END = ‘30NOV2004′d; output; end;
if substr(ESTRING,120,1) = ‘X’ then do; MO_START = ‘01DEC2004′d; MO_END = ‘31DEC2004′d; output; end;
* 2005;
if substr(ESTRING,121,1) = ‘X’ then do; MO_START = ‘01JAN2005′d; MO_END = ‘31JAN2005′d; output; end;
if substr(ESTRING,122,1) = ‘X’ then do; MO_START = ‘01FEB2005′d; MO_END = ‘28FEB2005′d; output; end;
if substr(ESTRING,123,1) = ‘X’ then do; MO_START = ‘01MAR2005′d; MO_END = ‘31MAR2005′d; output; end;
if substr(ESTRING,124,1) = ‘X’ then do; MO_START = ‘01APR2005′d; MO_END = ‘30APR2005′d; output; end;
if substr(ESTRING,125,1) = ‘X’ then do; MO_START = ‘01MAY2005′d; MO_END = ‘31MAY2005′d; output; end;
if substr(ESTRING,126,1) = ‘X’ then do; MO_START = ‘01JUN2005′d; MO_END = ‘30JUN2005′d; output; end;
if substr(ESTRING,127,1) = ‘X’ then do; MO_START = ‘01JUL2005′d; MO_END = ‘31JUL2005′d; output; end;
if substr(ESTRING,128,1) = ‘X’ then do; MO_START = ‘01AUG2005′d; MO_END = ‘31AUG2005′d; output; end;
if substr(ESTRING,129,1) = ‘X’ then do; MO_START = ‘01SEP2005′d; MO_END = ‘30SEP2005′d; output; end;
if substr(ESTRING,130,1) = ‘X’ then do; MO_START = ‘01OCT2005′d; MO_END = ‘31OCT2005′d; output; end;
if substr(ESTRING,131,1) = ‘X’ then do; MO_START = ‘01NOV2005′d; MO_END = ‘30NOV2005′d; output; end;
if substr(ESTRING,132,1) = ‘X’ then do; MO_START = ‘01DEC2005′d; MO_END = ‘31DEC2005′d; output; end;
* 2006;
if substr(ESTRING,133,1) = ‘X’ then do; MO_START = ‘01JAN2006′d; MO_END = ‘31JAN2006′d; output; end;
if substr(ESTRING,134,1) = ‘X’ then do; MO_START = ‘01FEB2006′d; MO_END = ‘28FEB2006′d; output; end;
if substr(ESTRING,135,1) = ‘X’ then do; MO_START = ‘01MAR2006′d; MO_END = ‘31MAR2006′d; output; end;
if substr(ESTRING,136,1) = ‘X’ then do; MO_START = ‘01APR2006′d; MO_END = ‘30APR2006′d; output; end;
if substr(ESTRING,137,1) = ‘X’ then do; MO_START = ‘01MAY2006′d; MO_END = ‘31MAY2006′d; output; end;
if substr(ESTRING,138,1) = ‘X’ then do; MO_START = ‘01JUN2006′d; MO_END = ‘30JUN2006′d; output; end;
if substr(ESTRING,139,1) = ‘X’ then do; MO_START = ‘01JUL2006′d; MO_END = ‘31JUL2006′d; output; end;
if substr(ESTRING,140,1) = ‘X’ then do; MO_START = ‘01AUG2006′d; MO_END = ‘31AUG2006′d; output; end;
if substr(ESTRING,141,1) = ‘X’ then do; MO_START = ‘01SEP2006′d; MO_END = ‘30SEP2006′d; output; end;
if substr(ESTRING,142,1) = ‘X’ then do; MO_START = ‘01OCT2006′d; MO_END = ‘31OCT2006′d; output; end;
if substr(ESTRING,143,1) = ‘X’ then do; MO_START = ‘01NOV2006′d; MO_END = ‘30NOV2006′d; output; end;
if substr(ESTRING,144,1) = ‘X’ then do; MO_START = ‘01DEC2006′d; MO_END = ‘31DEC2006′d; output; end;
* 2007;
if substr(ESTRING,145,1) = ‘X’ then do; MO_START = ‘01JAN2007′d; MO_END = ‘31JAN2007′d; output; end;
if substr(ESTRING,146,1) = ‘X’ then do; MO_START = ‘01FEB2007′d; MO_END = ‘28FEB2007′d; output; end;
if substr(ESTRING,147,1) = ‘X’ then do; MO_START = ‘01MAR2007′d; MO_END = ‘31MAR2007′d; output; end;
if substr(ESTRING,148,1) = ‘X’ then do; MO_START = ‘01APR2007′d; MO_END = ‘30APR2007′d; output; end;
if substr(ESTRING,149,1) = ‘X’ then do; MO_START = ‘01MAY2007′d; MO_END = ‘31MAY2007′d; output; end;
if substr(ESTRING,150,1) = ‘X’ then do; MO_START = ‘01JUN2007′d; MO_END = ‘30JUN2007′d; output; end;
if substr(ESTRING,151,1) = ‘X’ then do; MO_START = ‘01JUL2007′d; MO_END = ‘31JUL2007′d; output; end;
if substr(ESTRING,152,1) = ‘X’ then do; MO_START = ‘01AUG2007′d; MO_END = ‘31AUG2007′d; output; end;
if substr(ESTRING,153,1) = ‘X’ then do; MO_START = ‘01SEP2007′d; MO_END = ‘30SEP2007′d; output; end;
if substr(ESTRING,154,1) = ‘X’ then do; MO_START = ‘01OCT2007′d; MO_END = ‘31OCT2007′d; output; end;
if substr(ESTRING,155,1) = ‘X’ then do; MO_START = ‘01NOV2007′d; MO_END = ‘30NOV2007′d; output; end;
if substr(ESTRING,156,1) = ‘X’ then do; MO_START = ‘01DEC2007′d; MO_END = ‘31DEC2007′d; output; end;
format MO_START MO_END mmddyy10.;
keep PAT_ID MO_START MO_END;
run;
* 20,767,686;
*———————————————————;
*———————————————————;
* CREATE ENROLLMENT PERIODS FROM THE “MONTH” VARIABLES;
proc sort data = h.ENROLLMENT_MONTH;
by PAT_ID MO_START;
run;
data h.ENROLLMENT_PERIODS;
set h.ENROLLMENT_MONTH;
by PAT_ID MO_START;
retain STARTDT ENDDT RECCOUNT;
if first.PAT_ID then do;
STARTDT = MO_START;
ENDDT = MO_END;
RECCOUNT = 0;
end;
if MO_START <= ENDDT + 32 or MO_START = STARTDT then do;
ENDDT = MO_END;
RECCOUNT = RECCOUNT + 1;
end;
if MO_START > ENDDT + 32 then do;
output;
STARTDT = MO_START;
ENDDT = MO_END;
RECCOUNT = 1;
end;
if last.PAT_ID then do;
output;
end;
format STARTDT ENDDT mmddyy10.;
keep PAT_ID STARTDT ENDDT RECCOUNT;
run;
* 495,716;
/*
proc sql; select sum(RECCOUNT), count(distinct PAT_ID) from h.ENROLLMENT_PERIODS; quit;
* 20,767,686 / 455,655;
proc sql;
create table TEMP as
select PAT_ID, count(*) as nrecs
from h.ENROLLMENT_PERIODS group by PAT_ID;
quit;
* 455,655;
*/
*———————————————————;
*———————————————————;
* Adjust the enrollment periods for Pharmetrics dates;
proc sql;
create table h.ENROLLMENT_PERIODS as
select a.*, b.MXCE_FST, b.MXCE_LST
from h.ENROLLMENT_PERIODS as a left join h.PATLEVEL as b
on (a.PAT_ID = b.PAT_ID);
* 495,716;
quit;
data h.ENROLLMENT_PERIODS;
set h.ENROLLMENT_PERIODS;
if MXCE_FST > STARTDT and MXCE_FST < ENDDT then STARTDT = MXCE_FST;
if MXCE_LST > STARTDT and MXCE_LST < ENDDT then ENDDT = MXCE_LST;
format MXCE_FST MXCE_LST mmddyy10.;
run;
* 495,716;
*———————————————————;
Leave a Reply
You must be logged in to post a comment.