*==================================================================;
*  Title:  PROGRAM A3 PART I:  CALCULATE RISK-ADJUSTED AREA RATES FOR
*          AHRQ PREVENTION QUALITY INDICATORS
*
*  Description:
*         USES PROC SCORE TO CALCULATE RISK-ADJUSTED RATES FOR PREVENTION
*         QUALITY INDICATORS.
*         ADJUSTS FOR: AGE AND SEXCAT.
*
*          >>>  VERSION 2.1 (revision 4), November 2004 <<<
*
*===================================================================;
FILENAME CONTROL 'c:\pathname\CONTROL_PQI.SAS'; *<===USER MUST modify;

%INCLUDE CONTROL;

%MACRO AREA;
   %IF &MSALEVL EQ 1 %THEN MSA;
      %ELSE HOSPSTCO;
%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 SUM2MSA;
    %IF &MSALEVL EQ 1 %THEN %DO;
        PROC SUMMARY NWAY;
            CLASS MSA POPCAT SEXCAT;
            VAR POP;
            OUTPUT OUT=QIPOP (DROP=_TYPE_ _FREQ_) SUM=;
        RUN;
    %END;
%MEND;

 TITLE2 'PROGRAM A3 PART I';
 TITLE3 'AHRQ PREVENTION QUALITY INDICATORS: CALCULATE ADJUSTED AREA RATES';

 * ---------------------------------------------------------------- ;
 * --- ADD POPULATION DENOMINATOR --------------------------------- ;
 * --- THIS STEP DETERMINES WHICH AREAS ARE INCLUDED IN THE     --- ;
 * --- OUTPUT FROM PROGRAM A1.                                  --- ;
 * ---------------------------------------------------------------- ;

 PROC   SORT DATA=IN3.&INFILEA3. (KEEP=%AREA) OUT=%AREA NODUPKEY;
 BY     %AREA;
 RUN;


 DATA   QIPOP;
 LENGTH HOSPSTCO 8 POPCAT 3 SEXCAT $1 ;
 INFILE POPFILE3 MISSOVER;
 INPUT  HOSPSTCO POPCAT SEXCAT POP;
 %CTY2MSA
 RUN;

 %SUM2MSA

 PROC   SORT DATA=QIPOP;
 BY     %AREA POPCAT SEXCAT;
 RUN;

 DATA   QIPOP;
 MERGE  %AREA(IN=X) QIPOP;
 BY     %AREA;
 IF X;
 RUN;

 * -------------------------------------------------------------- ;
 * --- PREVENTION QUALITY INDICATORS ADJUSTED RATES ------------- ;
 * -------------------------------------------------------------- ;
 * --- THIS STEP SELECTS THE OBSERVATIONS FROM THE PROGRAM A1 --- ;
 * --- OUTPUT FOR EACH PREVENTION QUALITY INDICATOR IN TURN.  --- ;
 * --- EACH ITERATION PASSES VARIABLES THAT CONTROL THE       --- ;
 * --- COVARIATES FOR THAT PREVENTION QUALITY INDICATOR:      --- ;
 * --- N - OBSERVATION NUMBER FROM THE MEANS AND COVAR FILES  --- ;
 * ---     ALSO IDENTIFIES THE FORMAT USED TO INDEX COVARIATES -- ;
 * --- PQ - THE PREVENTION QUALITY INDICATOR NAME WITHOUT THE --- ;
 *          PREFIX (A)                                        --- ;
 * --- A - THE NUMBER OF DEMOGRAPHIC CATEGORIES (AGE AND SEX) --- ;
 * --- S - DETERMINES WHETHER AGE*SEX INTERACTIONS ARE NEEDED --- ;
 * --- O - DETERMINES THE OMITTED AGE CATEGORY IN FORMAT      --- ;
 * -------------------------------------------------------------- ;

 %MACRO MOD3(N,PQ,A,S,O);

 * --- THIS SET CREATES TEMP1 WHICH CONTAINS THE DEPENDENT    --- ;
 * --- VARIABLE (TPQ) AND INDEPENDENT VARIABLES USED IN       --- ;
 * --- REGRESSION.  IT APPENDS TO THE DISCHARGE DATA ONE      --- ;
 * --- OBSERVATION PER %AREA AND DEMOGRAPHIC GROUP.            --- ;

 DATA   TEMP1(KEEP=KEY %AREA T&PQ. SEX AGE1-AGE%EVAL(2*&A.) AIDX POP MERGEVAR);
 LENGTH AGE1-AGE%EVAL(2*&A.) AIDX 8;
 SET    IN3.&INFILEA3.(KEEP=KEY %AREA T&PQ. SEXCAT AGECAT AGE)
        QIPOP;

 * --- KEEP ONLY DISCHARGES/AREA/DEMOG GRP NEEDED FOR THIS    --- ;
 * --- PREVENTION QUALITY INDICATOR                           --- ;
 N = &N.;
 
 if %AREA eq . then delete;

 IF POP > 0 AND N NOTIN (2,9) THEN T&PQ. = 0;

 IF AGECAT IN ('1') OR POPCAT in (1,2,3,4) THEN DO;
   IF N IN (1,3,5,7,8,13,14,15,16)
     THEN T&PQ. = .;
 END;
 ELSE IF AGECAT IN ('2') OR POPCAT in (5,6,7,8) THEN DO;
   IF N IN (4,6,9)
     THEN T&PQ. = .;
 END;
 ELSE IF AGECAT IN ('3','4') OR
         POPCAT in (9,10,11,12,13,14,15,16,17,18) THEN DO;
   IF N IN (4,6,9)
     THEN T&PQ. = .;
 END;

 IF T&PQ. NE .;

 * --- INITIALIZE COVARIATE DUMMIES TO ZERO                   --- ;
 ARRAY AGEX{%EVAL(2*&A.)} AGE1-AGE%EVAL(2*&A.);

 SEX = 0;
 DO I = 1 TO %EVAL(2*&A.);
   AGEX(I)=0;
 END;

 * --- SET INDEX FOR AGE ARRAY (AIDX).  CATEGORIES VARY BY    --- ;
 * --- PREVENTION QUALITY INDICATOR AND ARE DETERMINED BY THE --- ;
 * --- FORMAT CORRESPONDING TO N                              --- ;
 IF AGE > 0 THEN AIDX = PUT(AGE,A&N.PQFMT.);
 ELSE IF POP > 0 THEN DO;
   AIDX = POPCAT;
   IF AIDX = &O. THEN AIDX = 0;
 END;
 ELSE AIDX = 0;

 * --- SET APPROPRIATE COVARIATE DUMMY TO 1 FOR THIS DISCHARGE -- ;
 IF SEXCAT IN (&S.) THEN SEX = 1;
 IF AIDX > 0 THEN DO; AGEX(AIDX) = 1; AGEX(&A.+AIDX) = 1 * SEX; END;

 MERGEVAR = 1;

 RUN;

 PROC   SORT DATA=TEMP1;
 BY %AREA SEX AIDX POP;
 RUN;

 * --- THIS DATA STEP SUBTRACTS THE NUMBER OF DISCHARGES FROM --- ;
 * --- THE %AREA/DEMOGRAPHIC GROUP POPULATION COUNT.  IT SETS A -- ;
 * --- WEIGHT OF 1 FOR EACH OBSERVATION FROM THE DISCHARGE DATA - ;
 * --- AND A WEIGHT OF (POP-DISCHARGES) FOR THE APPENDED OBS  --- ;
 * --- FOR EACH %AREA/DEMOGRAPHIC GROUP.                       --- ;

 DATA   TEMP1(KEEP=KEY %AREA T&PQ. SEX AGE1-AGE%EVAL(2*&A.) WHT MERGEVAR);
 SET    TEMP1;
 BY %AREA SEX AIDX;

 RETAIN WCNT 0;

 IF FIRST.AIDX THEN WCNT = 0;

 IF POP > 0 THEN WHT = POP - WCNT;
 ELSE WHT = 1;

 WCNT + 1;

 RUN;
 
 

 * --- THIS DATA STEP READS THE OVERALL MEAN FILE FOR THIS    --- ;
 * --- PREVENTION QUALITY INDICATOR.  THE F VARIABLES ARE     --- ;
 * --- FILLERS.                                               --- ;

 DATA   TEMP1M(DROP=N F1-F%EVAL(40-(2*&A.)));
 LENGTH N F1-F%EVAL(40-(2*&A.)) 3 MSEX MAGE1-MAGE%EVAL(2*&A.) 8;
 INFILE MEANSA MISSOVER LRECL=1000;
 INPUT N MSEX MAGE1-MAGE%EVAL(2*&A.) F1-F%EVAL(40-(2*&A.));

 MERGEVAR = 1;

 IF N = &N.;

 RUN;

 * --- THIS DATA STEP SUBTRACTS THE OVERALL MEAN OF THE        --- ;
 * --- INDEPENDENT VARIABLES FROM THE INDEPENDENT VARIABLES ON --- ;
 * --- EACH OBSERVATION.  THIS WAY THE ADJUSTED AREA RATE IS THE - ;
 * --- RATE FOR THE AVERAGE PERSON, RATHER THEN FOR THE OMITTED -- ;
 * --- CATEGORY.                                               --- ;

 DATA   TEMP1(KEEP=KEY %AREA T&PQ. SEX AGE1-AGE%EVAL(2*&A.) WHT);
 MERGE  TEMP1 TEMP1M;
 BY     MERGEVAR;

 ARRAY  COVAR{%EVAL(1+(2*&A.))}  SEX  AGE1-AGE%EVAL(2*&A.);
 ARRAY  MEANS{%EVAL(1+(2*&A.))} MSEX MAGE1-MAGE%EVAL(2*&A.);

 DO I = 1 TO %EVAL(1+(2*&A.));
   COVAR(I) = COVAR(I) - MEANS(I);
 END;

 RUN;
 
 * --- THIS DATA STEP READS THE REGRESSION COEFFICIENTS FOR EACH - ;
 * --- COVARIATE.                                              --- ;

 DATA   TEMP2(KEEP=INTERCEP SEX AGE1-AGE%EVAL(2*&A.) _TYPE_ _MODEL_ _DEPVAR_ T&PQ.);
 LENGTH INTERCEP SEX AGE1-AGE%EVAL(2*&A.) F1-F%EVAL(40-(2*&A.)) T&PQ. 8
        _TYPE_ _MODEL_ _DEPVAR_ $8;
 INFILE COVARA MISSOVER LRECL=1000;
 INPUT  N INTERCEP SEX AGE1-AGE%EVAL(2*&A.) F1-F%EVAL(40-(2*&A.))
        _DEPVAR_ _MODEL_ _TYPE_ _RMSE_ T&PQ.;

 IF N = &N.;

 RUN;

 * --- THIS PROC CALCULATES A PREDICTED PREVENTION QUALITY      --- ;
 * --- INDICATOR FOR EACH OBSERVATION USING THE ACTUAL COVARIATES - ;
 * --- AND THE ESTIMATED COEFFICIENTS.  THE COEFFICENTS HAVE BEEN - ;
 * --- ESTIMATED ON A DE-MEANED SAMPLE, WHERE THE %AREA EFFECTS  --- ;
 * --- HAVE BEEN AVERAGED OUT.  THEN THE %AREA EFFECT IS         --- ;
 * --- CALCULATED BY SUBTRACTING THE PREDICTION FROM THE ACTUAL --- ;
 * --- ON EACH OBSERVATION, AND CALCULATING THE MEAN DIFFERENCE --- ;
 * --- FOR THE %AREA.                                            --- ;
 * --- FOR A DISCUSSION OF THIS METHOD, PLEASE REFER TO GREENE, --- ;
 * --- WILLIAN H, ECONOMETRIC ANALYSIS, 2ND ED (1990) P. 466-69 --- ;

 PROC   SCORE DATA=TEMP1 SCORE=TEMP2 TYPE=PARMS OUT=TEMP1Y;
 VAR    SEX AGE1-AGE%EVAL(2*&A.);
 RUN;

 DATA   TEMP1Y;
 SET    TEMP1Y;

 EHAT = T&PQ. - MHAT;
 ONE = 1;

 RUN;

 PROC   SUMMARY DATA=TEMP1Y ;
 CLASS  %AREA;
 VAR    EHAT ONE;
 OUTPUT OUT=R&PQ. MEAN(EHAT)=R&PQ. SUM(ONE)=P&PQ.;
 WEIGHT WHT;
 RUN;

 %MEND;

 %MOD3(1,APQ01,18,'F',6);
 %MOD3(2,APQ02,4,'F',0);
 %MOD3(3,APQ03,18,'F',10);
 %MOD3(4,APQ04,18,'F',1);
 %MOD3(5,APQ05,18,'F',12);
 %MOD3(6,APQ06,18,'F',1);
 %MOD3(7,APQ07,18,'F',10);
 %MOD3(8,APQ08,18,'F',13);
 %MOD3(9,APQ09,2,'F',0);
 %MOD3(10,APQ10,18,'F',1);
 %MOD3(11,APQ11,18,'F',5);
 %MOD3(12,APQ12,18,'F',6);
 %MOD3(13,APQ13,18,'F',11);
 %MOD3(14,APQ14,18,'F',8);
 %MOD3(15,APQ15,18,'F',7);
 %MOD3(16,APQ16,18,'F',11);

 * --- MERGES THE %AREA ADJUSTED RATES FOR EACH PREVENTION QUALITY - ;
 * --- INDICATOR.  PREFIX FOR THE ADJUSTED RATES IS R(Risk      --- ;
 * --- Adjusted).                                               --- ;

 DATA   RISKADJ;
 LENGTH RAPQ01-RAPQ16 PAPQ01-PAPQ16 8;
 MERGE  RAPQ01(KEEP=%AREA RAPQ01 PAPQ01)
        RAPQ02(KEEP=%AREA RAPQ02 PAPQ02)
        RAPQ03(KEEP=%AREA RAPQ03 PAPQ03)
        RAPQ04(KEEP=%AREA RAPQ04 PAPQ04)
        RAPQ05(KEEP=%AREA RAPQ05 PAPQ05)
        RAPQ06(KEEP=%AREA RAPQ06 PAPQ06)
        RAPQ07(KEEP=%AREA RAPQ07 PAPQ07)
        RAPQ08(KEEP=%AREA RAPQ08 PAPQ08)
        RAPQ09(KEEP=%AREA RAPQ09 PAPQ09)
        RAPQ10(KEEP=%AREA RAPQ10 PAPQ10)
        RAPQ11(KEEP=%AREA RAPQ11 PAPQ11)
        RAPQ12(KEEP=%AREA RAPQ12 PAPQ12)
        RAPQ13(KEEP=%AREA RAPQ13 PAPQ13)
        RAPQ14(KEEP=%AREA RAPQ14 PAPQ14)
        RAPQ15(KEEP=%AREA RAPQ15 PAPQ15)
        RAPQ16(KEEP=%AREA RAPQ16 PAPQ16);
 BY     %AREA;

 LABEL
 RAPQ01 = 'DIABETES SHORT TRM COMPLICATN (Risk Adj)'
 RAPQ02 = 'PERFORATED APPENDIX           (Risk Adj)'
 RAPQ03 = 'DIABETES LONG TERM COMPLICATN (Risk Adj)'
 RAPQ04 = 'PEDIATRIC ASTHMA              (Risk Adj)'
 RAPQ05 = 'COPD                          (Risk Adj)'
 RAPQ06 = 'PEDIATRIC GASTROENTERITIS     (Risk Adj)'
 RAPQ07 = 'HYPERTENSION                  (Risk Adj)'
 RAPQ08 = 'CONGESTIVE HEART FAILURE      (Risk Adj)'
 RAPQ09 = 'LOW BIRTH WEIGHT              (Risk Adj)'
 RAPQ10 = 'DEHYDRATION                   (Risk Adj)'
 RAPQ11 = 'BACTERIAL PNEUMONIA           (Risk Adj)'
 RAPQ12 = 'URINARY INFECTION             (Risk Adj)'
 RAPQ13 = 'ANGINA                        (Risk Adj)'
 RAPQ14 = 'DIABETES UNCONTROLLED         (Risk Adj)'
 RAPQ15 = 'ADULT ASTHMA                  (Risk Adj)'
 RAPQ16 = 'LOWER EXTREMITY AMPUTATION    (Risk Adj)'
 ;

 LABEL
 PAPQ01 = 'DIABETES SHORT TRM CMPLICTN(Denominator)'
 PAPQ02 = 'PERFORATED APPENDIX        (Denominator)'
 PAPQ03 = 'DIABETES LONG TRM CMPLICTN (Denominator)'
 PAPQ04 = 'PEDIATRIC ASTHMA           (Denominator)'
 PAPQ05 = 'COPD                       (Denominator)'
 PAPQ06 = 'PEDIATRIC GASTROENTERITIS  (Denominator)'
 PAPQ07 = 'HYPERTENSION               (Denominator)'
 PAPQ08 = 'CONGESTIVE HEART FAILURE   (Denominator)'
 PAPQ09 = 'LOW BIRTH WEIGHT           (Denominator)'
 PAPQ10 = 'DEHYDRATION                (Denominator)'
 PAPQ11 = 'BACTERIAL PNEUMONIA        (Denominator)'
 PAPQ12 = 'URINARY INFECTION          (Denominator)'
 PAPQ13 = 'ANGINA                     (Denominator)'
 PAPQ14 = 'DIABETES UNCONTROLLED      (Denominator)'
 PAPQ15 = 'ADULT ASTHMA               (Denominator)'
 PAPQ16 = 'LOWER EXTREMITY AMPUTATION (Denominator)'
        ;

 ARRAY ARRY1{16} RAPQ01--RAPQ16;
 DO I = 1 TO 16;
   IF ARRY1(I) < 0 THEN ARRY1(I) = 0;
   ELSE IF ARRY1(I) > 1 THEN ARRY1(I) = 1;
 END;

 DROP I;

 RUN;

*==================================================================;
*  Title:  PROGRAM A3  PART II:  CALCULATE SMOOTHED %AREA RATES FOR
*  AHRQ PREVENTION QUALITY INDICATORS.
*
*  Description:
*         CALCULATE SMOOTHED RATES FOR PREVENTION QUALITY INDICATORS
*
*                 >>>  VERSION 2.1  <<<
*
*===================================================================;

 TITLE2 'PROGRAM A3  PART II';
 TITLE3 'AHRQ PREVENTION QUALITY INDICATORS: CALCULATE SMOOTHED AREA RATES';

 * ---------------------------------------------------------------- ;
 * --- PREVENTION QUALITY INDICATOR SMOOTHED RATES              --- ;
 * ---   IN UNIVARIATE MODEL, SMOOTHED AREA ESTIMATE IS DEMEANED -- ;
 * ---   AREA RATE * (SIGNAL / (SIGNAL + NOISE)                 --- ;
 * ---------------------------------------------------------------- ;

 DATA   SMOOTHED(DROP=RAPQ01-RAPQ16);
 SET    RISKADJ;

 %INCLUDE MSX;

 ARRAY ARRYA{16} RAPQ01-RAPQ16;
 ARRAY ARRYN{16} PAPQ01-PAPQ16;
 ARRAY ARRYX{16} SAPQ01-SAPQ16;

 DO I = 1 TO 16;
   ARRYX(I) = ARRYA(I) - ARRYA3(I);
   IF ARRYN(I) NE 0 AND ARRYA2(I) NE 0 THEN
      ARRYX(I) = ARRYX(I) * (ARRYA2(I) / (ARRYA2(I) + (ARRYA1(I) / ARRYN(I))));
   ELSE ARRYX(I)=.;
   ARRYX(I) = ARRYX(I) + ARRYA3(I);
 END;

 LABEL
 SAPQ01 = 'DIABETES SHORT TRM COMPLICATN (Smoothed)'
 SAPQ02 = 'PERFORATED APPENDIX           (Smoothed)'
 SAPQ03 = 'DIABETES LONG TERM COMPLICATN (Smoothed)'
 SAPQ04 = 'PEDIATRIC ASTHMA              (Smoothed)'
 SAPQ05 = 'COPD                          (Smoothed)'
 SAPQ06 = 'PEDIATRIC GASTROENTERITIS     (Smoothed)'
 SAPQ07 = 'HYPERTENSION                  (Smoothed)'
 SAPQ08 = 'CONGESTIVE HEART FAILURE      (Smoothed)'
 SAPQ09 = 'LOW BIRTH WEIGHT              (Smoothed)'
 SAPQ10 = 'DEHYDRATION                   (Smoothed)'
 SAPQ11 = 'BACTERIAL PNEUMONIA           (Smoothed)'
 SAPQ12 = 'URINARY INFECTION             (Smoothed)'
 SAPQ13 = 'ANGINA                        (Smoothed)'
 SAPQ14 = 'DIABETES UNCONTROLLED         (Smoothed)'
 SAPQ15 = 'ADULT ASTHMA                  (Smoothed)'
 SAPQ16 = 'LOWER EXTREMITY AMPUTATION    (Smoothed)'
 ;

 DROP I;

 RUN;


*==================================================================;
*  Title:  PROGRAM A3  PART III:  MERGE AREA RATES FOR HCUP
*          PREVENTION QUALITY INDICATORS
*
*  Description:  MERGE RATES FOR PREVENTION QUALITY INDICATORS
*
*                 >>>  VERSION 2.1  <<<
*
*===================================================================;

 TITLE2 'PROGRAM A3  PART III';
 TITLE3 'AHRQ PREVENTION QUALITY INDICATORS:  AREA-LEVEL MERGED FILES';

 * ---------------------------------------------------------------- ;
 * --- PREVENTION QUALITY INDICATOR MERGED RATES                --- ;
 * ---------------------------------------------------------------- ;

 DATA   OUT3.&OUTFILA3.;
 MERGE  IN3.&INFILEA2. (WHERE=(_TYPE_ IN(0,8))
               KEEP=%AREA _TYPE_ TAPQ01-TAPQ16 PAPQ01-PAPQ16 OAPQ01-OAPQ16)
            RISKADJ(KEEP=%AREA RAPQ01-RAPQ16)
            SMOOTHED(KEEP=%AREA SAPQ01-SAPQ16) ;
 BY     %AREA;
 RUN;

 * ---------------------------------------------------------------- ;
 * --- CONTENTS AND MEANS OF %AREA MERGED MEANS FILE             --- ;
 * ---------------------------------------------------------------- ;

 PROC CONTENTS DATA=OUT3.&OUTFILA3. POSITION;
 RUN;

 PROC MEANS DATA=OUT3.&OUTFILA3.(WHERE=(_TYPE_ IN (8))) N NMISS MIN MAX MEAN SUM;
 TITLE4  'SUMMARY OF AREA-LEVEL RATES (_TYPE_=8)';
 RUN;

 * ---------------------------------------------------------------- ;
 * --- PRINT AREA MERGED MEANS FILE                             --- ;
 * ---------------------------------------------------------------- ;

%MACRO PRT (PQ,TEXT);
    PROC   PRINT DATA=OUT3.&OUTFILA3. LABEL SPLIT='*';
    VAR    %AREA TAPQ&PQ. PAPQ&PQ. OAPQ&PQ. RAPQ&PQ. SAPQ&PQ.;
    LABEL %AREA    = "%AREA"
       TAPQ&PQ.   = "TAPQ&PQ.*(Numerator)"
       PAPQ&PQ.   = "PAPQ&PQ.*(Denominator)"
       OAPQ&PQ.   = "OAPQ&PQ.*(Observed)"
       RAPQ&PQ.   = "RAPQ&PQ.*(Risk Adj)"
       SAPQ&PQ.   = "SAPQ&PQ.*(Smoothed)"
    ;
    FORMAT TAPQ&PQ. PAPQ&PQ. 13.0 OAPQ&PQ. RAPQ&PQ. SAPQ&PQ. 8.6;
    TITLE4 "FINAL OUTPUT";
    TITLE5 "Indicator # &PQ.:  &TEXT";
    RUN;
%MEND;

 %MACRO PRT2;
    %IF &PRINT. = 1 %THEN %DO;
        %PRT(01,DIABETES SHORT TERM CX);
        %PRT(02,PERFORATED APPENDIX);
        %PRT(03,DIABETES LONG TERM CX);
        %PRT(04,PEDIATRIC ASTHMA);
        %PRT(05,COPD);
        %PRT(06,PEDIATRIC GASTROENTERITIS);
        %PRT(07,HYPERTENSION);
        %PRT(08,CHF);
        %PRT(09,LOW BIRTH WEIGHT);
        %PRT(10,DEHYDRATION);
        %PRT(11,BACTERIAL PNEUMONIA);
        %PRT(12,URINARY INFECTION);
        %PRT(13,ANGINA W/O PROCEDURES);
        %PRT(14,DIABETES UNCONTROLLED);
        %PRT(15,ADULT ASTHMA);
        %PRT(16,LOWER EXTREMITY AMPUTATION DM);
    %END;
 %MEND PRT2 ;

 %PRT2;


 * ---------------------------------------------------------------- ;
 * --- WRITE SAS OUTPUT DATA SET TO TEXT FILE                   --- ;
 * ---------------------------------------------------------------- ;

 %MACRO TEXT;

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

 DATA _NULL_;
   SET OUT3.&OUTFILA3;
 FILE PQTEXTA3 LRECL=1000;
 IF _N_=1 THEN PUT "%Area"  ","  "Type" ","
 "TAPQ01" "," "TAPQ02" "," "TAPQ03" "," "TAPQ04" "," 
 "TAPQ05" "," "TAPQ06" "," "TAPQ07" "," "TAPQ08" ","
 "TAPQ09" "," "TAPQ10" "," "TAPQ11" "," "TAPQ12" ","
 "TAPQ13" "," "TAPQ14" "," "TAPQ15" "," "TAPQ16" ","
 "PAPQ01" "," "PAPQ02" "," "PAPQ03" "," "PAPQ04" ","
 "PAPQ05" "," "PAPQ06" "," "PAPQ07" "," "PAPQ08" ","
 "PAPQ09" "," "PAPQ10" "," "PAPQ11" "," "PAPQ12" ","
 "PAPQ13" "," "PAPQ14" "," "PAPQ15" "," "PAPQ16" ","
 "OAPQ01" "," "OAPQ02" "," "OAPQ03" "," "OAPQ04" ","
 "OAPQ05" "," "OAPQ06" "," "OAPQ07" "," "OAPQ08" ","
 "OAPQ09" "," "OAPQ10" "," "OAPQ11" "," "OAPQ12" ","
 "OAPQ13" "," "OAPQ14" "," "OAPQ15" "," "OAPQ16" ","
 "RAPQ01" "," "RAPQ02" "," "RAPQ03" "," "RAPQ04" "," 
 "RAPQ05" "," "RAPQ06" "," "RAPQ07" "," "RAPQ08" ","
 "RAPQ09" "," "RAPQ10" "," "RAPQ11" "," "RAPQ12" "," 
 "RAPQ13" "," "RAPQ14" "," "RAPQ15" "," "RAPQ16" ","
 "SAPQ01" "," "SAPQ02" "," "SAPQ03" "," "SAPQ04" ","
 "SAPQ05" "," "SAPQ06" "," "SAPQ07" "," "SAPQ08" ","
 "SAPQ09" "," "SAPQ10" "," "SAPQ11" "," "SAPQ12" ","
 "SAPQ13" "," "SAPQ14" "," "SAPQ15" "," "SAPQ16" 
 ;

 PUT %AREA  ","   _TYPE_ 2.  ","
 (TAPQ01-TAPQ16) (7.0 ",")
  ","
 (PAPQ01-PAPQ16) (13.2 ",")
 ","
 (OAPQ01-OAPQ16) (12.10 ",")
 ","
 (RAPQ01-RAPQ16) (12.10 ",")
 ","
 (SAPQ01-SAPQ16) (12.10 ",")
 ;
 RUN;

 %END;

 %MEND TEXT;

 %TEXT;





