*===================================================================;
*  Title:  PROGRAM P3: CALCULATES RISK-ADJUSTED PROVIDER
*          RATES FOR AHRQ INPATIENT QUALITY INDICATORS
*
*  Description:
*         USES MCMC TO CALCULATE RISK-ADJUSTED RATES FOR
*         INPATIENT QUALITY INDICATORS.
*         ADJUSTS FOR: SEX, AGE, APR-DRG SUBCLASS AND MDC
*
*          >>>  VERSION 4.1, December 2009 						 <<<
*
*===================================================================;
FILENAME CONTROL 'C:\PATHNAME\CONTROL_IQI.SAS';  *<===USER MUST modify;

%INCLUDE CONTROL;


TITLE2 'PROGRAM P3 PART I';
TITLE3 'AHRQ INPATIENT QUALITY INDICATORS: CALCULATE RISK-ADJUSTED PROVIDER RATES';

 * -------------------------------------------------------------- ;
 * --- INPATIENT QUALITY INDICATOR ADJUSTED RATES  -------------- ;
 * -------------------------------------------------------------- ;
 * --- THIS STEP SELECTS THE OBSERVATIONS FROM THE PROGRAM 1    - ;
 * --- OUTPUT FOR EACH INPATIENT QUALITY INDICATOR IN TURN.     - ;
 * --- EACH ITERATION PASSES VARIABLES THAT CONTROL THE         - ;
 * --- COVARIATES FOR THAT INPATIENT QUALITY INDICATOR:         - ;
 * --- N - OBSERVATION NUMBER FROM THE MEANS AND COVAR FILES    - ;
 * ---     ALSO IDENTIFIES THE FORMAT USED TO INDEX COVARIATES  - ;
 * --- IQ - THE INPATIENT QUALITY INDICATOR NAME WITHOUT THE    - ;
 * ---      PREFIX (P)                                          - ;
 * --- APRDRG - THE NAME OF THE VARIABLE CONTAINING APR-DRG     - ;
 * --- SUBCLS - THE NAME OF THE VARIABLE CONTAINING THE APR-    - ;
 * ---          DRG SUBCLASS APPROPRIATE FOR THAT INPATIENT     - ;
 * ---          QUALITY INDICATOR                               - ;
 * --- Z,X - NUMBER OF COVARIATES                               - ;
 * -------------------------------------------------------------- ;

 %MACRO ADDAPR;
    %IF &APRDRGFG EQ 1 %THEN &APRDRG &MORTAL &XMORTAL;
 %MEND;
 
 %MACRO MOD3(N,IQ,APRDRG,ZSUBCLS,XSUBCLS,Z,X);

 * --- THIS SET CREATES TEMP1 WHICH CONTAINS THE DEPENDENT      - ;
 * --- VARIABLE (TIQ) AND INDEPENDENT VARIABLES USED IN         - ;
 * --- REGRESSION.                                              - ;

 DATA TEMP1
   (KEEP=KEY HOSPID AGECAT SEXCAT PAYCAT RACECAT
         T&IQ. YT&IQ. P1 ZCV1-ZCV&Z. XCV1-XCV&X. DISCWT);
 LENGTH APRDRGZ APRDRGX $4 ZCV1-ZCV&Z. XCV1-XCV&X. P1 
        SIDX AIDX ZIDX XIDX MIDX 3;
 SET IN1.&INFILE1.
   (KEEP=KEY HOSPID
         POPCAT AGECAT SEXCAT PAYCAT RACECAT 
         T&IQ. %ADDAPR DISCWT
         NOPOA TRNSFER NOPOUB04 RUPTURED MDC);

 * --- KEEP ONLY DISCHARGES NEEDED FOR THIS IQ ------------------ ;
 IF T&IQ. NE .;

 * --- INITIALIZE COVARIATE DUMMIES TO ZERO --------------------- ;
 ARRAY ZCV{&Z.} ZCV1-ZCV&Z.;
 ARRAY XCV{&X.} XCV1-XCV&X.;

 DO I = 1 TO &Z.;
   ZCV(I) = 0;
 END;

 DO I = 1 TO &X.;
   XCV(I) = .;
   IF NOPOA IN (0) THEN XCV(I) = 0; 
 END;

 * --- SET INDEX FOR SEX, AGE, APRDRG AND MDC                 --- ;
 * --- CATEGORIES VARY BY INPATIENT QUALITY INDICATOR AND ARE --- ;
 * --- DETERMINED BY THE FORMAT CORRESPONDING TO N.           --- ;

 SIDX = PUT(SEXCAT,S&N.IQFMT.);
 AIDX = PUT(POPCAT,A&N.IQFMT.);

 IF &ZSUBCLS. >= 0 THEN DO;
    APRDRGZ = PUT(&APRDRG.,Z3.)||PUT(&ZSUBCLS.,Z1.);
    ZIDX = PUT(APRDRGZ,$C&N.IQFM.);
 END;
 ELSE ZIDX = 0;

 IF &XSUBCLS. >= 0 THEN DO;
    APRDRGX = PUT(&APRDRG.,Z3.)||PUT(&XSUBCLS.,Z1.);
    XIDX = PUT(APRDRGX,$C&N.IQFM.);
 END; 
 ELSE XIDX = 0;
 
 MIDX = PUT(MDC,M&N.IQFMT.);

 * --- SET APPROPRIATE COVARIATE DUMMY TO 1 FOR THIS DISCHARGE  - ;
 IF SIDX > 0 THEN ZCV(SIDX) = 1; 
 IF AIDX > 0 THEN ZCV(AIDX) = 1; 
 IF ZIDX > 0 THEN ZCV(ZIDX) = 1;
 IF ZIDX = -1 AND MIDX > 0 THEN ZCV(MIDX) = 1;

 IF NOPOA IN (0) THEN DO;
    IF SIDX > 0 THEN XCV(SIDX) = 1; 
    IF AIDX > 0 THEN XCV(AIDX) = 1; 
    IF XIDX > 0 THEN XCV(XIDX) = 1; 
    IF XIDX = -1 AND MIDX > 0 THEN XCV(MIDX) = 1;
 END;

 IF &N. = 11 THEN DO;
    IF RUPTURED THEN ZCV(11) = 1;
 END;
 IF &N. = 13 THEN DO;
    IF TRNSFER THEN ZCV(16) = 1;
 END;
 IF &N. = 15 THEN DO;
    IF TRNSFER THEN ZCV(26) = 1;
 END;
 IF &N. = 16 THEN DO;
    IF TRNSFER THEN ZCV(27) = 1;
    IF NOPOUB04 THEN ZCV(28) = 1;
 END;
 IF &N. = 17 THEN DO;
    IF NOPOUB04 THEN ZCV(29) = 1;
 END;
 IF &N. = 18 THEN DO;
    IF TRNSFER THEN ZCV(24) = 1;
 END;
 IF &N. = 19 THEN DO;
    IF TRNSFER THEN ZCV(16) = 1;
    IF NOPOUB04 THEN ZCV(17) = 1;
 END;
 IF &N. = 20 THEN DO;
    IF TRNSFER THEN ZCV(28) = 1;
 END;
 IF &N. = 30 THEN DO;
    IF TRNSFER THEN ZCV(20) = 1;
    IF NOPOUB04 THEN ZCV(21) = 1;
 END;

 IF NOPOA IN (0) THEN DO;
    IF &N. = 11 THEN DO;
       IF RUPTURED THEN XCV(11) = 1;
    END;
    IF &N. = 13 THEN DO;
       IF TRNSFER THEN XCV(16) = 1;
    END;
    IF &N. = 15 THEN DO;
       IF TRNSFER THEN XCV(26) = 1;
    END;
    IF &N. = 16 THEN DO;
       IF TRNSFER THEN XCV(27) = 1;
       IF NOPOUB04 THEN XCV(28) = 1;
    END;
    IF &N. = 17 THEN DO;
       IF NOPOUB04 THEN XCV(29) = 1;
    END;
    IF &N. = 18 THEN DO;
       IF TRNSFER THEN XCV(24) = 1;
    END;
    IF &N. = 19 THEN DO;
       IF TRNSFER THEN XCV(16) = 1;
       IF NOPOUB04 THEN XCV(17) = 1;
    END;
    IF &N. = 20 THEN DO;
       IF TRNSFER THEN XCV(28) = 1;
    END;
    IF &N. = 30 THEN DO;
       IF TRNSFER THEN XCV(20) = 1;
       IF NOPOUB04 THEN XCV(21) = 1;
    END;
 END;

 YT&IQ. = T&IQ.;
 *P1 = QPIQ&IQ.;
 P1 = .;
 IF NOPOA IN (0) THEN P1 = 0;
 
 RUN;

 %let dsid=%sysfunc(open(temp1));
 %let dnum=%sysfunc(attrn(&dsid,nobs));
 %let drc=%sysfunc(close(&dsid));

 %if &dnum ne 0 %then %do;

 DATA TEMP1Y;
 LENGTH KEY HOSPID 8 YT&IQ. P1 ZCV1-ZCV&Z. XCV1-XCV&X. 3;
 SET TEMP1
   (KEEP=KEY HOSPID
         YT&IQ. P1 
         ZCV1-ZCV&Z. XCV1-XCV&X.);

  RUN;

 PROC SORT DATA=TEMP1Y;
 BY HOSPID KEY;
 RUN;

 PROC MEANS DATA=TEMP1Y N MEAN;
 VAR YT&IQ. P1 ZCV1-ZCV&Z. XCV1-XCV&X.;
 RUN;

 DATA TEMP1W;
 SET TEMP1
   (KEEP=KEY HOSPID 
         AGECAT SEXCAT PAYCAT RACECAT
         T&IQ. DISCWT);

 RUN;

 PROC SORT DATA=TEMP1W;
 BY HOSPID KEY;
 RUN;

 %INCLUDE PRDP;

 PROC SORT DATA=TEMP1I(KEEP=HOSPID KEY P P_X Y_X_P_0 Y_X_P_0_MCMC);
 BY HOSPID KEY;
 RUN;

 DATA TEMP1W;
 MERGE TEMP1W TEMP1I;
 BY HOSPID KEY;

 %INCLUDE MSXP;
 IF &N. =  8 THEN SUB_N = 1;
 IF &N. =  9 THEN SUB_N = 2;
 IF &N. = 11 THEN SUB_N = 3;
 IF &N. = 12 THEN SUB_N = 4;
 IF &N. = 13 THEN SUB_N = 5;
 IF &N. = 14 THEN SUB_N = 6;
 IF &N. = 15 THEN SUB_N = 7;
 IF &N. = 16 THEN SUB_N = 8;
 IF &N. = 17 THEN SUB_N = 9;
 IF &N. = 18 THEN SUB_N = 10;
 IF &N. = 19 THEN SUB_N = 11;
 IF &N. = 20 THEN SUB_N = 12;
 IF &N. = 30 THEN SUB_N = 18;
 IF &N. = 31 THEN SUB_N = 19;
 IF &N. = 32 THEN SUB_N = 20;

 EHAT = (ARRYP3(SUB_N)/(ARRYP3(SUB_N)-ARRYP4(SUB_N))) * Y_X_P_0_MCMC;
 PHAT = EHAT * (1 - EHAT);

 IF P = . THEN PWHT = (1 - P_X) * DISCWT;
 ELSE PWHT = (1 - P) * DISCWT;

 RUN;

 PROC SUMMARY DATA=TEMP1W;
 CLASS HOSPID AGECAT SEXCAT PAYCAT RACECAT;
 VAR T&IQ. EHAT PHAT;
 OUTPUT OUT=R&IQ. SUM(T&IQ. EHAT PHAT)=T&IQ. EHAT PHAT 
                  SUMWGT(T&IQ.)=P&IQ.;
 WEIGHT PWHT;
 RUN;

 DATA R&IQ.(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT _TYPE_
                 E&IQ. R&IQ. L&IQ. U&IQ. S&IQ. X&IQ. V&IQ.
                 T&IQ. P&IQ. O&IQ.);
 SET R&IQ.;

 IF _TYPE_ &TYPELVLP;

 %INCLUDE MSXP;
 IF &N. =  8 THEN SUB_N = 1;
 IF &N. =  9 THEN SUB_N = 2;
 IF &N. = 11 THEN SUB_N = 3;
 IF &N. = 12 THEN SUB_N = 4;
 IF &N. = 13 THEN SUB_N = 5;
 IF &N. = 14 THEN SUB_N = 6;
 IF &N. = 15 THEN SUB_N = 7;
 IF &N. = 16 THEN SUB_N = 8;
 IF &N. = 17 THEN SUB_N = 9;
 IF &N. = 18 THEN SUB_N = 10;
 IF &N. = 19 THEN SUB_N = 11;
 IF &N. = 20 THEN SUB_N = 12;
 IF &N. = 30 THEN SUB_N = 18;
 IF &N. = 31 THEN SUB_N = 19;
 IF &N. = 32 THEN SUB_N = 20;

 T&IQ. = ROUND(T&IQ.,1);
 P&IQ. = ROUND(P&IQ.,1);

 E&IQ. = EHAT / P&IQ.;
 O&IQ. = T&IQ. / P&IQ.;
 
 IF PHAT < 0 THEN DO;
    R&IQ.   = .;
    SE&IQ.  = .;
    V&IQ.   = .;
    S&IQ.   = .;
    X&IQ.   = .;
 END;
 ELSE IF _TYPE_ IN (0,16) THEN DO;
    R&IQ.   = (O&IQ. / E&IQ.) * ARRYP3(SUB_N);
    SE&IQ.  = (ARRYP3(SUB_N) / E&IQ.) * (1 / P&IQ.) * SQRT(PHAT);
    V&IQ.   = SE&IQ.**2;
    SN&IQ.  = ARRYP2(SUB_N) / (ARRYP2(SUB_N) + V&IQ.);
    S&IQ.   = (R&IQ. * SN&IQ.) + ((1 -  SN&IQ.) * ARRYP3(SUB_N));
    X&IQ.   = SQRT(ARRYP2(SUB_N)- (SN&IQ. * ARRYP2(SUB_N)));
 END;
 ELSE DO;
    R&IQ.   = (O&IQ./ E&IQ.);
    SE&IQ.  = (1 / E&IQ.) * (1 / P&IQ.) * SQRT(PHAT);
    V&IQ.   = .;
    S&IQ.   = .;
    X&IQ.   = .;
 END;

 L&IQ.   = R&IQ. - (1.96 * SE&IQ.);
 IF L&IQ. < 0 THEN L&IQ. = 0;
 U&IQ.   = R&IQ. + (1.96 * SE&IQ.);
 IF U&IQ. > 1 THEN U&IQ. = 1;
 IF R&IQ. > 1 THEN R&IQ. = 1;

 RUN;

 %end;
 %else %do;

 DATA   R&IQ.;
    HOSPID=.;AGECAT=.;SEXCAT=.;PAYCAT=.;RACECAT=.;_TYPE_=0;
    E&IQ=.;R&IQ=.;L&IQ=.;U&IQ=.;S&IQ=.;X&IQ=.;V&IQ =.;
    T&IQ =.;P&IQ=.;O&IQ =.;
    OUTPUT;
 RUN;

 %end;

 PROC   DATASETS NOLIST;
 DELETE TEMP1 TEMP1Y TEMP1W;
 RUN;

 %MEND;

 %MOD3(8,PIQ08,&APRDRG.,&MORTAL.,&XMORTAL.,5,5);
 %MOD3(9,PIQ09,&APRDRG.,&MORTAL.,&XMORTAL.,6,6);
 %MOD3(11,PIQ11,&APRDRG.,&MORTAL.,&XMORTAL.,11,11);
 %MOD3(12,PIQ12,&APRDRG.,&MORTAL.,&XMORTAL.,23,23);
 %MOD3(13,PIQ13,&APRDRG.,&MORTAL.,&XMORTAL.,16,16);
 %MOD3(14,PIQ14,&APRDRG.,&MORTAL.,&XMORTAL.,6,6);
 %MOD3(15,PIQ15,&APRDRG.,&MORTAL.,&XMORTAL.,26,26);
 %MOD3(16,PIQ16,&APRDRG.,&MORTAL.,&XMORTAL.,28,28);
 %MOD3(17,PIQ17,&APRDRG.,&MORTAL.,&XMORTAL.,29,29);
 %MOD3(18,PIQ18,&APRDRG.,&MORTAL.,&XMORTAL.,24,24);
 %MOD3(19,PIQ19,&APRDRG.,&MORTAL.,&XMORTAL.,17,17);
 %MOD3(20,PIQ20,&APRDRG.,&MORTAL.,&XMORTAL.,28,28);
 %MOD3(30,PIQ30,&APRDRG.,&MORTAL.,&XMORTAL.,21,21);
 %MOD3(31,PIQ31,&APRDRG.,&MORTAL.,&XMORTAL.,6,6);
 %MOD3(32,PIQ32,&APRDRG.,&MORTAL.,&XMORTAL.,23,23);

 * --- MERGES THE AREA ADJUSTED RATES FOR EACH INPATIENT QUALITY  - ;
 * --- INDICATOR.  PREFIX FOR THE ADJUSTED RATES IS (R).          - ;

 DATA   RISKADJ;
 MERGE  RPIQ08(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ08 RPIQ08 LPIQ08 UPIQ08 SPIQ08 XPIQ08 VPIQ08 TPIQ08 PPIQ08 OPIQ08)
        RPIQ09(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ09 RPIQ09 LPIQ09 UPIQ09 SPIQ09 XPIQ09 VPIQ09 TPIQ09 PPIQ09 OPIQ09)
        RPIQ11(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ11 RPIQ11 LPIQ11 UPIQ11 SPIQ11 XPIQ11 VPIQ11 TPIQ11 PPIQ11 OPIQ11)
        RPIQ12(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ12 RPIQ12 LPIQ12 UPIQ12 SPIQ12 XPIQ12 VPIQ12 TPIQ12 PPIQ12 OPIQ12)
        RPIQ13(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ13 RPIQ13 LPIQ13 UPIQ13 SPIQ13 XPIQ13 VPIQ13 TPIQ13 PPIQ13 OPIQ13)
        RPIQ14(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ14 RPIQ14 LPIQ14 UPIQ14 SPIQ14 XPIQ14 VPIQ14 TPIQ14 PPIQ14 OPIQ14)
        RPIQ15(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ15 RPIQ15 LPIQ15 UPIQ15 SPIQ15 XPIQ15 VPIQ15 TPIQ15 PPIQ15 OPIQ15)
        RPIQ16(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ16 RPIQ16 LPIQ16 UPIQ16 SPIQ16 XPIQ16 VPIQ16 TPIQ16 PPIQ16 OPIQ16)
        RPIQ17(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ17 RPIQ17 LPIQ17 UPIQ17 SPIQ17 XPIQ17 VPIQ17 TPIQ17 PPIQ17 OPIQ17)
        RPIQ18(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ18 RPIQ18 LPIQ18 UPIQ18 SPIQ18 XPIQ18 VPIQ18 TPIQ18 PPIQ18 OPIQ18)
        RPIQ19(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ19 RPIQ19 LPIQ19 UPIQ19 SPIQ19 XPIQ19 VPIQ19 TPIQ19 PPIQ19 OPIQ19)
        RPIQ20(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ20 RPIQ20 LPIQ20 UPIQ20 SPIQ20 XPIQ20 VPIQ20 TPIQ20 PPIQ20 OPIQ20)
        RPIQ30(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ30 RPIQ30 LPIQ30 UPIQ30 SPIQ30 XPIQ30 VPIQ30 TPIQ30 PPIQ30 OPIQ30)
        RPIQ31(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ31 RPIQ31 LPIQ31 UPIQ31 SPIQ31 XPIQ31 VPIQ31 TPIQ31 PPIQ31 OPIQ31)
        RPIQ32(KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT EPIQ32 RPIQ32 LPIQ32 UPIQ32 SPIQ32 XPIQ32 VPIQ32 TPIQ32 PPIQ32 OPIQ32);
 BY HOSPID AGECAT SEXCAT PAYCAT RACECAT;

 LABEL
 EPIQ08 ='IN-HOSP MORT ESOPHL RESECTION (Expected)'
 EPIQ09 ='IN-HOSP MORT PANCRC RESECTION (Expected)'
 EPIQ11 ='IN-HOSP MORT AAA REPAIR (Expected)'
 EPIQ12 ='IN-HOSP MORT CABG (Expected)'
 EPIQ13 ='IN-HOSP MORT CRANIOTOMY (Expected)'
 EPIQ14 ='IN-HOSP MORT HIP REPLACEMENT (Expected)'
 EPIQ15 ='IN-HOSP MORT AMI (Expected)'
 EPIQ16 ='IN-HOSP MORT CHF (Expected)'
 EPIQ17 ='IN-HOSP MORT STROKE (Expected)'
 EPIQ18 ='IN-HOSP MORT GI HEMORRHAGE (Expected)'
 EPIQ19 ='IN-HOSP MORT HIP FRACTURE (Expected)'
 EPIQ20 ='IN-HOSP MORT PNEUMONIA (Expected)'
 EPIQ30 ='IN-HOSP MORT PTCA (Expected)'
 EPIQ31 ='IN-HOSP MORT CAROTID ENDARTERECTMY (Exp)'
 EPIQ32 ='IN-HOSP MORT AMI,w/o TRANSFERS(Expected)'
 ;

 LABEL
 RPIQ08 ='IN-HOSP MORT ESOPHL RESECTION (Risk Adj)'
 RPIQ09 ='IN-HOSP MORT PANCRC RESECTION (Risk Adj)'
 RPIQ11 ='IN-HOSP MORT AAA REPAIR (Risk Adj)'
 RPIQ12 ='IN-HOSP MORT CABG (Risk Adj)'
 RPIQ13 ='IN-HOSP MORT CRANIOTOMY (Risk Adj)'
 RPIQ14 ='IN-HOSP MORT HIP REPLACEMENT (Risk Adj)'
 RPIQ15 ='IN-HOSP MORT AMI (Risk Adj)'
 RPIQ16 ='IN-HOSP MORT CHF (Risk Adj)'
 RPIQ17 ='IN-HOSP MORT STROKE (Risk Adj)'
 RPIQ18 ='IN-HOSP MORT GI HEMORRHAGE (Risk Adj)'
 RPIQ19 ='IN-HOSP MORT HIP FRACTURE (Risk Adj)'
 RPIQ20 ='IN-HOSP MORT PNEUMONIA (Risk Adj)'
 RPIQ30 ='IN-HOSP MORT PTCA (Risk Adj)'
 RPIQ31 ='IN-HOSP MORT CAROTID ENDARTERECTMY (RAd)'
 RPIQ32 ='IN-HOSP MORT AMI,w/o TRANSFERS(Risk Adj)'
 ;

 LABEL
 LPIQ08 ='IN-HOSP MORT ESOPHL RESECTION (Lower CL)'
 LPIQ09 ='IN-HOSP MORT PANCRC RESECTION (Lower CL)'
 LPIQ11 ='IN-HOSP MORT AAA REPAIR (Lower CL)'
 LPIQ12 ='IN-HOSP MORT CABG (Lower CL)'
 LPIQ13 ='IN-HOSP MORT CRANIOTOMY (Lower CL)'
 LPIQ14 ='IN-HOSP MORT HIP REPLACEMENT (Lower CL)'
 LPIQ15 ='IN-HOSP MORT AMI (Lower CL)'
 LPIQ16 ='IN-HOSP MORT CHF (Lower CL)'
 LPIQ17 ='IN-HOSP MORT STROKE (Lower CL)'
 LPIQ18 ='IN-HOSP MORT GI HEMORRHAGE (Lower CL)'
 LPIQ19 ='IN-HOSP MORT HIP FRACTURE (Lower CL)'
 LPIQ20 ='IN-HOSP MORT PNEUMONIA (Lower CL)'
 LPIQ30 ='IN-HOSP MORT PTCA (Lower CL)'
 LPIQ31 ='IN-HOSP MORT CAROTID ENDARTERECTMY (LCL)'
 LPIQ32 ='IN-HOSP MORT AMI,w/o TRANSFERS(Lower CL)'
 ;

 LABEL
 UPIQ08 ='IN-HOSP MORT ESOPHL RESECTION (Upper CL)'
 UPIQ09 ='IN-HOSP MORT PANCRC RESECTION (Upper CL)'
 UPIQ11 ='IN-HOSP MORT AAA REPAIR (Upper CL)'
 UPIQ12 ='IN-HOSP MORT CABG (Upper CL)'
 UPIQ13 ='IN-HOSP MORT CRANIOTOMY (Upper CL)'
 UPIQ14 ='IN-HOSP MORT HIP REPLACEMENT (Upper CL)'
 UPIQ15 ='IN-HOSP MORT AMI (Upper CL)'
 UPIQ16 ='IN-HOSP MORT CHF (Upper CL)'
 UPIQ17 ='IN-HOSP MORT STROKE (Upper CL)'
 UPIQ18 ='IN-HOSP MORT GI HEMORRHAGE (Upper CL)'
 UPIQ19 ='IN-HOSP MORT HIP FRACTURE (Upper CL)'
 UPIQ20 ='IN-HOSP MORT PNEUMONIA (Upper CL)'
 UPIQ30 ='IN-HOSP MORT PTCA (Upper CL)'
 UPIQ31 ='IN-HOSP MORT CAROTID ENDARTERECTMY (UCL)'
 UPIQ32 ='IN-HOSP MORT AMI,w/o TRANSFERS(Upper CL)'
 ;

 LABEL
 SPIQ08 ='IN-HOSP MORT ESOPHL RESECTION (Smoothed)'
 SPIQ09 ='IN-HOSP MORT PANCRC RESECTION (Smoothed)'
 SPIQ11 ='IN-HOSP MORT AAA REPAIR (Smoothed)'
 SPIQ12 ='IN-HOSP MORT CABG (Smoothed)'
 SPIQ13 ='IN-HOSP MORT CRANIOTOMY (Smoothed)'
 SPIQ14 ='IN-HOSP MORT HIP REPLACEMENT (Smoothed)'
 SPIQ15 ='IN-HOSP MORT AMI (Smoothed)'
 SPIQ16 ='IN-HOSP MORT CHF (Smoothed)'
 SPIQ17 ='IN-HOSP MORT STROKE (Smoothed)'
 SPIQ18 ='IN-HOSP MORT GI HEMORRHAGE (Smoothed)'
 SPIQ19 ='IN-HOSP MORT HIP FRACTURE (Smoothed)'
 SPIQ20 ='IN-HOSP MORT PNEUMONIA (Smoothed)'
 SPIQ30 ='IN-HOSP MORT PTCA (Smoothed)'
 SPIQ31 ='IN-HOSP MORT CAROTID ENDARTERECTMY(Smth)'
 SPIQ32 ='IN-HOSP MORT AMI,w/o TRANSFERS(Smoothed)'
 ;

 LABEL
 XPIQ08 ='IN-HOSP MORT ESOPHL RESECTION (Smthe SE)'
 XPIQ09 ='IN-HOSP MORT PANCRC RESECTION (Smthe SE)'
 XPIQ11 ='IN-HOSP MORT AAA REPAIR (Smthe SE)'
 XPIQ12 ='IN-HOSP MORT CABG (Smthe SE)'
 XPIQ13 ='IN-HOSP MORT CRANIOTOMY (Smthe SE)'
 XPIQ14 ='IN-HOSP MORT HIP REPLACEMENT (Smthe SE)'
 XPIQ15 ='IN-HOSP MORT AMI (Smthe SE)'
 XPIQ16 ='IN-HOSP MORT CHF (Smthe SE)'
 XPIQ17 ='IN-HOSP MORT STROKE (Smthe SE)'
 XPIQ18 ='IN-HOSP MORT GI HEMORRHAGE (Smthe SE)'
 XPIQ19 ='IN-HOSP MORT HIP FRACTURE (Smthe SE)'
 XPIQ20 ='IN-HOSP MORT PNEUMONIA (Smthe SE)'
 XPIQ30 ='IN-HOSP MORT PTCA (Smthe SE)'
 XPIQ31 ='IN-HOSP MORT CAROTID ENDARTERECTMY(S SE)'
 XPIQ32 ='IN-HOSP MORT AMI,w/o TRANSFERS(Smthe SE)'
 ;

 RUN;

*==================================================================;
*  Title:  PROGRAM P3  PART II:  MERGE PROVIDER RATES FOR AHRQ
*  INPATIENT QUALITY INDICATORS
*
*  Description:  MERGED RATES FOR INPATIENT QUALITY INDICATORS
*
*          >>>  VERSION 4.0, August 2009 <<<
*
*===================================================================;

 TITLE2 'PROGRAM P3 PART II';
 TITLE3 'AHRQ INPATIENT QUALITY INDICATORS: PROVIDER-LEVEL MERGED FILES';

 * ---------------------------------------------------------------- ;
 * --- INPATIENT QUALITY INDICATOR MERGED RATES                   - ;
 * ---------------------------------------------------------------- ;

 DATA OUTP3.&OUTFILP3.;
 MERGE INP2.&INFILEP2.
   (KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT _TYPE_ 
         TPIQ01-TPIQ02 TPIQ04-TPIQ07 TPIQ21-TPIQ25 TPIQ33-TPIQ34 
         PPIQ21-PPIQ25 PPIQ33-PPIQ34 
         OPIQ21-OPIQ25 OPIQ33-OPIQ34)

       RISKADJ
   (KEEP=HOSPID AGECAT SEXCAT PAYCAT RACECAT 
         EPIQ08-EPIQ09 EPIQ11-EPIQ20 EPIQ30-EPIQ32
         RPIQ08-RPIQ09 RPIQ11-RPIQ20 RPIQ30-RPIQ32
         LPIQ08-LPIQ09 LPIQ11-LPIQ20 LPIQ30-LPIQ32 
         UPIQ08-UPIQ09 UPIQ11-UPIQ20 UPIQ30-UPIQ32
         SPIQ08-SPIQ09 SPIQ11-SPIQ20 SPIQ30-SPIQ32
         XPIQ08-XPIQ09 XPIQ11-XPIQ20 XPIQ30-XPIQ32
         VPIQ08-VPIQ09 VPIQ11-VPIQ20 VPIQ30-VPIQ32
         TPIQ08-TPIQ09 TPIQ11-TPIQ20 TPIQ30-TPIQ32
         PPIQ08-PPIQ09 PPIQ11-PPIQ20 PPIQ30-PPIQ32
         OPIQ08-OPIQ09 OPIQ11-OPIQ20 OPIQ30-OPIQ32);
 BY HOSPID AGECAT SEXCAT PAYCAT RACECAT;

 %INCLUDE MSXP;

 ARRAY TRRY1{7} _TEMPORARY_ (13 14 15 16 17 21 22);
 ARRAY TRRY2{7} OPIQ21 OPIQ22 OPIQ23 OPIQ24 OPIQ25 OPIQ33 OPIQ34;
 ARRAY TRRY3{7} PPIQ21 PPIQ22 PPIQ23 PPIQ24 PPIQ25 PPIQ33 PPIQ34;
 ARRAY TRRY4{7} EPIQ21 EPIQ22 EPIQ23 EPIQ24 EPIQ25 EPIQ33 EPIQ34;
 ARRAY TRRY5{7} RPIQ21 RPIQ22 RPIQ23 RPIQ24 RPIQ25 RPIQ33 RPIQ34;
 ARRAY TRRY6{7} SEIQ21 SEIQ22 SEIQ23 SEIQ24 SEIQ25 SEIQ33 SEIQ34;
 ARRAY TRRY7{7} VPIQ21 VPIQ22 VPIQ23 VPIQ24 VPIQ25 VPIQ33 VPIQ34;
 ARRAY TRRY8{7} SNIQ21 SNIQ22 SNIQ23 SNIQ24 SNIQ25 SNIQ33 SNIQ34;
 ARRAY TRRY9{7} SPIQ21 SPIQ22 SPIQ23 SPIQ24 SPIQ25 SPIQ33 SPIQ34;
 ARRAY TRRY10{7} XPIQ21 XPIQ22 XPIQ23 XPIQ24 XPIQ25 XPIQ33 XPIQ34;
 ARRAY TRRY11{7} LPIQ21 LPIQ22 LPIQ23 LPIQ24 LPIQ25 LPIQ33 LPIQ34;
 ARRAY TRRY12{7} UPIQ21 UPIQ22 UPIQ23 UPIQ24 UPIQ25 UPIQ33 UPIQ34;

 DO I = 1 TO 7;
    TRRY4(I) = ARRYP3(TRRY1(I));
    IF AGECAT = . AND SEXCAT = . AND PAYCAT = . AND RACECAT = . THEN DO;
       TRRY5(I)  = TRRY2(I);
       TRRY6(I)  = SQRT(TRRY2(I)*(1-TRRY2(I)) / TRRY3(I));
       TRRY7(I)  = TRRY6(I)**2;
       TRRY8(I)  = ARRYP2(TRRY1(I)) / (ARRYP2(TRRY1(I)) + TRRY7(I));
       TRRY9(I)  = (TRRY5(I) * TRRY8(I)) + ((1 -  TRRY8(I)) * ARRYP3(TRRY1(I)));
       TRRY10(I)  = SQRT(ARRYP2(TRRY1(I))- (TRRY8(I) * ARRYP2(TRRY1(I))));
    END;
    ELSE DO;
       TRRY3(I)  = (TRRY2(I) / TRRY4(I));
       TRRY6(I)  = SQRT(TRRY2(I)*(1-TRRY2(I)) / TRRY3(I)) / TRRY4(I);
       TRRY7(I)  = .;
       TRRY9(I)  = .;
       TRRY10(I)  = .;
    END;
    TRRY11(I)   = TRRY5(I) - (1.96 * TRRY6(I));
    IF TRRY11(I) < 0 THEN TRRY11(I) = 0;
    TRRY12(I)   = TRRY5(I) + (1.96 * TRRY6(I));
    IF TRRY12(I) > 1 THEN TRRY12(I) = 1;
 END;

 LABEL
 EPIQ21 ='CESAREAN SECTION DELIVERY (Expected)'
 EPIQ22 ='VAG BTH AFT C_SECTION,UNCOMPL (Expected)'
 EPIQ23 ='LAPAROSCOPIC CHOLECYSTECTOMY (Expected)'
 EPIQ24 ='INCIDENTAL APPENDECTOMY (Expected)'
 EPIQ25 ='BI-LATERAL CATHETERIZATION (Expected)'
 EPIQ33 ='PRIMARY CESAREAN SECTION (Expected)'
 EPIQ34 ='VBAC, ALL (Expected)'
 ;

 LABEL
 RPIQ21 ='CESAREAN SECTION DELIVERY (Risk Adj)'
 RPIQ22 ='VAG BTH AFT C_SECTION,UNCOMPL (Risk Adj)'
 RPIQ23 ='LAPAROSCOPIC CHOLECYSTECTOMY (Risk Adj)'
 RPIQ24 ='INCIDENTAL APPENDECTOMY (Risk Adj)'
 RPIQ25 ='BI-LATERAL CATHETERIZATION (Risk Adj)'
 RPIQ33 ='PRIMARY CESAREAN SECTION (Risk Adj)'
 RPIQ34 ='VBAC, ALL (Risk Adj)'
 ;

 LABEL
 LPIQ21 ='CESAREAN SECTION DELIVERY (Lower CL)'
 LPIQ22 ='VAG BTH AFT C_SECTION,UNCOMPL (Lower CL)'
 LPIQ23 ='LAPAROSCOPIC CHOLECYSTECTOMY (Lower CL)'
 LPIQ24 ='INCIDENTAL APPENDECTOMY (Lower CL)'
 LPIQ25 ='BI-LATERAL CATHETERIZATION (Lower CL)'
 LPIQ33 ='PRIMARY CESAREAN SECTION (Lower CL)'
 LPIQ34 ='VBAC, ALL (Lower CL)'
 ;

 LABEL
 UPIQ21 ='CESAREAN SECTION DELIVERY (Upper CL)'
 UPIQ22 ='VAG BTH AFT C_SECTION,UNCOMPL (Upper CL)'
 UPIQ23 ='LAPAROSCOPIC CHOLECYSTECTOMY (Upper CL)'
 UPIQ24 ='INCIDENTAL APPENDECTOMY (Upper CL)'
 UPIQ25 ='BI-LATERAL CATHETERIZATION (Upper CL)'
 UPIQ33 ='PRIMARY CESAREAN SECTION (Upper CL)'
 UPIQ34 ='VBAC, ALL (Upper CL)'
 ;

 LABEL
 SPIQ21 ='CESAREAN SECTION DELIVERY (Smoothed)'
 SPIQ22 ='VAG BTH AFT C-SECTION,UNCOMPL (Smoothed)'
 SPIQ23 ='LAPAROSCOPIC CHOLECYSTECTOMY (Smoothed)'
 SPIQ24 ='INCIDENTAL APPENDECTOMY (Smoothed)'
 SPIQ25 ='BI-LATERAL CATHETERIZATION (Smoothed)'
 SPIQ33 ='PRIMARY CESAREAN SECTION (Smoothed)'
 SPIQ34 ='VBAC, ALL (Smoothed)'
 ;

 LABEL
 XPIQ21 ='CESAREAN SECTION DELIVERY (Smthe SE)'
 XPIQ22 ='VAG BTH AFT C-SECTION,UNCOMPL (Smthe SE)'
 XPIQ23 ='LAPAROSCOPIC CHOLECYSTECTOMY (Smthe SE)'
 XPIQ24 ='INCIDENTAL APPENDECTOMY (Smthe SE)'
 XPIQ25 ='BI-LATERAL CATHETERIZATION (Smthe SE)'
 XPIQ33 ='PRIMARY CESAREAN SECTION (Smthe SE)'
 XPIQ34 ='VBAC, ALL (Smthe SE)'
 ;

 ARRAY ARRY1{22} EPIQ08-EPIQ09 EPIQ11-EPIQ25 EPIQ30-EPIQ34;
 ARRAY ARRY2{22} RPIQ08-RPIQ09 RPIQ11-RPIQ25 RPIQ30-RPIQ34;
 ARRAY ARRY3{22} LPIQ08-LPIQ09 LPIQ11-LPIQ25 LPIQ30-LPIQ34;
 ARRAY ARRY4{22} UPIQ08-UPIQ09 UPIQ11-UPIQ25 UPIQ30-UPIQ34;
 ARRAY ARRY5{22} SPIQ08-SPIQ09 SPIQ11-SPIQ25 SPIQ30-SPIQ34;
 ARRAY ARRY6{22} XPIQ08-XPIQ09 XPIQ11-XPIQ25 XPIQ30-XPIQ34;
 ARRAY ARRY7{22} VPIQ08-VPIQ09 VPIQ11-VPIQ25 VPIQ30-VPIQ34;
 ARRAY ARRY8{22} PPIQ08-PPIQ09 PPIQ11-PPIQ25 PPIQ30-PPIQ34;

 DO I = 1 TO 22;
   IF ARRY8(I) <= 2 THEN DO;
      ARRY1(I) = .; ARRY2(I) = .; ARRY3(I) = .; ARRY4(I) = .;
      ARRY5(I) = .; ARRY6(I) = .; ARRY7(I) = .; 
   END;
 END;

 DROP I;

 FORMAT EPIQ08 EPIQ09 EPIQ11 EPIQ12 EPIQ13 EPIQ14 EPIQ15 EPIQ16 
		EPIQ17 EPIQ18 EPIQ19 EPIQ20 EPIQ21 EPIQ22 EPIQ23 EPIQ24 
		EPIQ25 EPIQ30 EPIQ31 EPIQ32 EPIQ33 EPIQ34
		LPIQ08 LPIQ09 LPIQ11 LPIQ12 LPIQ13 LPIQ14 LPIQ15 LPIQ16
		LPIQ17 LPIQ18 LPIQ19 LPIQ20 LPIQ21 LPIQ22 LPIQ23 LPIQ24
		LPIQ25 LPIQ30 LPIQ31 LPIQ32 LPIQ33 LPIQ34 
		OPIQ08 OPIQ09 OPIQ11 OPIQ12 OPIQ13 OPIQ14 OPIQ15 OPIQ16
		OPIQ17 OPIQ18 OPIQ19 OPIQ20 OPIQ21 OPIQ22 OPIQ23 OPIQ24
		OPIQ25 OPIQ30 OPIQ31 OPIQ32 OPIQ33 OPIQ34 
		RPIQ08 RPIQ09 RPIQ11 RPIQ12 RPIQ13 RPIQ14 RPIQ15 RPIQ16
		RPIQ17 RPIQ18 RPIQ19 RPIQ20 RPIQ21 RPIQ22 RPIQ23 RPIQ24
		RPIQ25 RPIQ30 RPIQ31 RPIQ32 RPIQ33 RPIQ34 
		SEIQ21 SEIQ22 SEIQ23 SEIQ24 SEIQ25 SEIQ33 SEIQ34
		SNIQ21 SNIQ22 SNIQ23 SNIQ24 SNIQ25 SNIQ33 SNIQ34
		SPIQ08 SPIQ09 SPIQ11 SPIQ12 SPIQ13 SPIQ14 SPIQ15 SPIQ16
		SPIQ17 SPIQ18 SPIQ19 SPIQ20 SPIQ21 SPIQ22 SPIQ23 SPIQ24
		SPIQ25 SPIQ30 SPIQ31 SPIQ32 SPIQ33 SPIQ34
		UPIQ08 UPIQ09 UPIQ11 UPIQ12 UPIQ13 UPIQ14 UPIQ15 UPIQ16
		UPIQ17 UPIQ18 UPIQ19 UPIQ20 UPIQ21 UPIQ22 UPIQ23 UPIQ24
		UPIQ25 UPIQ30 UPIQ31 UPIQ32 UPIQ33 UPIQ34 
		VPIQ08 VPIQ09 VPIQ11 VPIQ12 VPIQ13 VPIQ14 VPIQ15 VPIQ16 
		VPIQ17 VPIQ18 VPIQ19 VPIQ20 VPIQ21 VPIQ22 VPIQ23 VPIQ24
		VPIQ25 VPIQ30 VPIQ31 VPIQ32 VPIQ33 VPIQ34 
		XPIQ08 XPIQ09 XPIQ11 XPIQ12 XPIQ13 XPIQ14 XPIQ15 XPIQ16
		XPIQ17 XPIQ18 XPIQ19 XPIQ20 XPIQ21 XPIQ22 XPIQ23 XPIQ24
		XPIQ25 XPIQ30 XPIQ31 XPIQ32 XPIQ33 XPIQ34 13.7
		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 13.0;

 RUN;

 * -------------------------------------------------------------- ;
 * --- CONTENTS AND MEANS OF PROVIDER-LEVEL MERGED FILE --------- ;
 * -------------------------------------------------------------- ;

 PROC CONTENTS DATA=OUTP3.&OUTFILP3. POSITION;
 RUN;

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

 * -------------------------------------------------------------- ;
 * --- PRINT PROVIDER MERGED FILE ------------------------------- ;
 * -------------------------------------------------------------- ;

 %MACRO PRT2;

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

 %MACRO PRT(IQ,TEXT,VOLUME);

 PROC  PRINT DATA=OUTP3.&OUTFILP3. LABEL SPLIT='*';
 %IF   &VOLUME = 0 %THEN %DO;
 VAR   HOSPID AGECAT SEXCAT PAYCAT RACECAT 
       TPIQ&IQ. PPIQ&IQ. OPIQ&IQ. EPIQ&IQ. RPIQ&IQ. LPIQ&IQ. UPIQ&IQ. SPIQ&IQ. XPIQ&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)"
       EPIQ&IQ.   = "EPIQ&IQ.*(Expected)"
       RPIQ&IQ.   = "RPIQ&IQ.*(Risk Adj)"
       LPIQ&IQ.   = "LPIQ&IQ.*(Lower CL)"
       UPIQ&IQ.   = "UPIQ&IQ.*(Upper CL)"
       SPIQ&IQ.   = "SPIQ&IQ.*(Smoothed)"
       XPIQ&IQ.   = "XPIQ&IQ.*(Smthe SE)"
       ;
 FORMAT AGECAT AGECAT.
        SEXCAT SEXCAT.
        PAYCAT PAYCAT.
        RACECAT RACECAT.
        TPIQ&IQ. PPIQ&IQ. 13.0 OPIQ&IQ. EPIQ&IQ. RPIQ&IQ. LPIQ&IQ. UPIQ&IQ. SPIQ&IQ. XPIQ&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 AGECAT AGECAT.
        SEXCAT SEXCAT.
        PAYCAT PAYCAT.
        RACECAT RACECAT.
        TPIQ&IQ. 13.0;
 %END;
 TITLE4 "FINAL OUTPUT";
 TITLE5 "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 TEXT;

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

 DATA _NULL_;
 SET OUTP3.&OUTFILP3;
 FILE IQTEXTP3 LRECL=3000;
 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" ","
 "EPIQ08" "," "EPIQ09" "," "EPIQ11" "," "EPIQ12" ","
 "EPIQ13" "," "EPIQ14" "," "EPIQ15" "," "EPIQ16" ","
 "EPIQ17" "," "EPIQ18" "," "EPIQ19" "," "EPIQ20" ","
 "EPIQ21" "," "EPIQ22" "," "EPIQ23" "," "EPIQ24" ","
 "EPIQ25" "," "EPIQ30" "," "EPIQ31" "," "EPIQ32" "," 
 "EPIQ33" "," "EPIQ34" ","
 "RPIQ08" "," "RPIQ09" "," "RPIQ11" "," "RPIQ12" ","
 "RPIQ13" "," "RPIQ14" "," "RPIQ15" "," "RPIQ16" ","
 "RPIQ17" "," "RPIQ18" "," "RPIQ19" "," "RPIQ20" ","
 "RPIQ21" "," "RPIQ22" "," "RPIQ23" "," "RPIQ24" ","
 "RPIQ25" "," "RPIQ30" "," "RPIQ31" "," "RPIQ32" "," 
 "RPIQ33" "," "RPIQ34" ","
 "LPIQ08" "," "LPIQ09" "," "LPIQ11" "," "LPIQ12" ","
 "LPIQ13" "," "LPIQ14" "," "LPIQ15" "," "LPIQ16" ","
 "LPIQ17" "," "LPIQ18" "," "LPIQ19" "," "LPIQ20" ","
 "LPIQ21" "," "LPIQ22" "," "LPIQ23" "," "LPIQ24" ","
 "LPIQ25" "," "LPIQ30" "," "LPIQ31" "," "LPIQ32" "," 
 "LPIQ33" "," "LPIQ34" ","
 "UPIQ08" "," "UPIQ09" "," "UPIQ11" "," "UPIQ12" ","
 "UPIQ13" "," "UPIQ14" "," "UPIQ15" "," "UPIQ16" ","
 "UPIQ17" "," "UPIQ18" "," "UPIQ19" "," "UPIQ20" ","
 "UPIQ21" "," "UPIQ22" "," "UPIQ23" "," "UPIQ24" ","
 "UPIQ25" "," "UPIQ30" "," "UPIQ31" "," "UPIQ32" "," 
 "UPIQ33" "," "UPIQ34" ","
 "SPIQ08" "," "SPIQ09" "," "SPIQ11" "," "SPIQ12" ","
 "SPIQ13" "," "SPIQ14" "," "SPIQ15" "," "SPIQ16" ","
 "SPIQ17" "," "SPIQ18" "," "SPIQ19" "," "SPIQ20" ","
 "SPIQ21" "," "SPIQ22" "," "SPIQ23" "," "SPIQ24" ","
 "SPIQ25" "," "SPIQ30" "," "SPIQ31" "," "SPIQ32" "," 
 "SPIQ33" "," "SPIQ34" "," 
 "XPIQ08" "," "XPIQ09" "," "XPIQ11" "," "XPIQ12" ","
 "XPIQ13" "," "XPIQ14" "," "XPIQ15" "," "XPIQ16" ","
 "XPIQ17" "," "XPIQ18" "," "XPIQ19" "," "XPIQ20" ","
 "XPIQ21" "," "XPIQ22" "," "XPIQ23" "," "XPIQ24" ","
 "XPIQ25" "," "XPIQ30" "," "XPIQ31" "," "XPIQ32" "," 
 "XPIQ33" "," "XPIQ34"  
 ;

 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 ",")  ","
 (EPIQ08-EPIQ09 EPIQ11-EPIQ25 EPIQ30-EPIQ34) (12.10 ",")  ","
 (RPIQ08-RPIQ09 RPIQ11-RPIQ25 RPIQ30-RPIQ34) (12.10 ",")  ","
 (LPIQ08-LPIQ09 LPIQ11-LPIQ25 LPIQ30-LPIQ34) (12.10 ",")  ","
 (UPIQ08-UPIQ09 UPIQ11-UPIQ25 UPIQ30-UPIQ34) (12.10 ",")  ","
 (SPIQ08-SPIQ09 SPIQ11-SPIQ25 SPIQ30-SPIQ34) (12.10 ",")  ","
 (XPIQ08-XPIQ09 XPIQ11-XPIQ25 XPIQ30-XPIQ34) (12.10 ",") 
 ;

 RUN;

 %END;

 %MEND TEXT;

 %TEXT;

