*===================================================================;
*  Title:  PROGRAM P2 CALCULATES OBSERVED PROVIDER RATES FOR AHRQ
*          INPATIENT QUALITY INDICATORS
*
*  Description:;
*         USES PROC SUMMARY TO CALCULATE OBSERVED RATES FOR
*         INPATIENT QUALITY INDICATORS ACROSS STRATIFIERS.
*         PROGRAM USES HOSPID, AGECAT, SEXCAT, PAYCAT AND RACECAT.
*
*          >>>  VERSION 4.1, December 2009 <<<
*
*===================================================================;
FILENAME CONTROL 'C:\PATHNAME\CONTROL_IQI.SAS';  *<===USER MUST modify;

%INCLUDE CONTROL;


 TITLE2 'PROGRAM: P2';
 TITLE3 'AHRQ INPATIENT QUALITY INDICATORS: CALCULATE OBSERVED PROVIDER RATES';

 * -------------------------------------------------------------- ;
 * --- PROVIDER LEVEL MEANS ON INPATIENT DATA FILE  ------------- ;
 * -------------------------------------------------------------- ;

 PROC   SUMMARY DATA=IN1.&INFILE1.;
 CLASS  HOSPID AGECAT SEXCAT PAYCAT RACECAT;
 VAR    TPIQ01-TPIQ02 TPIQ04-TPIQ09 TPIQ11-TPIQ25 TPIQ30-TPIQ34;
 OUTPUT OUT=&OUTFILP2.
        SUM(TPIQ01-TPIQ02 TPIQ04-TPIQ09 TPIQ11-TPIQ25 TPIQ30-TPIQ34)=
        SUMWGT(TPIQ08-TPIQ09 TPIQ11-TPIQ25 TPIQ30-TPIQ34)=PPIQ08-PPIQ09 PPIQ11-PPIQ25 PPIQ30-PPIQ34
        MEAN(TPIQ08-TPIQ09 TPIQ11-TPIQ25 TPIQ30-TPIQ34)=OPIQ08-OPIQ09 OPIQ11-OPIQ25 OPIQ30-OPIQ34;
 WEIGHT DISCWT;
 RUN;

 PROC   SORT DATA=&OUTFILP2.;
 BY HOSPID AGECAT SEXCAT PAYCAT RACECAT;
 RUN;

 DATA   OUTP2.&OUTFILP2.;
 SET    &OUTFILP2. (WHERE=(_TYPE_ &TYPELVLP))
;

 LABEL
 TPIQ01   ='VOLUME ESOPHAGEAL RESECTION (Numerator)'
 TPIQ02   ='VOLUME PANCREATIC RESECTION (Numerator)'
 TPIQ04   ='VOLUME AAA REPAIR (Numerator)'
 TPIQ05   ='VOLUME CABG (Numerator)'
 TPIQ06   ='VOLUME PTCA (Numerator)'
 TPIQ07   ='VOLUME CAROTID ENDARTERECTOMY (Num)'
 TPIQ08   ='IN-HOSP MORT ESOPHAGEAL RESECTION (Num)'
 TPIQ09   ='IN-HOSP MORT PANCREATIC RESECTION (Num)'
 TPIQ11   ='IN-HOSP MORT AAA REPAIR (Numerator)'
 TPIQ12   ='IN-HOSP MORT CABG (Numerator)'
 TPIQ13   ='IN-HOSP MORT CRANIOTOMY (Numerator)'
 TPIQ14   ='IN-HOSP MORT HIP REPLACEMENT (Numerator)'
 TPIQ15   ='IN-HOSP MORT AMI (Numerator)'
 TPIQ16   ='IN-HOSP MORT CHF (Numerator)'
 TPIQ17   ='IN-HOSP MORT STROKE (Numerator)'
 TPIQ18   ='IN-HOSP MORT GI HEMORRHAGE (Numerator)'
 TPIQ19   ='IN-HOSP MORT HIP FRACTURE (Numerator)'
 TPIQ20   ='IN-HOSP MORT PNEUMONIA (Numerator)'
 TPIQ21   ='CESAREAN SECTION DELIVERY (Numerator)'
 TPIQ22   ='VAG BTH AFT C-SECTION,UNCOMPLICATED(Num)'
 TPIQ23   ='LAPAROSCOPIC CHOLECYSTECTOMY (Numerator)'
 TPIQ24   ='INCIDENTAL APPENDECTOMY (Numerator)'
 TPIQ25   ='BI-LATERAL CATHETERIZATION (Numerator)'
 TPIQ30   ='IN-HOSP MORT PTCA (Numerator)'
 TPIQ31   ='IN-HOSP MORT CAROTID ENDARTERECTOMY(Num)'
 TPIQ32   ='IN-HOSP MORT AMI, w/o TRANSFERS (Num)'
 TPIQ33   ='PRIMARY CESAREAN SECTION (Numerator)'
 TPIQ34   ='VBAC, ALL (Numerator)'
 PPIQ08   ='IN-HOSP MORT ESOPHAGEAL RESECTION (Pop)'
 PPIQ09   ='IN-HOSP MORT PANCREATIC RESECTION (Pop)'
 PPIQ11   ='IN-HOSP MORT AAA REPAIR (Population)'
 PPIQ12   ='IN-HOSP MORT CABG (Population)'
 PPIQ13   ='IN-HOSP MORT CRANIOTOMY (Population)'
 PPIQ14   ='IN-HOSP MORT HIP REPLACEMENT(Population)'
 PPIQ15   ='IN-HOSP MORT AMI (Population)'
 PPIQ16   ='IN-HOSP MORT CHF (Population)'
 PPIQ17   ='IN-HOSP MORT STROKE (Population)'
 PPIQ18   ='IN-HOSP MORT GI HEMORRHAGE (Population)'
 PPIQ19   ='IN-HOSP MORT HIP FRACTURE (Population)'
 PPIQ20   ='IN-HOSP MORT PNEUMONIA (Population)'
 PPIQ21   ='CESAREAN SECTION DELIVERY (Population)'
 PPIQ22   ='VAG BTH AFT C-SECTION,UNCOMPLICATED(Pop)'
 PPIQ23   ='LAPAROSCOPIC CHOLECYSTECTOMY(Population)'
 PPIQ24   ='INCIDENTAL APPENDECTOMY (Population)'
 PPIQ25   ='BI-LATERAL CATHETERIZATION (Population)'
 PPIQ30   ='IN-HOSP MORT PTCA (Population)'
 PPIQ31   ='IN-HOSP MORT CAROTID ENDARTERECTOMY(Pop)'
 PPIQ32   ='IN-HOSP MORT AMI, w/o TRANSFERS (Pop)'
 PPIQ33   ='PRIMARY CESAREAN SECTION (Population)'
 PPIQ34   ='VBAC, ALL (Population)'
 OPIQ08   ='IN-HOSP MORT ESOPHAGEAL RESECT(Observed)'
 OPIQ09   ='IN-HOSP MORT PANCREATIC RESECT(Observed)'
 OPIQ11   ='IN-HOSP MORT AAA REPAIR (Observed)'
 OPIQ12   ='IN-HOSP MORT CABG (Observed)'
 OPIQ13   ='IN-HOSP MORT CRANIOTOMY (Observed)'
 OPIQ14   ='IN-HOSP MORT HIP REPLACEMENT (Observed)'
 OPIQ15   ='IN-HOSP MORT AMI (Observed)'
 OPIQ16   ='IN-HOSP MORT CHF (Observed)'
 OPIQ17   ='IN-HOSP MORT STROKE (Observed)'
 OPIQ18   ='IN-HOSP MORT GI HEMORRHAGE (Observed)'
 OPIQ19   ='IN-HOSP MORT HIP FRACTURE (Observed)'
 OPIQ20   ='IN-HOSP MORT PNEUMONIA (Observed)'
 OPIQ21   ='CESAREAN SECTION DELIVERY (Observed)'
 OPIQ22   ='VAG BTH AFT C-SECTION,UNCOMPL (Observed)'
 OPIQ23   ='LAPAROSCOPIC CHOLECYSTECTOMY (Observed)'
 OPIQ24   ='INCIDENTAL APPENDECTOMY (Observed)'
 OPIQ25   ='BI-LATERAL CATHETERIZATION (Observed)'
 OPIQ30   ='IN-HOSP MORT PTCA (Observed)'
 OPIQ31   ='IN-HOSP MORT CAROTID ENDARTERECTOMY(Obs)'
 OPIQ32   ='IN-HOSP MORT AMI,w/o TRANSFERS(Observed)'
 OPIQ33   ='PRIMARY CESAREAN SECTION (Observed)'
 OPIQ34   ='VBAC, ALL (Observed)'
 _TYPE_   ='STRATIFICATION LEVEL'
;
 DROP _FREQ_ ;

 RUN;

 * -------------------------------------------------------------- ;
 * --- CONTENTS AND MEANS OF PROVIDER OBSERVED MEANS FILE ------- ;
 * -------------------------------------------------------------- ;

 PROC   CONTENTS DATA=OUTP2.&OUTFILP2. POSITION;
 RUN;

 PROC   MEANS DATA=OUTP2.&OUTFILP2. (WHERE=(_TYPE_ IN (16))) N NMISS MIN MAX MEAN SUM;
 TITLE4 "SUMMARY OF PROVIDER-LEVEL RATES (_TYPE_=16)";
 RUN;

 * -------------------------------------------------------------- ;
 * --- PRINT PROVIDER OBSERVED MEANS FILE ----------------------- ;
 * -------------------------------------------------------------- ;

 %MACRO PRT2;

 %IF &PRINT. = 1 %THEN %DO;

 %MACRO PRT(IQ,TEXT,VOLUME);

 PROC   PRINT DATA=OUTP2.&OUTFILP2. LABEL SPLIT='*';
 %IF &VOLUME=0 %THEN %DO;
 VAR    HOSPID AGECAT SEXCAT PAYCAT RACECAT TPIQ&IQ. PPIQ&IQ. OPIQ&IQ. ;
 LABEL HOSPID  = "HOSPID"
       AGECAT  = "AGECAT"
       SEXCAT  = "SEXCAT"
       PAYCAT  = "PAYCAT"
       RACECAT = "RACECAT"
       TPIQ&IQ.   = "TPIQ&IQ.*(Numerator)"
       PPIQ&IQ.   = "PPIQ&IQ.*(Denominator)"
       OPIQ&IQ.   = "OPIQ&IQ.*(Observed)"
       ;
 FORMAT TPIQ&IQ. PPIQ&IQ. 13.0 OPIQ&IQ. 8.6;
 %END;
 %ELSE %DO;
 VAR    HOSPID AGECAT SEXCAT PAYCAT RACECAT TPIQ&IQ.  ;
 LABEL HOSPID  = "HOSPID"
       AGECAT  = "AGECAT"
       SEXCAT  = "SEXCAT"
       PAYCAT  = "PAYCAT"
       RACECAT = "RACECAT"
       TPIQ&IQ.   = "TPIQ&IQ.*(Numerator)"
       ;
 FORMAT TPIQ&IQ. 13.0;
 %END;
 FORMAT AGECAT AGECAT.
        SEXCAT SEXCAT.
        PAYCAT PAYCAT.
        RACECAT RACECAT.
   ;
 TITLE4 "Indicator # &IQ.: &TEXT";
 RUN;

 %MEND PRT;

 %PRT(01,VOLUME ESOPHAGEAL RESECTION,1);
 %PRT(02,VOLUME PANCREATIC RESECTION,1);
 %PRT(04,VOLUME AAA REPAIR,1);
 %PRT(05,VOLUME CABG,1); 
 %PRT(06,VOLUME PTCA,1);
 %PRT(07,VOLUME CAROTID ENDARTERECTOMY,1);
 %PRT(08,IN-HOSP MORT ESOPHAGEAL RESECTION,0);
 %PRT(09,IN-HOSP MORT PANCREATIC RESECTION,0);
 %PRT(11,IN-HOSP MORT AAA REPAIR,0);
 %PRT(12,IN-HOSP MORT CABG,0);
 %PRT(13,IN-HOSP MORT CRANIOTOMY,0);
 %PRT(14,IN-HOSP MORT HIP REPLACEMENT,0);
 %PRT(15,IN-HOSP MORT AMI,0);
 %PRT(16,IN-HOSP MORT CHF,0);
 %PRT(17,IN-HOSP MORT STROKE,0);
 %PRT(18,IN-HOSP MORT GI HEMORRHAGE,0);
 %PRT(19,IN-HOSP MORT HIP FRACTURE,0);
 %PRT(20,IN-HOSP MORT PNEUMONIA,0);
 %PRT(21,CESAREAN SECTION DELIVERY,0);
 %PRT(22,VAG BTH AFT C-SECTION-UNCOMPLICATED,0);
 %PRT(23,LAPAROSCOPIC CHOLECYSTECTOMY,0);
 %PRT(24,INCIDENTAL APPENDECTOMY AMONG ELDERLY,0);
 %PRT(25,BI-LATERAL CARDIAC CATHETERIZATION,0);
 %PRT(30,IN-HOSP MORT PTCA,0);
 %PRT(31,IN-HOSP MORT CAROTID ENDARTERECTOMY,0);
 %PRT(32,IN-HOSP MORT AMI-WITHOUT TRANSFER CASES,0);
 %PRT(33,PRIMARY CESAREAN SECTION,0);
 %PRT(34,VBAC-ALL,0);

 %END;

 %MEND PRT2;

 %PRT2;


 * -------------------------------------------------------------- ;
 * --- WRITE SAS OUTPUT DATA SET TO COMMA-DELIMITED TEXT FILE --- ;
 * --- FOR EXPORT INTO SPREADSHEETS ----------------------------- ;
 * -------------------------------------------------------------- ;

 %MACRO TEXTP2;

 %IF &TEXTP2. = 1  %THEN %DO;

 DATA _NULL_;
 SET OUTP2.&OUTFILP2.;
 FILE IQTEXTP2 LRECL=1000;
 IF _N_=1 THEN PUT "Hosp Id" "," "Age"  "," "Sex"  "," "Payer" "," "Race"  "," "Type" ","
 "TPIQ01" "," "TPIQ02" "," "TPIQ04" ","
 "TPIQ05" "," "TPIQ06" "," "TPIQ07" "," "TPIQ08" ","
 "TPIQ09" "," "TPIQ11" "," "TPIQ12" ","
 "TPIQ13" "," "TPIQ14" "," "TPIQ15" "," "TPIQ16" ","
 "TPIQ17" "," "TPIQ18" "," "TPIQ19" "," "TPIQ20" ","
 "TPIQ21" "," "TPIQ22" "," "TPIQ23" "," "TPIQ24" "," 
 "TPIQ25" "," "TPIQ30" "," "TPIQ31" "," "TPIQ32" "," 
 "TPIQ33" "," "TPIQ34" ","  
 "PPIQ08" ","
 "PPIQ09" "," "PPIQ11" "," "PPIQ12" ","
 "PPIQ13" "," "PPIQ14" "," "PPIQ15" "," "PPIQ16" ","
 "PPIQ17" "," "PPIQ18" "," "PPIQ19" "," "PPIQ20" ","
 "PPIQ21" "," "PPIQ22" "," "PPIQ23" "," "PPIQ24" "," 
 "PPIQ25" "," "PPIQ30" "," "PPIQ31" "," "PPIQ32" "," 
 "PPIQ33" "," "PPIQ34" "," 
 "OPIQ08" ","
 "OPIQ09" "," "OPIQ11" "," "OPIQ12" ","
 "OPIQ13" "," "OPIQ14" "," "OPIQ15" "," "OPIQ16" ","
 "OPIQ17" "," "OPIQ18" "," "OPIQ19" "," "OPIQ20" ","
 "OPIQ21" "," "OPIQ22" "," "OPIQ23" "," "OPIQ24" ","
 "OPIQ25" "," "OPIQ30" "," "OPIQ31" "," "OPIQ32" "," 
 "OPIQ33" "," "OPIQ34" 
 ;

 PUT HOSPID 13. "," AGECAT 3.  "," SEXCAT 3. "," PAYCAT 3. "," RACECAT 3. "," _TYPE_ 2.  ","
 (TPIQ01-TPIQ02 TPIQ04-TPIQ09 TPIQ11-TPIQ25 TPIQ30-TPIQ34) (7.0 ",")
 ","
 (PPIQ08-PPIQ09 PPIQ11-PPIQ25 PPIQ30-PPIQ34) (13.2 ",")
 ","
 (OPIQ08-OPIQ09 OPIQ11-OPIQ25 OPIQ30-OPIQ34) (12.10 ",")
 ;
 RUN;

 %END;

 %MEND TEXTP2;

 %TEXTP2;
