*=================================================================;
*  Title:  PROGRAM 1  ASSIGN AHRQ INPATIENT QUALITY INDICATORS
*          TO INPATIENT RECORDS
*
*  Description:;
*         ASSIGNS THE OUTCOME OF INTEREST AND POPULATION AT RISK
*         INDICATORS TO INPATIENT RECORDS;
*
*          >>>  VERSION 2.1 (revision 3), July 2004 <<<
*
*  USER NOTE:  Make sure you have created the format library
*              using IQFMTS.SAS BEFORE running this program.
*
*=================================================================;
FILENAME CONTROL 'c:\pathname\CONTROL_IQI.SAS';  *<===USER MUST modify;

%INCLUDE CONTROL;

OPTIONS COMPRESS=YES;

 TITLE2 'PROGRAM 1';
 TITLE3 'AHRQ INPATIENT QUALITY INDICATORS: ASSIGN QIS TO INPATIENT DATA';

 * -------------------------------------------------------------- ;
 * --- INPATIENT QUALITY INDICATOR (IQI) NAMING CONVENTION:   --- ;
 * --- THE FIRST LETTER IDENTIFIES THE INPATIENT QUALITY      --- ;
 * --- 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 IQI AS A PROVIDER (P) --- ;
 * --- OR AN AREA (A) LEVEL INDICATOR.  THE                   --- ;
 * --- NEXT TWO CHARACTERS ARE ALWAYS 'IQ'. THE LAST TWO      --- ;
 * --- DIGITS ARE THE INDICATOR NUMBER (WITHIN THAT SUBTYPE). --- ;
 * -------------------------------------------------------------- ;

 %MACRO INPUTDSN;

 %IF &APRDRGFG = 1 %THEN %DO; *INCLUDES APR_DRG-RELATED VARIABLES;

DATA INPUTDSN;
 SET IN1.&infile1.
                 (KEEP=KEY DRG MDC SEX AGE AGEDAY HOSPSTCO
                       PAY1 HOSPID DISP ASOURCE RACE
                       DX1-DX&NDX. 
                       PR1-PR&NPR. &APRDRG &SEVERE &MORTAL);
  %END;

  %ELSE %DO;

DATA INPUTDSN;
 SET IN1.&infile1.
                 (KEEP=KEY DRG MDC SEX AGE AGEDAY HOSPSTCO
                       PAY1 HOSPID DISP ASOURCE RACE
                       DX1-DX&NDX. 
                       PR1-PR&NPR.);
  %END;
  %MEND INPUTDSN;

  %INPUTDSN
  run;

DATA OUT1.&outfile1.
                                (DROP=DISP PAY1 RACE SEX
                                      DX1-DX&NDX. PR1-PR&NPR.
                                      MPR1P MDX2D MDX3D
                                      MDX4D MPR3AP MPR3BP MPR3CP
                                      MPR3DP MPR3EP MPR3FP MPR4P
                                      MPR5P MPR6P MPR7P PDA);
  SET INPUTDSN;

 * -------------------------------------------------------------- ;
 * --- AREA, DIAGNOSIS AND PROCEDURE MACROS --------------------- ;
 * -------------------------------------------------------------- ;

 %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 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 MPR(FMT);

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

 %MEND;

 %MACRO PRPDCNT1;

    MPR1P = 0; MDX2D = 0; MDX3D = 0; MDX4D = 0; 

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

    %DO I = 1 %TO &NDX.;
       IF PUT(DX&I.,$PRPED2D.) = '1' THEN MDX2D + 1;
       IF PUT(DX&I.,$PRPED3D.) = '1' THEN MDX3D + 1;
       IF PUT(DX&I.,$PRPED4D.) = '1' THEN MDX4D + 1;
    %END;

 %MEND;

 %MACRO PRPDCNT2;

    MPR3AP = 0; MPR3BP = 0; MPR3CP = 0; MPR3DP = 0; 
    MPR3EP = 0; MPR3FP = 0; MPR4P = 0;  MPR5P = 0;  
    MPR6P = 0;  MPR7P = 0;

    %DO I = 1 %TO &NPR.;
       IF (MPR1P > 0 OR MDX2D > 0) AND PUT(PR&I.,$PRPED2P.) = '1' 
       THEN MPR1P + 1;
       IF PUT(PR&I.,$PRPD3AP.) = '1' 
       THEN MPR3AP + 1;
       IF PUT(PR&I.,$PRPD3BP.) = '1' 
       THEN MPR3BP + 1;
       IF PUT(PR&I.,$PRPD3CP.) = '1' 
       THEN MPR3CP + 1;
       IF PUT(PR&I.,$PRPD3DP.) = '1' 
       THEN MPR3DP + 1;
       IF PUT(PR&I.,$PRPD3EP.) = '1' 
       THEN MPR3EP + 1;
       IF PUT(PR&I.,$PRPD3FP.) = '1' 
       THEN MPR3FP + 1;
       IF PUT(PR&I.,$PRPED4P.) = '1' 
       THEN MPR4P + 1;      
       IF PUT(PR&I.,$PRPED5P.) = '1' 
       THEN MPR5P + 1;      
       IF PUT(PR&I.,$PRPED6P.) = '1' 
       THEN MPR6P + 1;
       IF PUT(PR&I.,$PRPED7P.) = '1' 
       THEN MPR7P + 1;
   %END;

 %MEND;


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

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

 * -------------------------------------------------------------- ;
 * --- DEFINE PROVIDER LEVEL VOLUME INDICATORS ------------------ ;
 * -------------------------------------------------------------- ;
 ATTRIB
 TPIQ01 LENGTH=3
   LABEL='VOLUME ESOPHAGEAL RESECTION  (Numerator)'
 TPIQ02 LENGTH=3
   LABEL='VOLUME PANCREATIC RESECTION  (Numerator)'
 TPIQ03 LENGTH=3
   LABEL='VOLUME PEDIATRIC HEART SURGERY (Numertr)'
 TPIQ04 LENGTH=3
   LABEL='VOLUME AAA REPAIR            (Numerator)'
 TPIQ05 LENGTH=3
   LABEL='VOLUME CABG                  (Numerator)'
 TPIQ06 LENGTH=3
   LABEL='VOLUME PTCA                  (Numerator)'
 TPIQ07 LENGTH=3
   LABEL='VOLUME CAROTID ENDARTERECTOMY (Numeratr)'
;

 * -------------------------------------------------------------- ;
 * --- DEFINE PROVIDER LEVEL MORTALITY INDICATORS --------------- ;
 * -------------------------------------------------------------- ;
 ATTRIB
 TPIQ08 LENGTH=3
   LABEL='IN-HOSP MORT ESOPHAGEAL RESECTION  (Num)'
 TPIQ09 LENGTH=3
   LABEL='IN-HOSP MORT PANCREATIC RESECTION  (Num)'
 TPIQ10 LENGTH=3
   LABEL='IN-HOSP MORT PEDIATRIC HEART SURG  (Num)'
 TPIQ11 LENGTH=3
   LABEL='IN-HOSP MORT AAA REPAIR      (Numerator)'
 TPIQ12 LENGTH=3
   LABEL='IN-HOSP MORT CABG            (Numerator)'
 TPIQ13 LENGTH=3
   LABEL='IN-HOSP MORT CRANIOTOMY      (Numerator)'
 TPIQ14 LENGTH=3
   LABEL='IN-HOSP MORT HIP REPLACEMENT (Numerator)'
;

 ATTRIB
 TPIQ15 LENGTH=3
   LABEL='IN-HOSP MORT AMI             (Numerator)'
 TPIQ16 LENGTH=3
   LABEL='IN-HOSP MORT CHF             (Numerator)'
 TPIQ17 LENGTH=3
   LABEL='IN-HOSP MORT STROKE          (Numerator)'
 TPIQ18 LENGTH=3
   LABEL='IN-HOSP MORT GI HEMORRHAGE   (Numerator)'
 TPIQ19 LENGTH=3
   LABEL='IN-HOSP MORT HIP FRACTURE    (Numerator)'
 TPIQ20 LENGTH=3
   LABEL='IN-HOSP MORT PNEUMONIA       (Numerator)'
;

 * -------------------------------------------------------------- ;
 * --- DEFINE PROVIDER LEVEL UTILIZATION INDICATORS ------------- ;
 * -------------------------------------------------------------- ;
 ATTRIB
 TPIQ21 LENGTH=3
   LABEL='CESAREAN SECTION DELIVERY    (Numerator)'
 TPIQ22 LENGTH=3
   LABEL='VAG BTH AFT C-SECTION,UNCOMPL (Numeratr)'
 TPIQ23 LENGTH=3
   LABEL='LAPAROSCOPIC CHOLECYSTECTOMY (Numerator)'
 TPIQ24 LENGTH=3
   LABEL='INCIDENTAL APPENDECTOMY      (Numerator)'
 TPIQ25 LENGTH=3
   LABEL='BI-LATERAL CATHETERIZATION   (Numerator)'
;

 * -------------------------------------------------------------- ;
 * --- DEFINE AREA LEVEL UTILIZATION INDICATORS ----------------- ;
 * -------------------------------------------------------------- ;
 ATTRIB
 TAIQ26 LENGTH=3
   LABEL='CORONARY ARTERY BYPASS GRAFT (Numerator)'
 TAIQ27 LENGTH=3
   LABEL='PTCA                         (Numerator)'
 TAIQ28 LENGTH=3
   LABEL='HYSTERECTOMY                 (Numerator)'
 TAIQ29 LENGTH=3
   LABEL='LAMINECTOMY AND/OR SPINAL FUSION   (Num)'
;

 * -------------------------------------------------------------- ;
 * --- DEFINE ADDITIONAL PROVIDER LEVEL MORTALITY INDICATORS ---- ;
 * -------------------------------------------------------------- ;
 ATTRIB
 TPIQ30 LENGTH=3
   LABEL='IN-HOSP MORT PTCA            (Numerator)'
 TPIQ31 LENGTH=3
   LABEL='IN-HOSP MORT CAROTID ENDARTERECTMY (Num)'
 TPIQ32 LENGTH=3
   LABEL='IN-HOSP MORT AMI,w/o TRANSFERS(Numeratr)'
;

 * -------------------------------------------------------------- ;
 * --- DEFINE ADDITIONAL PROVIDER LEVEL UTILIZATION INDICATORS -- ;
 * -------------------------------------------------------------- ;
 ATTRIB
 TPIQ33 LENGTH=3
   LABEL='PRIMARY CESAREAN SECTION     (Numerator)'
 TPIQ34 LENGTH=3
   LABEL='VBAC, ALL                    (Numerator)'
;

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

   * --- VOLUME ESOPHAGEAL RESECTION       --- ;

   IF MDC NOTIN (14,15) AND %MDX($PRESOPD.) AND

      %MPR($PRESOPP.) THEN

      TPIQ01 = 1;

   * --- VOLUME PANCREATIC RESECTION       --- ;

   IF MDC NOTIN (14,15) AND %MDX($PRPANCD.) AND

      %MPR($PRPANCP.) THEN

      TPIQ02 = 1;

   * --- VOLUME PEDIATRIC HEART SURGERY    --- ;

   IF MDC NOTIN (14) AND (0 <= AGE < 18) THEN DO; 

      * --- COUNTS THE NUMBER OF CARDIAC SURGERY CODES -------------- ;

      %PRPDCNT1;
      %PRPDCNT2;

      IF MPR1P > 0  THEN DO;

         TPIQ03 = 1;

      * --- EXCLUDE TRANSCATHETER INTERVENTIONS ------------------------ ;

         PDA = 0;
         IF ((MDX3D > 0 AND MDX3D = MDX2D) AND (MPR3EP > 0 AND MPR3EP = MPR1P))
         THEN PDA = 1;

         IF MPR5P = 0 AND MPR6P > 0 AND (
            MPR3AP = MPR1P OR 
            MPR3BP = MPR1P OR 
            MPR3CP = MPR1P OR 
            MPR3DP = MPR1P OR 
            PDA OR 
            MPR3FP = MPR1P) 
         THEN TPIQ03 = .;

         IF MPR5P = 0 AND (MPR4P = MPR1P) 
         THEN TPIQ03 = .;

       END;

   END;

   * --- VOLUME AAA REPAIR                 --- ;

   IF MDC NOTIN (14,15) AND %MDX($PRAAARD.) AND

      %MPR($PRAAARP.) THEN

      TPIQ04 = 1;

   * --- VOLUME CABG                       --- ;

   IF MDC NOTIN (14,15) AND (AGE >=40) AND

      %MPR($PRCABGP.) THEN

      TPIQ05 = 1;

   * --- VOLUME PTCA                       --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 40) AND

      %MPR($PRPTCAP.) THEN

      TPIQ06 = 1;

   * --- VOLUME CAROTID ENDARTERECTOMY     --- ;

   IF MDC NOTIN (14,15) AND %MPR($PRCEATP.) THEN

      TPIQ07 = 1;


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

   * --- IN-HOSP MORT ESOPHAGEAL RESECTION --- ;

   IF MDC NOTIN (14,15) AND %MDX($PRESOPD.) AND

      %MPR($PRESOPP.) THEN DO;

      TPIQ08 = 0;

      IF DISP = 20 THEN

         TPIQ08 = 1;

   END;

   * --- IN-HOSP MORT PANCREATIC RESECTION --- ;

   IF MDC NOTIN (14,15) AND %MDX($PRPANCD.) AND

      %MPR($PRPANCP.) THEN DO;

      TPIQ09 = 0;

      IF DISP = 20 THEN

         TPIQ09 = 1;

   END;

   * --- PEDIATRIC HEART SURGERY MORTALITY  --- ;

   IF MDC NOTIN (14) AND (0 <= AGE < 18) THEN DO; 

      * --- COUNTS THE NUMBER OF CARDIAC SURGERY CODES -------------- ;

      %PRPDCNT1;
      %PRPDCNT2;

      IF MPR1P > 0  THEN DO;

         TPIQ10 = 0;

         IF DISP = 20 THEN

            TPIQ10 = 1;

      * --- EXCLUDE TRANSCATHETER INTERVENTIONS ------------------------ ;

         PDA = 0;
         IF ((MDX3D > 0 AND MDX3D = MDX2D) AND (MPR3EP > 0 AND MPR3EP = MPR1P))
         THEN PDA = 1;

         IF MPR5P = 0 AND MPR6P > 0 AND (
            MPR3AP = MPR1P OR 
            MPR3BP = MPR1P OR 
            MPR3CP = MPR1P OR 
            MPR3DP = MPR1P OR 
            PDA OR 
            MPR3FP = MPR1P) 
         THEN TPIQ10 = .;

         IF MPR5P = 0 AND (MPR4P = MPR1P) 
         THEN TPIQ10 = .;

      * --- EXCLUDE HEART TRANSPLANT, UNKNOWN DISPOSITION, PREMATURE INFANTS
            WITH PDA AS ONLY CARDIAC PROCEDURE AND AGE LESS THAN 30 DAYS WITH
            PDA AS ONLY CARDIAC PROCEDURE                          ----- ;

         IF MPR7P > 0 OR DISP = . OR
            (MDX4D AND PDA) OR
            ((AGE = 0 AND AGEDAY <=30) AND PDA)           
         THEN TPIQ10 = .;

       END;

   END;

   * --- IN-HOSP MORT AAA REPAIR           --- ;

   IF MDC NOTIN (14,15) AND %MDX($PRAAARD.) AND

      %MPR($PRAAARP.) THEN DO;

      TPIQ11 = 0;

      IF DISP = 20 THEN

         TPIQ11 = 1;

   END;

   * --- IN-HOSP MORT CABG                 --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 40) AND

      %MPR($PRCABGP.) THEN DO;

      TPIQ12 = 0;

      IF DISP = 20 THEN

         TPIQ12 = 1;

   END;

   * --- IN-HOSP MORT CRANIOTOMY           --- ;

   IF DRG IN (1,2,528,529,530) THEN DO;

      TPIQ13 = 0;
 
      IF DISP = 20 THEN

         TPIQ13 = 1;

      IF %MDX1($HTRAUID.) THEN TPIQ13 = .;
   
   END;

   * --- IN-HOSP MORT HIP REPLACEMENT      --- ;

   IF MDC NOTIN (14,15) AND %MPR($MTHIPRP.) AND

      %MDX($MTHIPRD.) THEN DO;

      TPIQ14 = 0;

      IF DISP = 20 THEN

         TPIQ14 = 1;

   END;

   * --- IN-HOSP MORT AMI                  --- ;

   IF (AGE >= 18) AND %MDX1($MRTAMID.) THEN DO;

      TPIQ15 = 0;
      TPIQ32 = 0;

      IF DISP = 20 THEN DO;

         TPIQ15 = 1;
         TPIQ32 = 1;

      END;

   END;

   * --- IN-HOSP MORT CHF                  --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 18) AND

      %MDX1($MRTCHFD.) THEN DO;

      TPIQ16 = 0;

      IF DISP = 20 THEN

         TPIQ16 = 1;

   END;
   * --- IN-HOSP MORT STROKE               --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 18) AND

      %MDX1($MRTCVDD.) THEN DO;

      TPIQ17 = 0;

      IF DISP = 20 THEN

         TPIQ17 = 1;

   END;

   * --- IN-HOSP MORT GI HEMORRHAGE        --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 18) AND

      %MDX1($MRTGIHD.) THEN DO;

      TPIQ18 = 0;

      IF DISP = 20 THEN

         TPIQ18 = 1;

   END;

   * --- IN-HOSP MORT HIP FRACTURE         --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 18) AND

      %MDX1($MTHIPFD.) THEN DO;

      TPIQ19 = 0;

      IF DISP = 20 THEN

         TPIQ19 = 1;

   END;

   * --- IN-HOSP MORT PNEUMONIA            --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 18) AND

      %MDX1($MTPNEUD.) THEN DO;

      TPIQ20 = 0;

      IF DISP = 20 THEN

         TPIQ20 = 1;

   END;


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

   * --- CESAREAN SECTION DELIVERY         --- ;

   IF (370 <= DRG <= 375) THEN DO;

      TPIQ21 = 0;

      IF (370 <= DRG <= 371) OR 
         (%MPR($PRCSECP.) AND NOT %MPR($PRCSE2P.)) THEN

         TPIQ21 = 1;

      IF %MDX($PRCSECD.) OR %MPR($PRCSE3P.) THEN

         TPIQ21 = .;

   END;

   * --- VAGINAL BIRTH AFTER C-SECTION     --- ;

   IF (370 <= DRG <= 375) AND

      %MDX($PRVBACD.) THEN DO;

      TPIQ22 = 0;
      TPIQ34 = 0;

      IF (372 <= DRG <= 375) THEN DO;

         TPIQ22 = 1;
         TPIQ34 = 1;

      END;

      IF %MDX($PRCSECD.) OR %MPR($PRCSE3P.) THEN

         TPIQ22 = .;

   END;

   * --- LAPAROSCOPIC CHOLECYSTECTOMY      --- ;

   IF MDC NOTIN (14,15) AND %MPR($PRLAP2P.) AND

      %MDX($PRLAPOD.) THEN DO;

      TPIQ23 = 0;

      IF %MPR($PRLAPOP.) THEN

         TPIQ23 = 1;

   END;

   * --- INCIDENTAL APPENDECTOMY           --- ;

   IF MDC NOTIN (14,15) AND (AGE >=65 ) AND

      PUT(DRG,PRAPPNG.) = '1' THEN DO;

      TPIQ24=0;

      IF %MPR($PRAPPNP.) THEN

         TPIQ24 = 1;

   END;

   * --- BI-LATERAL CATHETERIZATION        --- ;

   IF MDC NOTIN (14,15) AND %MPR($PRCAT2P.) AND

      %MDX($PRCATHD.) THEN DO;

      TPIQ25 = 0;

      IF %MPR($PRCATHP.) AND NOT %MDX($PRCAT2D.) THEN

         TPIQ25 = 1;

   END;


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

   * --- CORONARY ARTERY BYPASS GRAFT      --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 40) AND

      %MPR($PRCABGP.) THEN

      TAIQ26 = 1;

   * --- PTCA                              --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 40) AND

      %MPR($PRPTCAP.) THEN

      TAIQ27 = 1;

   * --- HYSTERECTOMY                      --- ;

   IF MDC NOTIN (14,15) AND (SEX=2) AND (AGE >= 18) AND

      %MPR($PRHYSTP.) THEN DO;

      TAIQ28 = 1;

      * --- EXCLUDE GENITAL CANCER -------------------- ;
      IF %MDX($PRHYS1D.) THEN TAIQ28 = .;

      * --- EXCLUDE PELVIC OR LOWER ABDOMINAL --------- ;
      ELSE IF %MDX($PRHYS2D.) THEN TAIQ28 = .;

   END;

   * --- LAMINECTOMY AND/OR SPINAL FUSION  --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 18) AND

      %MPR($PRLAMIP.) THEN

      TAIQ29 = 1;


 * -------------------------------------------------------------- ;
 * --- CONSTRUCT ADDITIONAL PROVIDER LEVEL MORTALITY INDICATORS - ;
 * -------------------------------------------------------------- ;

   * --- IN-HOSP MORTALITY PTCA            --- ;

   IF MDC NOTIN (14,15) AND (AGE >= 40) AND

      %MPR($PRPTCAP.) THEN DO;

      TPIQ30 = 0;

      IF DISP = 20 THEN

         TPIQ30 = 1;

   END;

   * --- IN-HOSP MORT CAROTID ENDARTERECTMY--- ;

   IF MDC NOTIN (14,15) AND 

      %MPR($PRCEATP.) THEN DO;

      TPIQ31 = 0;

      IF DISP = 20 THEN

         TPIQ31 = 1;

   END;

 * -------------------------------------------------------------- ;
 * --- CONSTRUCT ADDIT'L PROVIDER LEVEL UTILIZATION INDICATORS -- ;
 * -------------------------------------------------------------- ;

   IF TPIQ21 NE . AND TPIQ22 EQ . THEN TPIQ33 = TPIQ21;

 * -------------------------------------------------------------- ;
 * --- EXCLUDE CASES WITH MISSING VALUES FOR DISP OR ASOURCE  --- ;
 * -------------------------------------------------------------- ;

 IF (DISP LT 0) THEN DO;
   TPIQ08 = .;
   TPIQ09 = .;
   TPIQ10 = .;
   TPIQ11 = .;
   TPIQ12 = .;
   TPIQ13 = .;
   TPIQ14 = .;
   TPIQ15 = .;
   TPIQ16 = .;
   TPIQ17 = .;
   TPIQ18 = .;
   TPIQ19 = .;
   TPIQ20 = .;
   TPIQ30 = .;
   TPIQ31 = .;
   TPIQ32 = .;
 END;

 IF (ASOURCE LT 0) THEN 
   TPIQ32 = .;

 * -------------------------------------------------------------- ;
 * --- EXCLUDE TRANSFERS ---------------------------------------- ;
 * -------------------------------------------------------------- ;

 * --- TRANSFER FROM ANOTHER ACUTE ---------------- ;
 IF (ASOURCE = 2) THEN 
   TPIQ32 = .;

 * --- TRANSFER TO ANOTHER ACUTE ------------------ ;
 IF (DISP = 2) THEN DO;
   TPIQ08 = .;
   TPIQ09 = .;
   TPIQ10 = .;
   TPIQ11 = .;
   TPIQ12 = .;
   TPIQ13 = .;
   TPIQ14 = .;
   TPIQ15 = .;
   TPIQ16 = .;
   TPIQ17 = .;
   TPIQ18 = .;
   TPIQ19 = .;
   TPIQ20 = .;
   TPIQ30 = .;
   TPIQ31 = .;
   TPIQ32 = .;
 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;
