*===================================================================;
*  Title:  PROGRAM 1  ASSIGN AHRQ PATIENT SAFETY INDICATORS
*          TO INPATIENT RECORDS
*
*  Description:
*         ASSIGNS THE OUTCOME OF INTEREST AND POPULATION AT RISK
*         INDICATORS TO INPATIENT RECORDS.  ALSO ASSIGNS 
*         COMORBIDITY CATEGORIES.
*
*          >>>  VERSION 2.1 (revision 3), January 2005 <<<
*
*  USER NOTE:  Make sure you have created the format library
*              using PSFMTS.SAS BEFORE running this program.
*
*===================================================================;
FILENAME CONTROL "C:\PATHNAME\CONTROL_PSI.SAS"; *<==USER MUST modify;

%INCLUDE CONTROL;

 TITLE2 'PROGRAM 1';
 TITLE3 'AHRQ PATIENT SAFETY INDICATORS: ASSIGN PSIS TO INPATIENT DATA';

 * -------------------------------------------------------------- ;
 * --- PATIENT SAFETY INDICATOR (PSI) NAMING CONVENTION:      --- ;
 * --- THE FIRST LETTER IDENTIFIES THE PATIENT SAFETY         --- ;
 * --- INDICATOR AS ONE OF THE FOLLOWING:
                (O) OBSERVED RATES
                (R) RISK-ADJUSTED RATES
                (S) SMOOTHED RATES
                (T) NUMERATOR ("TOP")
                (P) POPULATION ("POP")
 * --- THE SECOND LETTER IDENTIFIES THE PSI AS A PROVIDER (P) --- ;
 * --- OR AN AREA (A) LEVEL INDICATOR.  THE                   --- ;
 * --- NEXT TWO CHARACTERS ARE ALWAYS 'PS'. THE LAST TWO      --- ;
 * --- DIGITS ARE THE INDICATOR NUMBER (WITHIN THAT SUBTYPE). --- ;
 * -------------------------------------------------------------- ;

 %MACRO ADDPRDAY; 
    %IF &PRDAY EQ 1 %THEN PRDAY1-PRDAY&NPR. ;
 %MEND;

 %MACRO ADDMSA;
    %IF &MSALEVL EQ 1 %THEN MSA;
 %MEND;

 %MACRO CTY2MSA;
    %IF &MSALEVL EQ 1 %THEN %DO;
        ATTRIB MSA LENGTH=$5
          LABEL='MSA AREA ASSIGNED FROM HOSPSTCO';
        MSA = INPUT(PUT(HOSPSTCO,AREA.),$5.);
    %END;
 %MEND;

 %MACRO ADDYR;
    %IF &YEARQTR EQ 1 %THEN YEAR ;
 %MEND ADDYR;

 %MACRO ADDQT;
    %IF &YEARQTR EQ 1 %THEN DQTR ;
 %MEND ADDQT;

 DATA OUT1.&OUTFILE1. (
      DROP=DISP PAY1 RACE SEX DX1-DX&NDX. PR1-PR&NPR. %ADDPRDAY 
           I J DXVALUE A1-A36 
           HTN HTNCX HTNWCHF HTNWOCHF HTNWRF HTNWORF HTNWHRF HTNWOHRF 
           CARDFLG PERIFLG CEREFLG NERVFLG PULMFLG DIABFLG HYPOFLG RENALFLG 
           RENFFLG LIVERFLG ULCEFLG HIVFLG LEUKFLG CANCFLG ARTHFLG
           NUTRFLG ANEMFLG ALCFLG
           MPRCNT ORCNT MPRDAY MPRDAYA MPRDAYB ORDAY);
   SET IN1.&INFILE1. (
      KEEP=KEY DRG MDC SEX AGE HOSPSTCO PAY1 HOSPID DISP RACE LOS ASOURCE ATYPE
           DX1-DX&NDX. PR1-PR&NPR. %ADDPRDAY %ADDYR %ADDQT);
           
 * -------------------------------------------------------------- ;
 * --- DIAGNOSIS AND PROCEDURE MACROS --------------------------- ;
 * -------------------------------------------------------------- ;

 %MACRO MDX(FMT);

 (%DO I = 1 %TO &NDX.-1;
  (PUT(DX&I.,&FMT.) = '1') OR
  %END;
  (PUT(DX&NDX.,&FMT.) = '1'))

 %MEND;

 %MACRO MDX1(FMT);

 ((PUT(DX1,&FMT.) = '1'))

 %MEND;

 %MACRO MDX2(FMT);

 (%DO I = 2 %TO &NDX.-1;
  (PUT(DX&I.,&FMT.) = '1') OR
  %END;
  (PUT(DX&NDX.,&FMT.) = '1'))

 %MEND;

 %MACRO MDR(FMT);

 (PUT(PUT(DRG,Z3.),&FMT.) = '1')

 %MEND;

 %MACRO MPR(FMT);

 (%DO I = 1 %TO &NPR.-1;
  (PUT(PR&I.,&FMT.) = '1') OR
  %END;
  (PUT(PR&NPR.,&FMT.) = '1'))

 %MEND;

 %MACRO MPR1(FMT);

 (PUT(PR1,&FMT.) = '1')

 %MEND;

 %MACRO MPR2(FMT);

 (%DO I = 2 %TO &NPR.-1;
  (PUT(PR&I.,&FMT.) = '1') OR
  %END;
  (PUT(PR&NPR.,&FMT.) = '1'))

 %MEND;

 %MACRO MPRCNT(FMT);

    MPRCNT = 0; 
    %DO I = 1 %TO &NPR.;
       IF PUT(PR&I.,&FMT.) = '1'    AND
          PUT(PR&I.,$ORPROC.) = '1' THEN MPRCNT + 1;
    %END;

 %MEND;

 %MACRO MPRDAY(FMT);

    MPRDAY = .;
    %DO I = 1 %TO &NPR.;
       IF PUT(PR&I.,&FMT.) = '1' AND PRDAY&I. NE . THEN DO;
          IF MPRDAY = . THEN MPRDAY = PRDAY&I;
          ELSE IF MPRDAY > PRDAY&I. THEN MPRDAY = PRDAY&I;
       END;
    %END;

 %MEND;

%MACRO ORCNT;

    ORCNT = 0;
    %DO I = 1 %TO &NPR.;
       IF PUT(PR&I.,$ORPROC.) = '1' THEN ORCNT + 1;
    %END;

%MEND;

%MACRO ORDAY(FMT);

    ORDAY = .;
    %DO I = 1 %TO &NPR.;
       IF PUT(PR&I.,$ORPROC.) = '1' AND
          PUT(PR&I.,&FMT.)    = '0' THEN DO;
          IF PRDAY&I. NE . THEN DO;
             IF ORDAY = . THEN ORDAY = PRDAY&I;
             ELSE IF ORDAY > PRDAY&I. THEN ORDAY = PRDAY&I;
          END;
       END;
    %END;

%MEND;

 * -------------------------------------------------------------- ;
 * --- DEFINE COMORBIDITY CATEGORIES ---------------------------- ;
 * -------------------------------------------------------------- ;

 ATTRIB 
 CHF      LENGTH=3
   LABEL='CONGESTIVE HEART FAILURE'
 VALVE    LENGTH=3
   LABEL='VALVULAR DISEASE'
 PULMCIRC LENGTH=3
   LABEL='PULMONARY CIRCULATION DISEASE'
 PERIVASC LENGTH=3
   LABEL='PERIPHERAL VASCULAR DISEASE'
 HTN_C    LENGTH=3
   LABEL='HYPERTENSION'
 PARA     LENGTH=3
   LABEL='PARALYSIS'
 NEURO    LENGTH=3
   LABEL='OTHER NEUROLOGICAL DISORDERS'
 CHRNLUNG LENGTH=3
   LABEL='CHRONIC PULMONARY DISEASE'
 DM       LENGTH=3
   LABEL='DIABETES'
 DMCX     LENGTH=3
   LABEL='DIABETES W CHRONIC COMPLICATIONS'
 HYPOTHY  LENGTH=3
   LABEL='HYPOTHYROIDISM'
 RENLFAIL LENGTH=3
   LABEL='RENAL FAILURE'
 LIVER    LENGTH=3
   LABEL='LIVER DISEASE'
 ULCER    LENGTH=3
   LABEL='PEPTIC ULCER DISEASE EX BLD WO OBS'
 AIDS     LENGTH=3
   LABEL='ACQUIRED IMMUNE DEFICIENCY SYNDROME'
 LYMPH    LENGTH=3
   LABEL='LYMPHOMA'
 METS     LENGTH=3
   LABEL='METASTATIC CANCER'
 TUMOR    LENGTH=3
   LABEL='SOLID TUMOR WOUT METASTASIS'
 ARTH     LENGTH=3
   LABEL='RHEUMATOID ARTHRITIS COLLAGEN VAS'
 COAG     LENGTH=3
   LABEL='COAGULOPTHY'
 OBESE    LENGTH=3
   LABEL='OBESITY'
 WGHTLOSS LENGTH=3
   LABEL='WEIGHT LOSS'
 LYTES    LENGTH=3
   LABEL='FLUID AND ELECTROLYTE DISORDERS'
 BLDLOSS  LENGTH=3
   LABEL='CHRONIC BLOOD LOSS ANEMIA'
 ANEMDEF  LENGTH=3
   LABEL='DEFICIENCY ANEMIAS'
 ALCOHOL  LENGTH=3
   LABEL='ALCOHOL ABUSE'
 DRUG     LENGTH=3
   LABEL='DRUG ABUSE'
 PSYCH    LENGTH=3
   LABEL='PSYCHOSES'
 DEPRESS  LENGTH=3
   LABEL='DEPRESSION'
;

 LENGTH A1  A2  A3  A4  A5  A6  A7  A8  A9  A10
        A11 A12 A13 A14 A15 A16 A17 A18 A19 A20
        A21 A22 A23 A24 A25 A26 A27 A28 A29 A30
        A31 A32 A33 A34 A35 A36 DXVALUE $8
;

 * ------------------------------------------------------------- ;
 * --- CREATION OF COMORBIDITY VARIABLES                         ;
 * ---                                                           ; 
 * --- Creates comorbidity variables based on the                ; 
 * --- presence of secondary diagnoses and redefines             ; 
 * --- comorbidity group by eliminating DRGs directly            ; 
 * --- related to them.                                          ; 
 * --------------------------------------------------------------; 

 * ------------------------------------------------------------- ;
 * ---  Declare variables as array elements                      ;
 * ------------------------------------------------------------- ;

   ARRAY ARRY1{&NDX.}  DX1 - DX&NDX.;

   ARRAY ARRY2{36}  CHF      VALVE    PULMCIRC PERIVASC HTN      
                    HTNCX    PARA     NEURO    CHRNLUNG DM       
                    DMCX     HYPOTHY  RENLFAIL LIVER    ULCER    
                    AIDS     LYMPH    METS     TUMOR    ARTH     
                    COAG     OBESE    WGHTLOSS LYTES    BLDLOSS  
                    ANEMDEF  ALCOHOL  DRUG     PSYCH    DEPRESS 
                    HTNWCHF  HTNWOCHF HTNWRF   HTNWORF  HTNWHRF 
                    HTNWOHRF ;

   ARRAY ARRY3{36}  A1  A2  A3  A4  A5  A6  A7  A8  A9  A10
                    A11 A12 A13 A14 A15 A16 A17 A18 A19 A20
                    A21 A22 A23 A24 A25 A26 A27 A28 A29 A30
                    A31 A32 A33 A34 A35 A36 ;


 * ------------------------------------------------------------- ;
 * ---  Initialize ARRY2 to 0 and assigns the variable           ;
 * ---  name from ARRY2 as the VALUE of ARRY3                    ;
 * ------------------------------------------------------------- ;

   DO I = 1 TO 36;
      ARRY2(I) = 0;
      CALL VNAME(ARRY2(I),ARRY3(I));
   END;

 * ------------------------------------------------------------- ;
 * ---  Looking at the secondary DXs and using formats,          ;
 * ---  create DXVALUE to define each comorbidity group          ;
 * ---                                                           ;
 * ---  If DXVALUE is equal to the comorbidity name in           ;
 * ---  array ARRY3 then a value of 1 is assigned to the         ;
 * ---  corresponding comorbidity group in array ARRY2           ;
 * ------------------------------------------------------------- ;

   DO I = 2 TO &NDX.;
      DXVALUE = PUT(ARRY1(I),$RCOMFMT.) ;
      DO J = 1 TO 36;
         IF DXVALUE = ARRY3(J) THEN ARRY2(J) = 1;
      END;
   END;

 * ------------------------------------------------------------- ;
 * ---  SET UP CODE TO COUNT HYPERTENSION, COMPLICATED           ;
 * ------------------------------------------------------------- ;

   IF HTNWCHF = 1 THEN DO; CHF = 1; HTNWOCHF = 1; END;
   IF HTNWRF  = 1 THEN DO; RENLFAIL = 1; HTNWORF = 1; END;
   IF HTNWHRF = 1 THEN DO; CHF = 1; RENLFAIL = 1; HTNWOHRF = 1; END;

 * ------------------------------------------------------------- ;
 * ---  SET UP CODE TO ONLY COUNT THE MORE SEVERE COMORBIDITY    ;
 * ------------------------------------------------------------- ;

   IF HTNCX = 1 OR HTNWOCHF = 1 OR HTNWORF = 1 OR HTNWOHRF = 1
      THEN HTN = 0 ;
   IF METS = 1 THEN TUMOR = 0 ;
   IF DMCX = 1 THEN DM = 0;

 * ------------------------------------------------------------- ;
 * ---  EXAMINE DRG AND SET FLAGS TO IDENTIFY A PARTICULAR       ;
 * ---  DRG GROUP                                                ;
 * ------------------------------------------------------------- ;

   IF PUT(DRG,CARDDRG.)  = 'YES' THEN CARDFLG  = 1;
   IF PUT(DRG,PERIDRG.)  = 'YES' THEN PERIFLG  = 1;
   IF PUT(DRG,CEREDRG.)  = 'YES' THEN CEREFLG  = 1;
   IF PUT(DRG,NERVDRG.)  = 'YES' THEN NERVFLG  = 1;
   IF PUT(DRG,PULMDRG.)  = 'YES' THEN PULMFLG  = 1;
   IF PUT(DRG,DIABDRG.)  = 'YES' THEN DIABFLG  = 1;
   IF PUT(DRG,HYPODRG.)  = 'YES' THEN HYPOFLG  = 1;
   IF PUT(DRG,RENALDRG.) = 'YES' THEN RENALFLG = 1;
   IF PUT(DRG,RENFDRG.)  = 'YES' THEN RENFFLG  = 1;
   IF PUT(DRG,LIVERDRG.) = 'YES' THEN LIVERFLG = 1;
   IF PUT(DRG,ULCEDRG.)  = 'YES' THEN ULCEFLG  = 1;
   IF PUT(DRG,HIVDRG.)   = 'YES' THEN HIVFLG   = 1;
   IF PUT(DRG,LEUKDRG.)  = 'YES' THEN LEUKFLG  = 1;
   IF PUT(DRG,CANCDRG.)  = 'YES' THEN CANCFLG  = 1;
   IF PUT(DRG,ARTHDRG.)  = 'YES' THEN ARTHFLG  = 1;
   IF PUT(DRG,NUTRDRG.)  = 'YES' THEN NUTRFLG  = 1;
   IF PUT(DRG,ANEMDRG.)  = 'YES' THEN ANEMFLG  = 1;
   IF PUT(DRG,ALCDRG.)   = 'YES' THEN ALCFLG   = 1;


  * ------------------------------------------------------------- ;
  * ---  REDEFINING COMORBIDITIES BY ELIMINATING THE DRG DIRECTLY ;
  * ---  RELATED TO COMORBIDITY, THUS LIMITING THE SCREENS TO     ;
  * ---  PRINCIPAL DIAGNOSES NOT DIRECTLY RELATED TO COMORBIDITY  ;
  * ---  IN QUESTION                                              ;
  * ------------------------------------------------------------- ;

   IF CHF      AND  CARDFLG  THEN CHF      = 0;
   IF VALVE    AND  CARDFLG  THEN VALVE    = 0;
   IF PULMCIRC AND (CARDFLG OR PULMFLG) 
                             THEN PULMCIRC = 0;
   IF PERIVASC AND  PERIFLG  THEN PERIVASC = 0;
   IF HTN      AND  DRG=134  THEN HTN      = 0;
   IF HTNCX    AND  DRG=134  THEN HTNCX    = 0;
   IF HTNWOCHF AND (CARDFLG OR DRG = 134)
                             THEN HTNWOCHF = 0;
   IF HTNWORF  AND (RENALFLG OR DRG = 134)
                             THEN HTNWORF  = 0;
   IF HTNWOHRF AND (CARDFLG OR RENALFLG OR DRG = 134)
                             THEN HTNWOHRF = 0;
   IF PARA     AND  CEREFLG  THEN PARA     = 0;
   IF NEURO    AND  NERVFLG  THEN NEURO    = 0;
   IF CHRNLUNG AND  PULMFLG  THEN CHRNLUNG = 0;
   IF DM       AND  DIABFLG  THEN DM       = 0;
   IF DMCX     AND  DIABFLG  THEN DMCX     = 0;
   IF HYPOTHY  AND  HYPOFLG  THEN HYPOTHY  = 0;
   IF RENLFAIL AND  RENFFLG  THEN RENLFAIL = 0;
   IF LIVER    AND  LIVERFLG THEN LIVER    = 0;
   IF ULCER    AND  ULCEFLG  THEN ULCER    = 0;
   IF AIDS     AND  HIVFLG   THEN AIDS     = 0;
   IF LYMPH    AND  LEUKFLG  THEN LYMPH    = 0;
   IF METS     AND  CANCFLG  THEN METS     = 0;
   IF TUMOR    AND  CANCFLG  THEN TUMOR    = 0;
   IF ARTH     AND  ARTHFLG  THEN ARTH     = 0;
   IF COAG     AND  DRG=397  THEN COAG     = 0;
   IF OBESE    AND (NUTRFLG OR DRG = 288 ) 
                             THEN OBESE    = 0;
   IF WGHTLOSS AND  NUTRFLG  THEN WGHTLOSS = 0;
   IF LYTES    AND  NUTRFLG  THEN LYTES    = 0;
   IF BLDLOSS  AND  ANEMFLG  THEN BLDLOSS  = 0;
   IF ANEMDEF  AND  ANEMFLG  THEN ANEMDEF  = 0;
   IF ALCOHOL  AND  ALCFLG   THEN ALCOHOL  = 0;
   IF DRUG     AND  ALCFLG   THEN DRUG     = 0;
   IF PSYCH    AND  DRG=430  THEN PSYCH    = 0;
   IF DEPRESS  AND  DRG=426  THEN DEPRESS  = 0;

  * ------------------------------------------------------------- ;
  * --- Combine HTN and HTNCX into HTN_C                          ;
  * ------------------------------------------------------------- ;
   IF HTN=1 OR HTNCX=1 OR HTNWOCHF=1 OR HTNWORF=1 OR HTNWOHRF=1
     THEN HTN_C=1; ELSE HTN_C=0;


 * -------------------------------------------------------------- ;
 * --- DELETE RECORDS WITH MISSING VALUES FOR AGE OR SEX--------- ;
 * -------------------------------------------------------------- ;
 IF SEX LE 0 THEN DELETE;
 IF AGE LT 0 THEN DELETE;

 * -------------------------------------------------------------- ;
 * --- DELETE RECORDS OUTSIDE CONTINENTAL US, AK or HI----------- ;
 * -------------------------------------------------------------- ;
 IF HOSPSTCO > 0 THEN DO;
    IF INT(HOSPSTCO/1000) GT 56 THEN DELETE;
 END;

 * -------------------------------------------------------------- ;
 * --- CONDITIONALLY DEFINE MSAS FROM COUNTY CODES -------------- ;
 * -------------------------------------------------------------- ;
 %CTY2MSA


 * -------------------------------------------------------------- ;
 * --- DEFINE STRATIFIER: PAYER CATEGORY ------------------------ ;
 * -------------------------------------------------------------- ;
 ATTRIB PAYCAT LENGTH=$1
   LABEL='(M)edicar Me(D)icaid (P)riv (S)elf (O)th';

 SELECT (PAY1);
   WHEN (1)  PAYCAT = 'M';
   WHEN (2)  PAYCAT = 'D';
   WHEN (3)  PAYCAT = 'P';
   WHEN (4)  PAYCAT = 'S';
   OTHERWISE PAYCAT = 'O';
 END; * SELECT PAY1 ;

 * -------------------------------------------------------------- ;
 * --- DEFINE STRATIFIER: RACE CATEGORY ------------------------- ;
 * -------------------------------------------------------------- ;
 ATTRIB RACECAT LENGTH=$1
   LABEL='(W)hite (B)lack (H)ispanic (O)ther';

 SELECT (RACE);
   WHEN (1)  RACECAT = 'W';
   WHEN (2)  RACECAT = 'B';
   WHEN (3)  RACECAT = 'H';
   OTHERWISE RACECAT = 'O';
 END; * SELECT RACE ;

 * -------------------------------------------------------------- ;
 * --- DEFINE STRATIFIER: AGE CATEGORY  ------------------------- ;
 * -------------------------------------------------------------- ;
 ATTRIB AGECAT LENGTH=$1
   LABEL='(1)0-17 (2)18-39 (3)40-64 (4)65+';

 SELECT;
   WHEN (0  <= AGE < 18)  AGECAT = '1';
   WHEN (18 <= AGE < 40)  AGECAT = '2';
   WHEN (40 <= AGE < 65)  AGECAT = '3';
   WHEN (65 <= AGE     )  AGECAT = '4';
 END; * SELECT AGE ;

 * -------------------------------------------------------------- ;
 * --- DEFINE STRATIFIER: SEX CATEGORY  ------------------------- ;
 * -------------------------------------------------------------- ;
 ATTRIB SEXCAT LENGTH=$1
   LABEL='(M)ale (F)emale';

 SELECT (SEX);
   WHEN (1)  SEXCAT = 'M';
   WHEN (2)  SEXCAT = 'F';
 END; * SELECT SEX ;

 * -------------------------------------------------------------- ;
 * --- COUNT OR PROCEDURES AND IDENTIFY FIRST OR PROCEDURE ------ ;
 * -------------------------------------------------------------- ;
 ATTRIB ORCNT LENGTH=8
   LABEL='OR PROCEDURE COUNT';

 ATTRIB ORDAY LENGTH=8
   LABEL='OR PROCEDURE DAY';

%ORCNT;

 * -------------------------------------------------------------- ;
 * --- DEFINE PROVIDER LEVEL INDICATORS ------------------------- ;
 * -------------------------------------------------------------- ;

 %MACRO LBL;

 ATTRIB
 TPPS01 LENGTH=3
   LABEL='COMPLICATIONS OF ANESTHESIA (Numerator)'
 TPPS02 LENGTH=3
   LABEL='DEATH IN LOW MORTALITY DRGS (Numerator)'
 TPPS02A LENGTH=3
   LABEL='DEATH IN LMD - ADULT MEDICAL (Numerator)'
 TPPS02B LENGTH=3
   LABEL='DEATH IN LMD - PED MEDICAL (Numerator)'
 TPPS02C LENGTH=3
   LABEL='DEATH IN LMD - ADULT SURG W/O OR (Num)'
 TPPS02D LENGTH=3
   LABEL='DEATH IN LMD - ADULT SURG W OR (Num)'
 TPPS02E LENGTH=3
   LABEL='DEATH IN LMD - PED SURG W/O OR (Num)'
 TPPS02F LENGTH=3
   LABEL='DEATH IN LMD - PED SURG W OR (Numerator)'
 TPPS02G LENGTH=3
   LABEL='DEATH IN LMD - OBSTETRIC (Numerator)'
 TPPS02H LENGTH=3
   LABEL='DEATH IN LMD - PSYCHIATRIC (Numerator)'
 TPPS03 LENGTH=3
   LABEL='DECUBITUS ULCER (Numerator)'
 TPPS04 LENGTH=3
   LABEL='FAILURE TO RESCUE (Numerator)'
 TPPS05 LENGTH=3
   LABEL='FOREIGN BODY LEFT IN DURING PROC (Num)'
 TPPS06 LENGTH=3
   LABEL='IATROGENIC PNEUMOTHORAX (Numerator)'
 TPPS07 LENGTH=3
   LABEL='INFECTION DUE TO MEDICAL CARE (Num)'
 TPPS08 LENGTH=3
   LABEL='POSTOPERATIVE HIP FRACTURE (Numerator)'
 TPPS09 LENGTH=3
   LABEL='POSTOP HEMORRHAGE OR HEMATOMA (Num)'
 TPPS10 LENGTH=3
   LABEL='POSTOP PHYSIO METABOL DERANGEMENT (Num)'
 TPPS11 LENGTH=3
   LABEL='POSTOP RESPIRATORY FAILURE (Numerator)'
 TPPS12 LENGTH=3
   LABEL='POSTOPERATIVE PE OR DVT (Numerator)'
 TPPS13 LENGTH=3
   LABEL='POSTOPERATIVE SEPSIS (Numerator)'
 TPPS14 LENGTH=3
   LABEL='POSTOPERATIVE WOUND DEHISCENCE (Num)'
 TPPS15 LENGTH=3
   LABEL='ACCIDENTAL PUNCTURE/LACERATION(Num)'
 TPPS16 LENGTH=3
   LABEL='TRANSFUSION REACTION (Numerator)'
 TPPS17 LENGTH=3
   LABEL='BIRTH TRAUMA -INJURY TO NEONATE(Num)'
 TPPS18 LENGTH=3
   LABEL='OB TRAUMA - VAGINAL W INSTRUMENT (Num)'
 TPPS19 LENGTH=3
   LABEL='OB TRAUMA - VAGINAL W/O INSTRUMENT (Num)'
 TPPS20 LENGTH=3
   LABEL='OB TRAUMA - C-SECTION (Numerator)'
 TPPS27 LENGTH=3
   LABEL='OB TRAUMA W 3 DEG - VAGINAL W INST (Num)'
 TPPS28 LENGTH=3
   LABEL='OB TRAUMA W 3 DEG - VAGINAL WO INST (Num)'
 TPPS29 LENGTH=3
   LABEL='OB TRAUMA W 3 DEG - C-SECTION (Num)';

 * -------------------------------------------------------------- ;
 * --- DEFINE AREA LEVEL INDICATORS ----------------------------- ;
 * -------------------------------------------------------------- ;
 ATTRIB
 TAPS21 LENGTH=3
   LABEL='FOREIGN BODY LEFT IN DURING PROC (Area Num)'
 TAPS22 LENGTH=3
   LABEL='IATROGENIC PNEUMOTHORAX (Area Numerator)'
 TAPS23 LENGTH=3
   LABEL='INFECTION DUE TO MEDICAL CARE (Area Num)'
 TAPS24 LENGTH=3
   LABEL='POSTOPERATIVE WOUND DEHISCENCE (Area Num)'
 TAPS25 LENGTH=3
   LABEL='ACCIDENTAL PUNCTURE/LACERATION(Area Num)'
 TAPS26 LENGTH=3
   LABEL='TRANSFUSION REACTION (Area Numerator)'
;

 * -------------------------------------------------------------- ;
 * --- RE-LABEL DAY DEPENDENT INDICATORS ------------------------ ;
 * -------------------------------------------------------------- ;
 %IF &PRDAY. = 0 %THEN %DO;
 LABEL
   TPPS08 = 'POSTOP HIP FRACTURE-NO PRDAY (Num)'
   TPPS09 = 'POSTOP HEMOR OR HEMAT-NO PRDAY (Num)'
   TPPS10 = 'POSTOP PHYSIO METABO DE-NO PRDAY (Num)'
   TPPS11 = 'POSTOP RESP FAILURE-NO PRDAY (Numerator)'
   TPPS12 = 'POSTOP PE OR DVT-NO PRDAY    (Numerator)'
   TPPS14 = 'POSTOP WOUND DEHISCENCE-NO PRDAY (Num)'
 ;
 %END;

 %MEND;

 %LBL;


 * -------------------------------------------------------------- ;
 * --- CONSTRUCT PROVIDER LEVEL INDICATORS ---------------------- ;
 * -------------------------------------------------------------- ;

   * --- COMPLICATIONS OF ANESTHESIA                          --- ;

   IF %MDR($SURGIDR.) AND ORCNT > 0 THEN DO;

      TPPS01 = 0;

      IF %MDX2($ANES1ID.) OR %MDX2($ANES2ID.) THEN TPPS01 = 1;

      *** Exclude principal diagnosis; 
    
      IF %MDX1($ANES1ID.) OR %MDX1($ANES2ID.) THEN TPPS01 = .;

      *** Exclude Active Drug Dependence, Active nondependent abuse
          of drugs, and self-inflicted injury;

      IF %MDX2($ANES1ID.) AND 
         (%MDX($ADRUGID.) OR %MDX($ANONDID.) OR %MDX($SELFIID.))
      THEN TPPS01 = .;

   END;

   * --- DEATH IN LOW MORTALITY DRGS                          --- ;

   IF %MDR($LOWMODR.) THEN DO;

      TPPS02 = 0;

      IF DISP IN (20) THEN TPPS02 = 1;
 
      *** Exclude Trauma, Immunocompomised state, and cancer;

      IF %MDX($TRAUMID.) OR %MDX($IMMUNID.) OR 
         %MPR($IMMUNIP.) OR %MDX($CANCEID.) 
      THEN TPPS02 = .;

      SELECT (PUT(PUT(DRG,Z3.),$LOWM2DR.));
        WHEN ('M')  TPPS02A = TPPS02;
        WHEN ('PM') TPPS02B = TPPS02;
        WHEN ('S')  TPPS02C = TPPS02;
        WHEN ('PS') TPPS02E = TPPS02;
        WHEN ('O')  TPPS02G = TPPS02;
        WHEN ('Y')  TPPS02H = TPPS02;
      END; * SELECT DRG ;

      IF ORCNT > 0 THEN DO;
         TPPS02D = TPPS02C; TPPS02C = .;
         TPPS02F = TPPS02E; TPPS02E = .;
      END; 

   END;

   * --- DECUBITUS ULCER                                      --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TPPS03 = 0;
     
      IF %MDX2($DECUBID.) THEN TPPS03 = 1;
 
      *** Exclude principal diagnosis; 

      IF %MDX1($DECUBID.) THEN TPPS03 = .;

      *** Exclude Hemiplegia, Paraplagia, Quadriplagia;

      IF %MDX($HEMIPID.) THEN TPPS03 = .;

      *** Exclude MDC 9 and 14;

      IF MDC IN (9, 14) THEN TPPS03 = .;

      *** Exclude LOS < 5, Admitted from LTC;

      IF LOS < 5 OR ASOURCE IN (3) THEN TPPS03 = .;

   END;

   * --- FAILURE TO RESCUE                                    --- ;

   IF (%MDX2($FTR1DX.) AND
       NOT (%MDX1($FTR1DX.) OR %MDX1($FTR1EX.) OR %MDX1($AMIID.) OR %MDX1($CARDRID.) OR 
            %MDX1($CARDIID.) OR %MDX1($HEMORID.) OR %MDX1($GASTRID.) OR %MDX1($SHOCKID.) OR 
            %MDX1($TRAUMID.) OR %MDR($TRAUMDR.))) 
      OR
      (%MDX2($FTR2DX.) AND 
       NOT (%MDX1($FTR2DX.) OR %MDX1($OBEMBOL.)))
      OR
      (%MDX2($FTR3DX.) AND 
       NOT (%MDX1($FTR3DX.) OR %MDX1($FTR3EXA.) OR %MDX($FTR3EXB.) OR %MDX($IMMUNID.) OR 
            %MPR($IMMUNIP.) OR MDC IN (4)))
      OR
      (%MDX2($FTR4DX.) AND 
       NOT (%MDX1($FTR4DX.) OR %MDX($IMMUNID.) OR %MPR($IMMUNIP.) OR
            %MDX1($INFECID.) OR %MDR($INFECDR.) OR LOS < 4))
      OR
      ((%MDX2($FTR5DX.) OR %MPR($FTR5PR.)) AND 
       NOT (%MDX1($FTR5DX.) OR %MDX1($FTR5EX.) OR %MDX1($HEMORID.) OR %MDX1($TRAUMID.) OR 
            %MDR($TRAUMDR.) OR %MDX1($GASTRID.) OR MDC IN (4,5)))
      OR
      (%MDX2($FTR6DX.) AND 
       NOT (%MDX1($FTR6DX.) OR %MDX1($FTR6EX.) OR %MDX1($TRAUMID.) OR %MDR($TRAUMDR.) OR
            %MDX1($ALCHLSM.) OR MDC IN (6,7)))
   THEN DO;

      TPPS04 = 0;

      IF DISP IN (20) THEN TPPS04 = 1;

      *** Exclude Age GE 75 or Transfers from an acute care or LTC facility
          or Transferred to an acute care facility or MDC 15;

      IF AGE >= 75 OR ASOURCE IN (2,3) OR DISP IN (2) OR MDC IN (15) THEN TPPS04 = .;

   END;

   * --- FOREIGN BODY LEFT IN DURING PROCEDURE                --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TPPS05 = 0;

      IF %MDX2($FOREIID.) THEN TPPS05 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($FOREIID.) THEN TPPS05 = .;

   END;

   * --- IATROGENIC PNEUMOTHORAX                              --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TPPS06 = 0;

      IF %MDX2($IATROID.) THEN TPPS06 = 1;
   
      *** Exclude principal diagnosis; 

      IF %MDX1($IATROID.) THEN TPPS06 = .;

      *** Exclude Trauma, Thoracic surgery, Lung or pleural biopsy,
          or Cardiac surgery or MDC 14;

      IF %MDX($TRAUMID.) OR %MDR($TRAUMDR.) OR %MPR($THORAIP.) OR
         %MPR($LUNGBIP.) OR %MDR($CARDSDR.) OR MDC IN (14)
      THEN TPPS06 = .;

   END;

   * --- INFECTION DUE TO MEDICAL CARE                        --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TPPS07 = 0;

      IF %MDX2($IDTMCID.) THEN TPPS07 = 1;
 
      *** Exclude principal diagnosis; 

      IF %MDX1($IDTMCID.) THEN TPPS07 = .;

      *** Exclude Immunocompromised state and Cancer;

      IF %MDX($IMMUNID.) OR %MPR($IMMUNIP.) OR
         %MDX($CANCEID.) OR %MDR($CANCEDR.) 
      THEN TPPS07 = .;
 
   END;

   * --- POSTOPERATIVE HIP FRACTURE                           --- ;

 %MACRO PS8;

 IF (&PRDAY. = 1  AND ORDAY NE . AND MPRDAY NE .) THEN DO;

      IF MPRDAY < ORDAY THEN TPPS08 = .;

 END;
 ELSE DO;

      IF %MPR1($HIPFXIP.) THEN TPPS08 = .;

 END;

 %MEND;

   IF %MDR($SURGIDR.) AND ORCNT > 0 AND AGE >= 18 THEN DO;

      TPPS08 = 0;
  
      IF %MDX2($HIPFXID.) THEN TPPS08 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($HIPFXID.) THEN TPPS08 = .;

      *** Exclude if hip fracture repair or a related procedure is 
          the only OR procedure;
      %MPRCNT($HIPFXIP.);
      IF ORCNT = MPRCNT THEN TPPS08 = .;

      *** Exclude if hip fracture repair or a related procedure 
          occurs before the first OR procedure;
      %ORDAY($HIPFXIP.);
      %MPRDAY($HIPFXIP.);
      %PS8;

      *** Excludes Seizure, Syncope, Stroke, Coma, Cardiac arrest,
          Poisoning, Trauma, Delirium and other psychoses, Anoxic
          brain injury;

      IF %MDX1($SEIZUID.) OR %MDX1($SYNCOID.) OR %MDX1($STROKID.) OR
         %MDX1($COMAID.)  OR %MDX1($CARDIID.) OR %MDX1($POISOID.) OR
         %MDX1($TRAUMID.) OR %MDR($TRAUMDR.)  OR %MDX1($DELIRID.) OR
         %MDX1($ANOXIID.)
      THEN TPPS08 = .;

      *** Excludes Metastatic cancer, Lymphoid malignancy, 
          Bone malignancy, Self-inflicted injury;
 
      IF %MDX($METACID.) OR %MDX($LYMPHID.) OR %MDX($BONEMID.) OR
         %MDX($SELFIID.)
      THEN TPPS08 = .;

      *** Exclude MDC 8 and 14;

      IF MDC IN (8, 14) THEN TPPS08 = .;

   END;

   * --- POSTOPERATIVE HEMORRHAGE OR HEMATOMA                 --- ;

 %MACRO PS9;

 IF (&PRDAY. = 1 AND ORDAY NE . AND (MPRDAYA NE . OR MPRDAYB NE .)) THEN DO;

      IF (%MDX2($POHMAID.) AND MPRDAYA NE . AND MPRDAYA < ORDAY) OR
         (%MDX2($POHMRID.) AND MPRDAYB NE . AND MPRDAYB < ORDAY) 
      THEN TPPS09 = .;

 END;
 ELSE DO;

      IF (%MDX2($POHMAID.) AND %MPR1($HEMATIP.)) OR 
         (%MDX2($POHMRID.) AND %MPR1($HEMORIP.)) 
      THEN TPPS09 = .;

 END;

 %MEND;

   IF %MDR($SURGIDR.) AND ORCNT > 0 THEN DO;

      TPPS09 = 0;

      IF (%MDX2($POHMAID.) AND %MPR($HEMATIP.)) OR 
         (%MDX2($POHMRID.) AND %MPR($HEMORIP.)) 
      THEN TPPS09 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($POHMAID.) OR %MDX1($POHMRID.) THEN TPPS09 = .;

      *** Exclude if control of post-operative hemorrhage or
          hematoma are the only OR procedures;
      %MPRCNT($HEMIP.);
      IF ORCNT = MPRCNT THEN TPPS09 = .;

      *** Exclude if control of post-operative hemorrhage or
          hematoma occurs before the first OR procedure;
      %ORDAY($HEMIP.);
      %MPRDAY($HEMATIP.); MPRDAYA = MPRDAY;
      %MPRDAY($HEMORIP.); MPRDAYB = MPRDAY;
      %PS9;

      *** Exclude MDC 14;

      IF MDC IN (14) THEN TPPS09 = .;

   END;

   * --- POSTOPERATIVE PHYSIOLOGIC AND METABOLIC DERANGEMENTS --- ;

 %MACRO PS10;

 IF (&PRDAY. = 1  AND ORDAY NE . AND MPRDAY NE .) THEN DO;

      IF %MDX2($PHYSIDB.) AND MPRDAY <= ORDAY THEN TPPS10 = .;

 END;
 ELSE DO;

      IF %MDX2($PHYSIDB.) AND %MPR1($DIALYIP.) THEN TPPS10 = .;

 END;

 %MEND;

   IF %MDR($SURGIDR.) AND ORCNT > 0 AND ATYPE IN (3) THEN DO;

      TPPS10 = 0;

      IF %MDX2($PHYSIDA.) OR (%MDX2($PHYSIDB.) AND %MPR($DIALYIP.))
      THEN TPPS10 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($PHYSIDA.) OR %MDX1($PHYSIDB.) THEN TPPS10 = .;

      *** Exclude if dialysis procedure occurs before or on the same
          day as the first OR procedure;
      %ORDAY($DIALYIP.);
      %MPRDAY($DIALYIP.);
      %PS10;

      *** Exclude Ketoacidosis, Hyperosmolarity or other Coma and
          Diabetes;

      IF %MDX2($PHYSIDA.) AND %MDX1($DIABEID.) THEN TPPS10 = .;

      *** Exclude Acute renal failure and AMI, Cardiac arrhythmia,
          Cardiac arrest, Shock, Hemorrhage, or Gastrointestinal
          hemorrhage;

      IF %MDX2($PHYSIDB.) AND (%MDX1($AMIID.) OR %MDX1($CARDRID.) OR
         %MDR($CARDRDR.) OR %MDX1($CARDIID.) OR %MDX1($SHOCKID.) OR
         %MDX1($HEMORID.) OR %MDX1($GASTRID.))
      THEN TPPS10 = .;

      *** Exclude MDC 14;

      IF MDC IN (14) THEN TPPS10 = .;

   END;

   * --- POSTOPERATIVE RESPIRATORY FAILURE                    --- ;

 %MACRO PS11;

 IF (&PRDAY. = 1  AND ORDAY NE . AND MPRDAY NE .) THEN DO;

      IF MPRDAY < ORDAY THEN TPPS11 = .;

 END;
 ELSE DO;

      IF %MPR1($TRACHIP.) THEN TPPS11 = .;

 END;

 %MEND;

   IF %MDR($SURGIDR.) AND ORCNT > 0 AND ATYPE IN (3) THEN DO;

      TPPS11 = 0;

      IF %MDX2($ACURFID.) THEN TPPS11 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($ACURFID.) THEN TPPS11 = .;

      *** Exclude if tracheostomy procedure is the only OR procedure;
      %MPRCNT($TRACHIP.);
      IF ORCNT = MPRCNT THEN TPPS11 = .;

      *** Exclude if tracheostomy procedure occurs before the 
          first OR procedure;
      %ORDAY($TRACHIP.);
      %MPRDAY($TRACHIP.);
      %PS11;

      *** Exclude MDC 4, 5, 14;
 
      IF MDC IN (4,5,14) THEN TPPS11 = .;

   END;

   * --- POSTOPERATIVE PE OR DVT                              --- ;

 %MACRO PS12;

 IF (&PRDAY. = 1  AND ORDAY NE . AND MPRDAY NE .) THEN DO;

      IF MPRDAY <= ORDAY THEN TPPS12 = .;

 END;
 ELSE DO;

      IF %MPR1($VENACIP.) THEN TPPS12 = .;

 END;

 %MEND;

   IF %MDR($SURGIDR.) AND ORCNT > 0 THEN DO;

      TPPS12 = 0;

      IF %MDX2($DEEPVID.) OR %MDX2($PULMOID.) THEN TPPS12 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($DEEPVID.) OR %MDX1($PULMOID.) THEN TPPS12 = .;

      *** Exclude if Interruption of vena cava the only OR procedure;
      %MPRCNT($VENACIP.);
      IF ORCNT = MPRCNT THEN TPPS12 = .;

      *** Exclude if interruption of vena cava occurs before or on the
          same day as the first OR procedure;;

      %ORDAY($VENACIP.);
      %MPRDAY($VENACIP.);
      %PS12;

     *** Exclude MDC 14;

      IF MDC IN (14) THEN TPPS12 = .;

   END;

   * --- POSTOPERATIVE SEPSIS                                 --- ;

   IF %MDR($SURGIDR.) AND ORCNT > 0 AND ATYPE IN (3) THEN DO;

      TPPS13 = 0;

      IF %MDX2($SEPTIID.) THEN TPPS13 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($SEPTIID.) THEN TPPS13 = .;

      *** Exclude Infection, Immunocompromised or Cancer;

      IF %MDX1($INFECID.) OR %MDR($INFECDR.) OR 
         %MDX($IMMUNID.)  OR %MPR($IMMUNIP.) OR 
         %MDX($CANCEID.)  OR %MDR($CANCEDR.)
      THEN TPPS13 = .;

      *** Exclude Length of stay less then 4 days;

      IF LOS < 4 THEN TPPS13 = .;

      *** Exclude MDC 14;

      IF MDC IN (14) THEN TPPS13 = .;

   END;

   * --- POSTOPERATIVE WOUND DEHISCENCE                       --- ;

 %MACRO PS14;

 IF (&PRDAY. = 1 AND MPRDAYA NE . AND MPRDAYB NE .) THEN DO;

      IF MPRDAYB <= MPRDAYA THEN TPPS14 = .;

 END;
 ELSE DO;

      IF %MPR1($RECLOIP.) THEN TPPS14 = .;

 END;

 %MEND;
 %MACRO PS14B;

  %IF &YEARQTR = 1 %THEN %DO;

   IF ((YEAR < 2004 OR (YEAR = 2004 AND DQTR IN (1,2,3))) AND %MPR($ABDOMIP.)) OR
      ((YEAR > 2004 OR (YEAR = 2004 AND DQTR IN (4)))     AND (%MPR($ABDOMIP.) OR %MPR($ABDOM2P.))) 
   THEN DO;

  %END;
  %ELSE %DO;

   IF %MPR($ABDOMIP.) THEN DO;

  %END;

      TPPS14 = 0;

      IF %MPR($RECLOIP.) THEN TPPS14 = 1;

      *** Exclude if wound reclosure occurs before or on the same
          day as the first abdominopelvic procedure;;

      %MPRDAY($ABDOMIP.); MPRDAYA = MPRDAY;
      %MPRDAY($RECLOIP.); MPRDAYB = MPRDAY;
      %PS14;

     *** Exclude MDC 14;

      IF MDC IN (14) THEN TPPS14 = .;

   END;
 %MEND PS14B;
 %PS14B;

   * --- ACCIDENTAL PUNCTURE OR LACERATION                    --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TPPS15 = 0;

      IF %MDX2($TECHNID.) THEN TPPS15 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($TECHNID.) THEN TPPS15 = .;

      *** Exclude MDC 14;

      IF MDC IN (14) THEN TPPS15 = .;

   END;

   * --- TRANSFUSION REACTION                                 --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TPPS16 = 0;
 
      IF %MDX2($TRANFID.) THEN TPPS16 = 1;

      *** Exclude principal diagnosis; 

      IF %MDX1($TRANFID.) THEN TPPS16 = .;

   END;

   * --- BIRTH TRAUMA                                         --- ;

   IF (%MDX($LIVEBID.) OR %MDR($LIVEBDR.)) AND ATYPE IN (4) THEN DO;

      TPPS17 = 0;

      *** Exclude Subdural or cerebral hemorrhage if preterm;

      IF %MDX($BIRTIDA.) AND NOT %MDX($PRETEID.) THEN TPPS17 = 1;

      *** Exclude Injury to skeleton if osteogenesis imperfecta;

      IF %MDX($BIRTIDB.) AND NOT %MDX($OSTEOID.) THEN TPPS17 = 1;

      IF %MDX($BIRTIDC.) THEN TPPS17 = 1;

   END;

   * --- OB TRAUMA - VAGINAL WITH INSTRUMENTATION             --- ;

   IF %MDR($VAGINDR.) AND %MPR($INSTRIP.) THEN DO;

      TPPS18 = 0;
      TPPS27 = 0;

      IF %MDX($OBTRAID.) OR %MPR($OBTRAIP.) THEN TPPS18 = 1;
      IF %MDX($OBTRIDB.) OR %MPR($OBTRAIP.) THEN TPPS27 = 1;

   END;

   * --- OB TRAUMA - VAGINAL WITHOUT INSTRUMENTATION          --- ;

   IF %MDR($VAGINDR.) AND NOT %MPR($INSTRIP.) THEN DO;

      TPPS19 = 0;
      TPPS28 = 0;

      IF %MDX($OBTRAID.) OR %MPR($OBTRAIP.) THEN TPPS19 = 1;
      IF %MDX($OBTRIDB.) OR %MPR($OBTRAIP.) THEN TPPS28 = 1;

   END;

   * --- OB TRAUMA - C-SECTION                                --- ;

   IF %MDR($CESARDR.) THEN DO;

      TPPS20 = 0;
      TPPS29 = 0;

      IF %MDX($OBTRAID.) OR %MPR($OBTRAIP.) THEN TPPS20 = 1;
      IF %MDX($OBTRIDB.) OR %MPR($OBTRAIP.) THEN TPPS29 = 1;

   END;



 * -------------------------------------------------------------- ;
 * --- CONSTRUCT AREA LEVEL INDICATORS -------------------------- ;
 * -------------------------------------------------------------- ;

   * --- FOREIGN BODY LEFT IN DURING PROCEDURE                --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TAPS21 = 0;

      IF %MDX($FOREIID.) THEN TAPS21 = 1;

   END;

   * --- IATROGENIC PNEUMOTHORAX                              --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TAPS22 = 0;

      IF %MDX($IATROID.) THEN TAPS22 = 1;
   
      *** Exclude Trauma, Thoracic surgery, Lung or pleural biopsy,
          or Cardiac surgery;

      IF %MDX($TRAUMID.) OR %MDR($TRAUMDR.) OR %MPR($THORAIP.) OR
         %MPR($LUNGBIP.) OR %MDR($CARDSDR.)
      THEN TAPS22 = .;

      *** Exclude MDC 14;

      IF MDC EQ 14 THEN TAPS22 = .;
      
   END;

   * --- INFECTION DUE TO MEDICAL CARE                        --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TAPS23 = 0;

      IF %MDX($IDTMCID.) THEN TAPS23 = 1;
 
      *** Exclude Immunocompromised state and Cancer;
 
      IF %MDX($IMMUNID.) OR %MPR($IMMUNIP.) OR
         %MDX($CANCEID.) OR %MDR($CANCEDR.) 
      THEN TAPS23 = .;

   END;

   * --- POSTOPERATIVE WOUND DEHISCENCE                       --- ;

      TAPS24 = 0;

      IF %MPR($RECLOIP.) THEN TAPS24 = 1;

      *** Exclude MDC 14;

      IF MDC EQ 14 THEN TAPS24 = .;


   * --- ACCIDENTAL PUNCTURE OR LACERATION                    --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TAPS25 = 0;

      IF %MDX($TECHNID.) THEN TAPS25 = 1;

      *** Exclude MDC 14;

      IF MDC IN (14) THEN TAPS25 = .;

   END;

   * --- TRANSFUSION REACTION                                 --- ;

   IF %MDR($MEDICDR.) OR %MDR($SURGIDR.) THEN DO;

      TAPS26 = 0;
 
      IF %MDX($TRANFID.) THEN TAPS26 = 1;

   END;
RUN;


PROC MEANS DATA=OUT1.&OUTFILE1. N NMISS MIN MAX MEAN SUM;
RUN;

PROC CONTENTS DATA=OUT1.&OUTFILE1. POSITION;
RUN;

PROC PRINT DATA=OUT1.&OUTFILE1. (OBS=24);
TITLE4 "FIRST 24 RECORDS IN OUTPUT DATA SET &OUTFILE1.";
RUN;
