/********************************************************************** * PGM NAME: Comp_gest_new_fmt.sas * * (CD ROM sending to States who use new format of birth certificate * * NOTE: * * 1. This program is for NEW FORMAT BIRTH CERTIFICATE data * * 2. This programm is for creating a SAS data set from TEXT FILE * * created and maintained by State to edit the natality computed * * gestation(comp_gest) and combined gestation(comb_gest). * * 3. processing two variables: * * COMP_GEST--gestation computed based on LMP * * COMB_GEST--combined gestation based on the computed gestation * * or obstetric estimate gestation (owgest) described * * in Instruction manual part 12 -version 11/6/03 * * computer edits for Natality Data * * 2003 Revised Certificate * * Effective 2003 for Revising States * * CDC/NCHS * * DATE : 02/08/2005 * * PROGRAMMER: JIAQUAN XU * * SOFTWARE: SAS 8.02 * * ORGNIZATION: DVS/NCHS/CDC * **********************************************************************/ LIBNAME NAT 'C:\'; * where the SAS data set stored; FILENAME readin 'h:\_z\2005\nat\final\id05902a.nat'; * path for WA text file; *FILENAME readin 'c:\nat_file_gest\pa03916a.nat'; * path for WA text file; %GLOBAL ST YR; * create a global macro variable used in title; %let STE = id; * change the State name here; %let year = 2005; * this is the data year, change it accordingly; /************************************************************************************** * !!!!!! Variable Name Convention !!!!!! * * * * DOB_YY: Child Birth Year STATE: State * * CERT: Certificate Number DOB_MM: Child Birth Month * * DOB_DD: Child Birth Date DLMP_YY: Year of Last Normal Menses * * PLUR: Plurality DLMP_MM: Month Last Normal Menses * * BWT: Child Birth Weight DLMP_DD: Date Last Normal Menses * * MHISPC: Hispanic origin of Mother OWGEST: Obstetric Estimation of Gestation * * FHISPC: Hispanic origin of Father MBRACE: Mother's race * * FBRACE: Father's race VOID: Void * * OBWT: Birth weight used in PGM OBGEST: Recode of OWGEST uesd in PGM * * WT: Birth weight recode GESTMTH: Gestation month * * FRACE: Father's race recode MRACE: Mother's race recode * * MHISPC: Mother's Hispanic origin FHISPC: Father's Hispanic origin * * MRACEHISP: Mother's Hispanic origin recode * * FRACEHISP: Father's Hispanic origin recode * * COMPGESTok: Computed gestation consistency check value * * OBGESTok: Obstetric Gestation consistency check value * * * * COMP_GEST: Computed gestation * * COMB_GEST: Combined gestation * **************************************************************************************/ DATA NAT.GEST_&STE(DROP=HOLDBWT HOLDLMP_YY HOLDDOB_YY HOLDLMP_MM HOLDDOB_MM HOLDDOB_DD HOLDLMP_DD VOID); * read in data from text file; LENGTH HOLDBWT HOLDLMP_YY HOLDDOB_YY $ 8 HOLDLMP_MM HOLDDOB_MM HOLDDOB_DD HOLDLMP_DD $ 4; INFILE READIN LRECL = 1000; INPUT DOB_YY $ 1-4 STATE $ 5-6 CERT $ 7-12 VOID $ 13 DOB_MM $ 31-32 DOB_DD $ 33-34 DLMP_YY $ 812-815 DLMP_MM $ 816-817 DLMP_DD $ 818-819 BWT $ 865-868 OWGEST $ 870-871 PLUR $ 877-878 MHISPC $ 927-929 FHISPC $ 933-935 MBRACE $ 939-940 FBRACE $ 941-942; IF VOID = '1' THEN DELETE; * delete the record with void value 1; HOLDBWT = '0000' || BWT; * add zero(s) in front of the number if necessary; BWT = SUBSTR(RIGHT(HOLDBWT), 5); CERT = TRIM(CERT) || '000000'; * fill the blank space with zero(s) if necessary; HOLDLMP_YY ='0000' || DLMP_YY; DLMP_YY = SUBSTR(RIGHT(HOLDLMP_YY),5); HOLDDOB_YY ='0000' || DOB_YY; DOB_YY = SUBSTR(RIGHT(HOLDDOB_YY),5); HOLDLMP_MM ='00' || DLMP_MM; DLMP_MM = SUBSTR(RIGHT(HOLDLMP_MM),3); HOLDDOB_MM ='00' || DOB_MM; DOB_MM = SUBSTR(RIGHT(HOLDDOB_MM),3); HOLDLMP_DD ='00' || DLMP_DD; DLMP_DD = SUBSTR(RIGHT(HOLDLMP_DD),3); HOLDDOB_DD ='00' || DOB_DD; DOB_DD = SUBSTR(RIGHT(HOLDDOB_DD),3); RUN; PROC SORT DATA=NAT.GEST_&STE; BY STATE CERT; RUN; DATA NAT.MATRIX; /* Assign the value from previous year cases with complete reporting date of LMP to the matrix. The matrix will change as processing proceeds to reflect the last record with complete reporting of data of LMP, birth weight, and hispanic origin */ /***** Non_Hispanic White *****/ ARRAY NHWHITE(0:10, 5:10)WM1-WM66 /*<6 6 7 8 9 10+ gestation month*/ (20 21 24 28 33 39 /* <500 */ 18 23 29 31 34 38 /* 500 - 999 */ 18 22 26 32 38 39 /* 1000 - 1499 */ 18 21 27 31 38 40 /* 1500 - 1999 */ 18 23 25 30 34 40 /* 2000 - 2499 */ 18 23 28 33 35 39 /* 2500 - 2999 */ 18 23 27 32 38 39 /* 3000 - 3499 */ 17 17 24 34 38 39 /* 3500 - 3999 */ 19 23 27 30 34 39 /* 4000 - 4499 */ 17 21 26 31 36 39 /* 4500 - 4999 */ 18 23 27 31 38 40); /* >= 5000 */ /***** Non_Hispanic Black *****/ ARRAY NHBLACK(0:10, 5:10)BM1-BM66 /*<6 6 7 8 9 10+ gestation month*/ (18 23 26 29 33 39 /* <500 */ 19 22 26 33 35 39 /* 500 - 999 */ 17 22 26 31 38 39 /* 1000 - 1499 */ 18 21 25 32 38 40 /* 1500 - 1999 */ 19 21 28 30 34 38 /* 2000 - 2499 */ 19 22 26 31 37 39 /* 2500 - 2999 */ 17 22 27 34 38 39 /* 3000 - 3499 */ 20 21 24 29 34 40 /* 3500 - 3999 */ 18 23 27 31 34 39 /* 4000 - 4499 */ 17 22 26 31 37 39 /* 4500 - 4999 */ 19 21 27 33 36 40); /* >= 5000 */ /***** Non_Hispanic Other *****/ ARRAY NHOTHER(0:10, 5:10)OM1-OM66 /*<6 6 7 8 9 10+ gstation month*/ (20 23 28 30 34 39 /* <500 */ 17 21 27 32 37 39 /* 500 - 999 */ 17 23 26 31 38 40 /* 1000 - 1499 */ 19 21 23 31 36 39 /* 1500 - 1999 */ 17 20 29 32 35 39 /* 2000 - 2499 */ 19 21 27 31 38 39 /* 2500 - 2999 */ 17 21 27 32 38 40 /* 3000 - 3499 */ 18 23 26 29 33 39 /* 3500 - 3999 */ 18 23 26 32 35 39 /* 4000 - 4499 */ 18 23 26 31 38 39 /* 4500 - 4999 */ 17 23 25 29 37 40); /* >= 5000 */ /***** Hispanic *****/ ARRAY HISP(0:10, 5:10)HM1-HM66 /*<6 6 7 8 9 10+ gestation month*/ (20 21 24 28 33 39 /* <500 */ 18 23 29 31 34 38 /* 500 - 999 */ 18 22 26 32 38 39 /* 1000 - 1499 */ 18 21 27 31 38 40 /* 1500 - 1999 */ 18 23 25 30 34 40 /* 2000 - 2499 */ 18 23 28 33 35 39 /* 2500 - 2999 */ 18 23 27 32 38 39 /* 3000 - 3499 */ 17 17 24 34 38 39 /* 3500 - 3999 */ 19 23 27 30 34 39 /* 4000 - 4499 */ 17 21 26 31 36 39 /* 4500 - 4999 */ 18 23 27 31 38 40); /* >= 5000 */ RUN; DATA NAT.GEST&STE (KEEP = CERT DOB_DD DLMP_DD COMPGESTok OBGESTok OBWT DOB_MM DLMP_MM GESTMTH BWT DOB_YY DLMP_YY COMP_GEST WT OBGEST COMB_GEST STATE FRACE FBRACE FHISPC FRACEHISP MRACE MBRACE MHISPC MRACEHISP PLUR OWGEST RACEHISP INTDAY CALCDAY LMPLeap DOBLeap POB_YY POBLeap) NAT.MATRIX(KEEP = WM1-WM66 BM1-BM66 OM1-OM66 HM1-HM66); /*hotdeck*/ RETAIN PRE_DOB_MM PRE_RACE; LENGTH COMP_GEST 3 COMB_GEST 3; SET NAT.GEST_&STE END=EOF; IF _N_ = 1 THEN DO; SET NAT.MATRIX; * make the matrix available for all observations; CALL SYMPUT('ST', LEFT(TRIM(STATE))); * state name used in title; CALL SYMPUT('YR', LEFT(TRIM(DOB_YY))); * data year used in title; PRE_DOB_MM = '01'; * initializing month of birth; PRE_RACE = '01'; * initializing race of mother; END; /* Assign the values from the matrix to arrays based on the hispanic origin, gestation month and birth weight */ ARRAY NHWHITE(0:10, 5:10)WM1-WM66; ARRAY NHBLACK(0:10, 5:10)BM1-BM66; ARRAY NHOTHER(0:10, 5:10)OM1-OM66; ARRAY HISP (0:10, 5:10)HM1-HM66; /**** Date of Birth processing(Infant) ****/ /* p3 4B 1. Month of Birth: If the natality detail record is not coded 01-12, the code from the preceding record is inserted */ IF DOB_MM < '01' | DOB_MM > '12' THEN DOB_MM = PRE_DOB_MM; ELSE PRE_DOB_MM = DOB_MM; /* p3 4B 2. Day of Birth : B2.1 If the day is not within the range of 01-31 or is 99, chang to 15 */ IF DOB_DD < '01' | DOB_DD > '31' | DOB_DD = '99' THEN DOB_DD = '15'; /* p3 4B 2.2 The day of birth must fall within the correct range for the month (e.g. month 04,days 01-30). If not, change code for day to last permissible day of month. For example, if month is 04 and day is 31, change day code to 30 */ IF DOB_MM = '02' THEN DO; IF MOD(INPUT(SUBSTR(DOB_YY, 3), 2.), 4) = 0 THEN DO; IF DOB_DD > '29' THEN DOB_DD = '29'; * leap year; END; ELSE DO; IF DOB_DD > '28' THEN DOB_DD = '28'; * regular year; END; END; ELSE IF DOB_MM IN ('04' '06' '09' '11') THEN DO; * the month with 30 days; IF DOB_DD > '30' THEN DOB_DD = '30'; END; /* p37 49B Birth weight Coded in grams-edit detail entry for a range of 0227-8165 and if entry is outside this range or unknown, change code to 9999 */ OBWT = BWT; IF oBWT < '0227' | oBWT > '8165' THEN oBWT = '9999'; /* P39 52B Plurality If plurality not coded 01-16, change code to 01. */ IF PLUR < '01' | PLUR > '16' THEN PLUR = '01'; /**** Last menstrual Period Edits *****/ /* p30 39B LMP 39B 1. If MONTH of last normal menses is not coded 01-12 or 99, change to 99 */ IF DLMP_MM < '01' OR DLMP_MM > '12' THEN DLMP_MM = '99'; /* p30 39B 2. If DAY is not 01-31 or 99, change code to 99. Check that day is valid for month (e.g., month = 04, day = 01-30). If not, change it to the last valid day for month*/ IF DLMP_DD < '01' OR DLMP_DD > '31' THEN DLMP_DD = '99'; IF DLMP_MM = '02' THEN DO; * February; IF MOD(INPUT(SUBSTR(DLMP_YY, 3), 2.), 4) = 0 THEN DO; IF DLMP_DD > '29' & DLMP_DD ^= '99' THEN DLMP_DD = '29'; * leap year; END; ELSE DO; IF DLMP_DD > '28' & DLMP_DD ^= '99' THEN DLMP_DD = '28'; * regular year; END; END; IF DLMP_MM IN('04' '06' '09' '11') THEN DO; * The months with 30 days; IF DLMP_DD > '30' & DLMP_DD ^= '99' THEN DLMP_DD = '30'; END; /* p30 39B 3. If YEAR of last normal menses is not the same as or one or two years less than the year of birth, change code to 9999 */ if DOB_YY ^= &year then DOB_YY = &year; DOBYY = INPUT(DOB_YY, 4.) - 2; DOB_YY_2 = PUT(DOBYY, 4.); IF DLMP_YY < DOB_YY_2 | DLMP_YY > DOB_YY THEN DLMP_YY = '9999'; /* p30 39B 4. Period of gestation is compted from date of birth(output pos. 1-4, 31-32, 33-34) and date of LMP (output pos. 812-819). Each item must be edited for impossible codes before gestation can be computed */ /* p30 39B 4.1. If month of last normal menses (output pos. 816-817)is coded 99, code gestation 99 */ IF DLMP_MM = '99' THEN COMP_GEST = 99; /* p30 39B 4.2. If year of last normal menses (output pos. 812-815) is code 9999, code gestation 99*/ IF DLMP_YY = '9999' THEN COMP_GEST = 99; /* p30 39B 5. For records with complete date of LMP, comput period of gestation as follows: */ /* P30 39B 5.1. Determine interval in days between date of LMP and date of birth. */ /* p30 39 B 5.1.1. Determine day of year of birth and day of year of LMP. Day of year of the event = starting day factor of month of event (see chart) plus day of month. For example, the day of year of an event occurring on August 9 = 221 (212 + 9) ____________________________________________________________________ Month name month code starting day factor ____________________________________________________________________ January 01 000 February 02 031 March 03 059 April 04 090 May 05 120 June 06 151 July 07 181 August 08 212 September 09 243 October 10 273 November 11 304 December 12 334 ____________________________________________________________________*/ /* p31 39B 5.1.2. & 5.1.3. Interval in days = Day of year of birth minus day of year of LMP. If the data year is a Leap Year (Last 2 digits evenly divisible by 4) and month code of birth (see chart) is greater than 02, add 1 to calculated interval in days. */ POB_YY = DOB_YY - 1; if(mod(POB_YY,4) = 0) then POBLeap = 1; else POBLeap = 0; IF MOD(INPUT(SUBSTR(DOB_YY, 3), 2.), 4) = 0 THEN DO; * starting date factor for leap year; M1 = 0; M2 = 31; M3 = 60; M4 = 91; M5 = 121; M6 = 152; M7 = 182; M8 = 213; M9 = 244; M10= 274; M11 = 305; M12 = 335; dobLeap = 1; END; ELSE DO; * starting date factor for regular year; M1 = 0; M2 = 31; M3 = 59; M4 = 90; M5 = 120; M6 = 151; M7 = 181; M8 = 212; M9 = 243; M10 = 273; M11= 304; M12= 334; dobLeap = 0; END; IF DLMP_YY ^= '9999' THEN DO; IF MOD(INPUT(SUBSTR(DLMP_YY, 3), 2.), 4) = 0 THEN DO; * starting date factor for LMP leap year; L1 = 0; L2 = 31; L3 = 60; L4 = 91; L5 = 121; L6 = 152; L7 = 182; L8 = 213; L9 = 244; L10= 274; L11 = 305; L12 = 335; lmpLeap = 1; END; ELSE DO; * starting date factor for LMP regular year; L1 = 0; L2 = 31; L3 = 59; L4 = 90; L5 = 120; L6 = 151; L7 = 181; L8 = 212; L9 = 243; L10 = 273; L11= 304; L12= 334; lmpLeap = 0; END; END; ARRAY S_D_F_L(12) L1-L12; ARRAY S_D_F(12) M1-M12; *5.1.2; IF DLMP_YY ^='9999' & DLMP_MM ^= '99' & DLMP_DD ^= '99' THEN DO; CALCDAY = (S_D_F(INPUT(DOB_MM, 2.)) + INPUT(DOB_DD, 2.)) - (S_D_F_L(INPUT(DLMP_MM, 2.)) + INPUT(DLMP_DD, 2.)); put cert CALCDAY; intday = calcday; * out of range; if( DLMP_YY <= DOB_YY - 2 ) then INTDAY = 999; * lmp leap year; else if(INTDAY < 0 & LMPLeap = 1 & DOBLeap = 0) then INTDAY = INTDAY + 366; * lmp not leap year; else if(INTDAY < 0) then INTDAY = INTDAY + 365; /* P31 39B 5.2 Calculating interval in days between birth date and last normal menses. If interval in days is negative add 365 days. This can occur if: Year of LMP is incorrectely given as the same as the year of birth and month code of LMP is greater than month code of birth */ *IF DLMP_YY < DOB_YY THEN INTDAY + 365; * for record dob_yy>dlmp_yy; * IF INTDAY < 0 THEN INTDAY = INTDAY + 365; * for record dob_mm 47 THEN COMP_GEST= 99; END; /****** Check Mother's RACE ******/ /* p13 22. If record is coded 15 or 99 impute mother's race as that of father's race if coded 1-14. Otherwise, impute race of mother of preceding record IF preceding record is coded 1-14. */ IF MBRACE = '15' | MBRACE = '99' THEN DO; /* impute from father's or pre_race */ IF '01' <= FBRACE <= '14' THEN MBRACE = FBRACE; ELSE MBRACE = PRE_RACE; END; ELSE IF '01' <= MBRACE <= '14' THEN PRE_RACE = MBRACE; IF FBRACE = '15' THEN FBRACE = '99'; /* recode race */ /* mother's race */ IF MBRACE = "01" THEN MRACE = '1'; /* white */ ELSE IF MBRACE = "02" THEN MRACE = '2'; /* black */ ELSE IF MBRACE = "03" THEN MRACE = '3'; /* american_indian */ ELSE IF "04" <= MBRACE <= "14" THEN MRACE = '4'; /* pacific_islander */ ELSE IF MBRACE = "21" THEN MRACE = '1'; /* white */ ELSE IF MBRACE = "22" THEN MRACE = '2'; /* black */ ELSE IF MBRACE = "23" THEN MRACE = '3'; /* american Indian */ ELSE IF MBRACE = "24" THEN MRACE = '4'; /* pacific Islander */ /* father's race */ IF FBRACE = "01" THEN FRACE = '1'; /* white */ ELSE IF FBRACE = "02" THEN FRACE = '2'; /* black */ ELSE IF FBRACE = "03" THEN FRACE = '3'; /* american indian */ ELSE IF "04" <= FBRACE <= "14" THEN FRACE = '4'; /* pacific_islander */ ELSE IF FBRACE = "21" THEN FRACE = '1'; /* white */ ELSE IF FBRACE = "22" THEN FRACE = '2'; /* black */ ELSE IF FBRACE = "23" THEN FRACE = '3'; /* american indian */ ELSE IF FBRACE = "24" THEN FRACE = '4'; /* pacific islander */ ELSE FRACE = '0'; /* race unknown; /****** recode hispanic origin ******/ /* p10-2 21 && 24 */ IF MHISPC < '100' | ( '299' < MHISPC < '996') | MHISPC > '999' THEN MHISPC = "999"; * if code not in range, change to '999'; IF FHISPC < '100' | ( '299' < FHISPC < '996') | FHISPC > '999' THEN FHISPC = "999"; /* mother's hispanic origin */ IF '100' <= MHISPC <= '199' THEN rMHISP = '1'; /* non_Hispanic */ ELSE IF '200' <= MHISPC <= '209' THEN rMHISP = '7'; /* other Hispanic */ ELSE IF '210' <= MHISPC <= '220' THEN rMHISP = '2'; /* mexican */ ELSE IF '221' <= MHISPC <= '249' THEN rMHISP = '3'; /* south america */ ELSE IF '250' <= MHISPC <= '259' THEN rMHISP = '7'; /* other Hispanic */ ELSE IF '260' <= MHISPC <= '269' THEN rMHISP = '4'; /* puerto rican */ ELSE IF '270' <= MHISPC <= '274' THEN rMHISP = '5'; /* cuban */ ELSE IF '275' <= MHISPC <= '279' THEN rMHISP = '6'; /* dominican */ ELSE IF '280' <= MHISPC <= '299' THEN rMHISP = '7'; /* other Hispanic */ ELSE IF '996' <= MHISPC <= '999' THEN rMHISP = '9'; /* unknown */ IF rMHISP = '1' or rMHISP = '9' THEN DO; /* Non_Hispanic */ IF MRACE = '1' THEN MRACEHISP= '1'; /* NH White */ IF MRACE = '2' THEN MRACEHISP= '2'; /* NH Black */ IF MRACE = '3' THEN MRACEHISP= '3'; /* NH Other */ IF MRACE = '4' THEN MRACEHISP= '3'; /* NH Other */ END; ELSE IF '2'<=rMHISP<='7' THEN MRACEHISP= '4'; /* Hispanic */ RACEHISP = MRACEHISP; /* father's hispanic origin */ IF '100' <= FHISPC <= '199' THEN rFHISP = '1'; /* non_Hispanic */ ELSE IF '200' <= FHISPC <= '209' THEN rFHISP = '7'; /* other Hispanic */ ELSE IF '210' <= FHISPC <= '220' THEN rFHISP = '2'; /* mexican */ ELSE IF '221' <= FHISPC <= '249' THEN rFHISP = '3'; /* south america */ ELSE IF '250' <= FHISPC <= '259' THEN rFHISP = '7'; /* other Hispanic */ ELSE IF '260' <= FHISPC <= '269' THEN rFHISP = '4'; /* puerto rican */ ELSE IF '270' <= FHISPC <= '274' THEN rFHISP = '5'; /* cuban */ ELSE IF '275' <= FHISPC <= '279' THEN rFHISP = '6'; /* dominican */ ELSE IF '280' <= FHISPC <= '299' THEN rFHISP = '7'; /* other Hispanic */ ELSE IF '996' <= FHISPC <= '999' THEN rFHISP = '9'; /* unknown */ IF rFHISP = '1' THEN DO; /* Non_Hispanic */ IF FRACE = '1' THEN FRACEHISP= '1'; /* NH White */ IF FRACE = '2' THEN FRACEHISP= '2'; /* NH Black */ IF FRACE = '3' THEN FRACEHISP= '3'; /* NH Other */ IF FRACE = '4' THEN FRACEHISP= '3'; /* NH Other */ if FRACE = '0' then FRACEHISP= '3'; END; ELSE IF '2'<=rFHISP<='7' THEN FRACEHISP= '4'; /* Hispanic */ ELSE IF rFHISP = '9' THEN FRACEHISP= '3'; /* Unknown */ /* create a new variable(wt) and assign a value to it based on the birth weight and use this value, gestation month and Hispanic origin in ARRAY below to locate the single gestation week */ IF oBWT < "0500" THEN wt = 0; ELSE IF oBWT < "1000" THEN wt = 1; ELSE IF oBWT < "1500" THEN wt = 2; ELSE IF oBWT < "2000" THEN wt = 3; ELSE IF oBWT < "2500" THEN wt = 4; ELSE IF oBWT < "3000" THEN wt = 5; ELSE IF oBWT < "3500" THEN wt = 6; ELSE IF oBWT < "4000" THEN wt = 7; ELSE IF oBWT < "4500" THEN wt = 8; ELSE IF oBWT < "5000" THEN wt = 9; ELSE wt = 10; /* P31 39B 6. For records missing only day of LMP and with valid birth weight, compute period of gestation as follow: */ /* p31 39B 6.1 Convert month and year of birth and month and year of LMP into century months.(Century month = year of event times 12 plus month of event). */ IF DLMP_DD = "99" & DLMP_MM ^= "99" & DLMP_YY ^= "9999" & oBWT ^= "9999" THEN DO; DOB_CENT = INPUT(DOB_YY, 4.) * 12 + INPUT(DOB_MM, 2.); LMP_CENT = INPUT(DLMP_YY, 4.) * 12 + INPUT(DLMP_MM, 2.); /* p31 39B 6.2 Compute Month Difference: Month Difference = Century month of birth date minus century month of LMP. If computed month difference is 12 or higher, or less than 4, assign code 99 for weeks of gestation. If computed month difference is negative, add 12. */ GESTMTH = DOB_CENT - LMP_CENT; IF GESTMTH < 0 THEN GESTMTH = GESTMTH + 12; IF GESTMTH < 4 | GESTMTH >= 12 THEN COMP_GEST = 99; /* p31 39B 6.3 Impute single weeks of gestation (17-47) for each racial group of mother (Non-Hispanic white, non-Hispanic Black, Non-Hispanic other, Hispanic) using the following matrix. The initial matrix is created for each racial group based on previous year cases with complete reporting of date LMP. The matrix will change as processing proceeds to reflect the last record with complete reporting of date of LMP, birth weight, and Hispanic origin. */ /* RACEHISP (4) */ /* NHWHITE(0:10, 5:10) (wt(11), gestmth(6)) */ /* <6 6 7 8 9 10+ */ /* 20,21,24,28,33,39, /* <500 */ /* 18,23,29,31,34,38, /* 500 - 999 */ /* 18,22,26,32,38,39, /* 1000 - 1499 */ /* 18,21,27,31,38,40, /* 1500 - 1999 */ /* 18,23,25,30,34,40, /* 2000 - 2499 */ /* 18,23,28,33,35,39, /* 2500 - 2999 */ /* 18,23,27,32,38,39, /* 3000 - 3499 */ /* 17,17,24,34,38,39, /* 3500 - 3999 */ /* 19,23,27,30,34,39, /* 4000 - 4499 */ /* 17,21,26,31,36,39, /* 4500 - 4999 */ /* 18,23,27,31,38,40, /* >= 5000 */ /* NHBLACK(0:10, 5:10) (wt(11), gestmth(6)) */ /* <6 6 7 8 9 10+ */ /* 18,23,26,29,33,39, /* <500 */ /* 19,22,26,33,35,39, /* 500 - 999 */ /* 17,22,26,31,38,39, /* 1000 - 1499 */ /* 18,21,25,32,38,40, /* 1500 - 1999 */ /* 19,21,28,30,34,38, /* 2000 - 2499 */ /* 19,22,26,31,37,39, /* 2500 - 2999 */ /* 17,22,27,34,38,39, /* 3000 - 3499 */ /* 20,21,24,29,34,40, /* 3500 - 3999 */ /* 18,23,27,31,34,39, /* 4000 - 4499 */ /* 17,22,26,31,37,39, /* 4500 - 4999 */ /* 19,21,27,33,36,40, /* >= 5000 */ /* NHOTHER(0:10, 5:10) (wt(11), gestmth(6)) */ /* <6 6 7 8 9 10+ */ /* 20,23,28,30,34,39, /* <500 */ /* 17,21,27,32,37,39, /* 500 - 999 */ /* 17,23,26,31,38,40, /* 1000 - 1499 */ /* 19,21,23,31,36,39, /* 1500 - 1999 */ /* 17,20,29,32,35,39, /* 2000 - 2499 */ /* 19,21,27,31,38,39, /* 2500 - 2999 */ /* 17,21,27,32,38,40, /* 3000 - 3499 */ /* 18,23,26,29,33,39, /* 3500 - 3999 */ /* 18,23,26,32,35,39, /* 4000 - 4499 */ /* 18,23,26,31,38,39, /* 4500 - 4999 */ /* 17,23,25,29,37,40, /* >= 5000 */ /* HISP(0:10, 5:10) wt(11), gestmth(6)) */ /* <6 6 7 8 9 10+ */ /* 20,21,24,28,33,39, /* <500 */ /* 18,23,29,31,34,38, /* 500 - 999 */ /* 18,22,26,32,38,39, /* 1000 - 1499 */ /* 18,21,27,31,38,40, /* 1500 - 1999 */ /* 18,23,25,30,34,40, /* 2000 - 2499 */ /* 18,23,28,33,35,39, /* 2500 - 2999 */ /* 18,23,27,32,38,39, /* 3000 - 3499 */ /* 17,17,24,34,38,39, /* 3500 - 3999 */ /* 19,23,27,30,34,39, /* 4000 - 4499 */ /* 17,21,26,31,36,39, /* 4500 - 4999 */ /* 18,23,27,31,38,40 /* >= 5000 */ IF GESTMTH < 6 THEN GESTMTH = 5; * regroup the gestation month for; IF GESTMTH >=10 THEN GESTMTH = 10; * the array assignment below; IF COMP_GEST ^= 99 & oBWT ^= "9999" THEN DO; /*******************************************************/ /* Extract comp_gest from hotdeck for racords only */ /* missing day of LMP with valid birth weight */ /*******************************************************/ ***** Non-Hispanic White *****; IF RACEHISP= '1' THEN COMP_GEST = NHWHITE(WT,GESTMTH); ***** Non_Hispanic Black *****; IF RACEHISP= '2' THEN COMP_GEST = NHBLACK(WT, GESTMTH); ***** Non_Hispanic Other *****; IF RACEHISP= '3' THEN COMP_GEST = NHOTHER(WT, GESTMTH); ***** Hispanic *****; IF RACEHISP= '4' THEN COMP_GEST = HISP(WT, GESTMTH); END; END; /* Insert comp_gest to hotdeck when data for following 4 variables are good */ IF DLMP_DD ^= "99" & DLMP_MM ^= "99" & DLMP_YY ^= "9999" & oBWT ^= "9999" THEN DO; IF 17 <= COMP_GEST <= 47 THEN DO; DOB_CENT = INPUT(DOB_YY, 4.) * 12 + INPUT(DOB_MM, 2.); LMP_CENT = INPUT(DLMP_YY, 4.) * 12 + INPUT(DLMP_MM, 2.); GESTMTH = DOB_CENT - LMP_CENT; IF GESTMTH < 0 THEN GESTMTH = GESTMTH + 12; IF GESTMTH < 4 | GESTMTH >= 12 THEN COMP_GEST = 99; IF GESTMTH < 6 THEN GESTMTH = 5; * regroup the gestation month for; IF GESTMTH >=10 THEN GESTMTH = 10; * the array assignment below; IF COMP_GEST ^= 99 THEN DO; IF RACEHISP= '1' THEN NHWHITE(WT,GESTMTH) = COMP_GEST; IF RACEHISP= '2' THEN NHBLACK(WT,GESTMTH) = COMP_GEST; IF RACEHISP= '3' THEN NHOTHER(WT,GESTMTH) = COMP_GEST; IF RACEHISP= '4' THEN HISP(WT,GESTMTH) = COMP_GEST; END; END; END; /* p32 39B 6.4 Check to insure that imputed weeks of gestation is not impossible, given the DAY of birth. */ /* P32 39B 6.4.1. Compute the longest theoretical number of weeks of gestation from actual day of birth with the assumption that the day of LMP is the first day of the month of LMP. Similarly, compute the shortest theoretical number of weeks of gestation by assuming that the day of LMP is the last day of the month of LMP. To compute these two theoretical periods of gestation, follow the same procedure as outlined for records with complete LMP date (see 39B 5.). If the imputed weeks of gestation is fewer than the lowest theoretical number, substitute the lowest theorctical number. Similarly, if the imputed weeks of gestation is greater than the highest theoretical number, substitute the highest theoretical number. Check to see that the substitution falls within the range of 17 to 47 weeks. If outside this range, change imputed value to 99. */ IF DLMP_DD = '99' & DLMP_MM ^= '99' & DLMP_YY ^= "9999" & COMP_GEST ^= 99 THEN DO; /* maximum days, assuming first day of LMP. */ MAXDAYS = (S_D_F(INPUT(DOB_MM, 2.)) + INPUT(DOB_DD, 2.)) - (S_D_F_L(INPUT(DLMP_MM, 2.)) + 1); IF MAXDAYS <= 0 THEN MAXDAYS = MAXDAYS + 365; /* longest theoretical number of weeks of gestation */ MAXWKS = INT(MAXDAYS / 7); /* minmum days, assuming last day of LMP. */ IF DLMP_MM < '12' THEN MINDAYS = (S_D_F(INPUT(DOB_MM, 2.)) + INPUT(DOB_DD, 2.)) - (S_D_F_L(INPUT(DLMP_MM, 2.) + 1)); * for Jan.-Nov.; ELSE IF DLMP_MM = '12' THEN MINDAYS = (S_D_F(INPUT(DOB_MM, 2.)) + INPUT(DOB_DD, 2.)) - (S_D_F_L(INPUT(DLMP_MM, 2.)) + 31); * for Dec.; IF MINDAYS <= 0 THEN MINDAYS = MINDAYS + 365; /* shortest theoretical number of weeks of gestation */ MINWKS = INT(MINDAYS / 7); if comp_gest = . then do; /*this statements add here is for matching the comp_gest */ if 17 <= minwks <= 47 then comp_gest = minwks; /* generated from Steve's C program*/ else comp_gest = maxwks; end; IF COMP_GEST < MINWKS THEN COMP_GEST = MINWKS; IF COMP_GEST > MAXWKS THEN COMP_GEST = MAXWKS; IF COMP_GEST < 17 | COMP_GEST > 47 THEN COMP_GEST = 99; END; /* P37 50B Obstetric Estimation of Gestation (Output pos. 870-871). */ /* p37 50B 1. If not coded 00-98 or 99, change code to 99. */ OBGEST = OWGEST; * create a new variable used in PGM; IF ObGEST < '17' | ObGEST > '47' & ObGEST ^='99' THEN ObGEST = '99'; OBGESTok = 0; /* p37 50B 2. Generate a combined gestation field called comb_gest. */ /* p37 50B 2.1 comp_gest prefered Except as noted in 50B 2.2, IF LMP gestation is 17 to 47 weeks, enter LMP gestation in combined gestation field. */ /* use computed gestation if possible */ IF 17 <= COMP_GEST <= 47 THEN COMB_GEST = COMP_GEST; /* p37 50B 2.2 If LMP gestation is 17 to 47 weeks, check compatibility with birth weight as follow: */ /* p38 50B2.2.1 Once plurality is edited, compare weeks of gestation derived from LMP date with birth weight using the following table: If weeks of gestation AND Then birth weight based on LMP date are: Plurality is: should be: _________________________________________________________________________ A) Less than 20 weeks All Less than 1,000 grams B) 20-23 weeks All Less then 2,000 grams C) 24-27 weeks All Less than 3,000 grams D) 28-31 weeks All Less than 4,000 grams E) 32-35 weeks Singleton 500 grams or more* F) 36 or more weeks Singleton 750 grams or more* _________________________________________________________________________ * See 2.2.3 */ /* Edit comp_gest for valid values overwrite comb_gest if consistency check failed */ COMPGESTok = 0; IF 17 <= COMP_GEST <= 47 & OBWT ^= '9999' THEN DO; IF COMP_GEST < 20 & PLUR > '00' THEN DO; IF oBWT < '1000' THEN COMPGESTok = 1; END; ELSE IF 20 <= COMP_GEST <= 23 & PLUR > '00' THEN DO; IF oBWT < '2000' THEN COMPGESTok = 2; END; ELSE IF 24 <= COMP_GEST <= 27 & PLUR > '00' THEN DO; IF oBWT < '3000' THEN COMPGESTok = 3; END; ELSE IF 28 <= COMP_GEST <= 31 & PLUR > '00' THEN DO; IF oBWT < '4000' THEN COMPGESTok = 4; END; IF PLUR > '01' & COMPGESTok = 0 THEN COMPGESTok = 5; ELSE IF 32 <= COMP_GEST <= 35 & PLUR = '01' THEN DO; IF oBWT >= '0500' THEN COMPGESTok = 6; END; ELSE IF COMP_GEST > 35 & PLUR = '01' THEN DO; IF oBWT >= '0750' THEN COMPGESTok = 7; END; /* p38 50B 2.2.2 If records fail consistency checks A through F, then compare obstetric estimate of gestation with birth weight using these same parameters. */ /* computed gestation bad so try to use obgest */ IF COMPGESTok = 0 THEN DO; IF '17' <= ObGEST <= '47' THEN DO; OBGESTok = 0; IF OBGEST < '20' & PLUR > '00' THEN DO; IF oBWT < '1000' THEN OBGESTok = 1; END; ELSE IF '20' <= OBGEST <= '23' & PLUR > '00' THEN DO; IF oBWT < '2000' THEN OBGESTok = 2; END; ELSE IF '24' <= OBGEST <= '27' & PLUR > '00' THEN DO; IF oBWT < '3000' THEN OBGESTok = 3; END; ELSE IF '28' <= OBGEST <= '31' & PLUR > '00' THEN DO; IF oBWT < '4000' THEN OBGESTok = 4; END; IF PLUR > '01' THEN OBGESTok = 5; ELSE IF '32' <= OBGEST <= '35' & PLUR = '01' THEN DO; IF oBWT >= '0500' THEN OBGESTok = 6; END; ELSE IF OBGEST > '35' & PLUR = '01' THEN DO; IF oBWT >= '0750' THEN OBGESTok = 7; END; END; /* p38 50B 2.2.2.4 If obgest is unknown, assign 99 to comb_gest */ ELSE IF OBGEST = '99' THEN COMB_GEST = 99; /* p38 50B 2.2.2.1 If the obstetric estimate IS 17-47 WEEKS and IS compatible with birth weight, enter the obstetric estimate in combined gestation field. */ IF OBGESTok >= 1 THEN COMB_GEST = INPUT(OBGEST, 2.); /* obgest ok */ /* p38 50B 2.2.2.2 If obstetric estimate is also not compatible with birth weight, but is within plus or minus 5 weeks of gestation based on LMP date, code birth weight '9999', and enter gestation period based on LMP date in combined gestation field. */ ELSE IF OBGESTok = 0 & ((COMP_GEST - 5) <= INPUT(OBGEST, 2.) <= (COMP_GEST + 5)) THEN DO; BWT = '9999'; COMB_GEST = COMP_GEST; END; /* p38 50B 2.2.2.3 If obstetric estimate is also not compatible with birth weight, and is not within plus or minus 5 weeks of period of gestation based on LMP date, code birth weight '9999', and code combined gestation field '99'. */ ELSE IF (OBGESTok = 0 & INPUT(OBGEST, 2.) < (COMP_GEST - 5)) | (OBGESTok = 0 & INPUT(OBGEST, 2.) > (COMP_GEST + 5)) THEN DO; BWT = '9999'; COMB_GEST = 99; END; /* p38 50B 2.2.2.4 If obstetric estimate is unknown, code combined gestation field 99 */ ELSE IF OBGEST = '99' THEN COMB_GEST = 99; END; /* p38 50B 2.2.3 If LMP gestation is 32-35, plurality is single and birth weight is 500-999 grams, OR if LMP gestation is 36-weeks or more, plurality is single, and birth weight is 750-999 grams, check for consistency between LMP gestation and the obstetric estimate is three weeks or more LESS THAN the LMP gestation, enter the obstetric in the combined gestation field. Otherwise, leave all variables as reported. */ IF( 32 <= COMP_GEST <= 35 & PLUR = '01' & '0500' <= oBWT <= '0999') | (COMP_GEST >= 36 & PLUR = '01' & '0750' <= oBWT <= '0999') THEN DO; IF INPUT(OBGEST, 2.) <= (COMP_GEST - 3) THEN DO; COMB_GEST = INPUT(OBGEST, 2.); END; END; END; /* p39 50B 2.3 If LMP gestation is coded 99, and birth weight < '0227' or > '8165', and obgest is in 17-47, use obstetric estimate of gestation in combined gestation field. */ IF COMP_GEST = 99 THEN DO; /* p39 50.2.3.1 Compare weeks of gestation based on obstetric estimate with birth weight, using chart in 50B 2.2 */ IF '17' <= OBGEST <= '47' THEN DO; OBGESTok = 0; IF OBGEST < '20' & PLUR >= '01' THEN DO; IF oBWT < '1000' | BWT < '0227' | BWT > '8165' THEN OBGESTok = 1; END; ELSE IF '20' <= OBGEST <= '23' & PLUR >= '01' THEN DO; IF oBWT < '2000' | BWT < '0227' | BWT > '8165' THEN OBGESTok = 2; END; ELSE IF '24' <= OBGEST <= '27' & PLUR >= '01' THEN DO; IF oBWT < '3000' | BWT < '0227' | BWT > '8165' THEN OBGESTok = 3; END; ELSE IF '28' <= OBGEST <= '31' & PLUR >= '01' THEN DO; IF oBWT < '4000' | BWT < '0227' | BWT > '8165' THEN OBGESTok = 4; END; ELSE IF PLUR > '01' THEN OBGESTok = 5; ELSE IF '32' <= OBGEST <= '35' & PLUR = '01' THEN DO; IF oBWT >= '0500' | BWT < '0227' THEN OBGESTok = 6; END; ELSE IF OBGEST > '35' & PLUR = '01' THEN DO; IF oBWT >= '0750' | BWT < '0227' THEN OBGESTok = 7; END; END; /* p39 50B 2.3.1.1 If records fail consistency checks A, B, C,or D, OR if obstetric estimate is 32-35 weeks, plurality is single, and birth weight is less than 500 grams, OR if obstetric estimate is 36 weeks or more, plurality is single, and birth weight is less than 750 grams, code combined gestation field 99. */ IF OBGESTok = 0 | ('32' <= OBGEST <= '35' & PLUR = '01' & '0227' <= BWT < '0500') | (OBGEST >= '36' & PLUR = '01' & '0227' <= BWT < '0750') THEN DO; COMB_GEST = 99; END; /* p39 50B 2.3.1.2 Otherwise, enter obstetric estimate in combined gestation field. */ ELSE COMB_GEST = INPUT(OBGEST, 2.); END; OUTPUT NAT.GEST&STE; IF EOF THEN OUTPUT NAT.MATRIX; * keep the hotdeck for reference only; RUN; OPTIONS LS=100 PAGENO=1; PROC PRINT DATA=NAT.GEST&STE(obs=50); TITLE "computed gestation and combined gestation"; TITLE2 "for the STATE of &ST, year &YR, First 50 Records"; VAR STATE CERT COMP_GEST COMB_GEST DOB_YY DLMP_YY; * VAR STATE CERT DLMP_YY DLMP_MM DLMP_DD LMPLeap DOB_YY DOB_MM DOB_DD DOBLeap POBLeap CALCDAY INTDAY COMP_GEST COMB_GEST; RUN; DATA _NULL_; CALL SOUND(400,200); RUN;