*===================================================================;
*  Title:  PSI COMPOSITE CONSTRUCTS COMPOSITE MEASURE FOR 
*          PATIENT SAFETY INDICATORS
*
*  Description:
*         CONSTRUCTS A COMPOSITE MEASURE BASED ON USER DEFINED
*         WEIGHTS (DEFAULT IS EQUAL WEIGHTS)
*
*          >>>  VERSION 4.2, September 2010 <<<
*
*  USER NOTE:  Make sure you have run through PSSASP3.SAS 
*              BEFORE running this program.
*
*===================================================================;
LIBNAME IN1 "C:\PATHNAME";
LIBNAME OUT1 "C:\PATHNAME";
FILENAME MSXC "C:\PATHNAME\MSXPSC42.TXT";

%LET INFILE = PSP3;
%LET OUTFILE = PSC3;
%LET PRINT = 0;

*===================================================================;
*  PATIENT SAFETY FOR SELECTED INDICATORS                         --;
*  ASSIGN INDICATOR WEIGHTS                                       --;
*    WEIGHTS MUST SUM TO 1.0                                      --;
*===================================================================;
%LET W03 = 0.2403;
%LET W06 = 0.0457;
%LET W07 = 0.1280;
%LET W08 = 0.0011;
%LET W09 = 0.0000;
%LET W10 = 0.0000;
%LET W11 = 0.0000;
%LET W12 = 0.2360;
%LET W13 = 0.0383;
%LET W14 = 0.0124;
%LET W15 = 0.2983;

*===================================================================;
*  COMPUTE COMPOSITE                                              --;
*===================================================================;

DATA OUT1.&OUTFILE.(KEEP=HOSPID COMP1 COMP1VAR COMP1SE COMP1WHT);
SET IN1.&INFILE.;

%INCLUDE MSXC;

ARRAY ARRY4{11} 
   RPPS03 RPPS06 RPPS07 RPPS08 RPPS09 RPPS10
   RPPS11 RPPS12 RPPS13 RPPS14 RPPS15
;

ARRAY ARRY6{11} 
   VPPS03 VPPS06 VPPS07 VPPS08 VPPS09 VPPS10 
   VPPS11 VPPS12 VPPS13 VPPS14 VPPS15
;

ARRAY ARRY7{11} 
   APPS03 APPS06 APPS07 APPS08 APPS09 APPS10 
   APPS11 APPS12 APPS13 APPS14 APPS15
;

ARRAY ARRY12{11} _temporary_
   (&W03. &W06. &W07. &W08. &W09. &W10. 
    &W11. &W12. &W13. &W14. &W15.)
;

ARRAY ARRY13{11} 
   PPPS03 PPPS06 PPPS07 PPPS08 PPPS09 PPPS10 
   PPPS11 PPPS12 PPPS13 PPPS14 PPPS15
;

DO I = 1 TO 11;
   IF ARRY13(I) GE 3 THEN DO;
      ARRY6(I) = ARRY6(I) / (ARRYP3(I) * ARRYP3(I));
      DO J = I TO 11;
         IDX = ARRY10(I,J);
         IF I = J THEN ARRY7(I) = ARRY1(IDX) / (ARRY1(IDX) + ARRY6(I));
      END;
   END;
   ELSE DO;
      DO J = I TO 11;
         IDX = ARRY10(I,J);
         IF I = J THEN ARRY7(I) = 0;
      END;
   END;
END;

COMP1    = 0;
COMP1VAR = 0;
COMP1SE  = 0;
COMP1WHT = 0;

DO I = 1 TO 11;
   IF ARRY13(I) GE 3 THEN DO;
      COMP1 = COMP1 + (ARRY12(I) * (((ARRY4(I) / ARRYP3(I)) * ARRY7(I)) + (1 - ARRY7(I))));
      COMP1WHT = COMP1WHT + (ARRY12(I) * ARRY13(I));
   END;
   ELSE DO;
      COMP1 = COMP1 + ARRY12(I);
      COMP1WHT = COMP1WHT + 0;
   END;
   DO J = I TO 11;
      IDX = ARRY10(I,J);
      IF I = J THEN COMP1VAR = COMP1VAR 
      + (ARRY12(I) * (ARRY1(IDX) * (1 - ARRY7(I))) * ARRY12(J));
      ELSE COMP1VAR = COMP1VAR 
      + (ARRY12(I) * (ARRY1(IDX) * (1 - ARRY7(I)) * (1 - ARRY7(J))) * ARRY12(J));
   END;
END;

COMP1SE  = SQRT(COMP1VAR);

LABEL
  COMP1    = 'PATIENT SAFETY FOR SELECTED INDICATORS'
  COMP1VAR = 'COMPOSITE VARIANCE'
  COMP1SE  = 'COMPOSITE SE'
  COMP1WHT = 'COMPOSITE WEIGHTED DENOMINATOR'
;

RUN;

PROC MEANS DATA=OUT1.&OUTFILE. N MEAN;
TITLE 'PATIENT SAFETY INDICATOR COMPOSITE';
VAR COMP1 COMP1VAR COMP1SE COMP1WHT;
RUN;

%MACRO PRT;

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

PROC PRINT DATA=OUT1.&OUTFILE.;
TITLE 'INPATIENT QUALITY INDICATOR COMPOSITES';
VAR HOSPID
    COMP1 COMP1VAR COMP1SE COMP1WHT;
RUN;

%END;

%MEND;

%PRT;

