********************************************************************;
*   6/30/2010: with thanks to Brett Larive of the Cleveland        *;
*   Clinic for bringing to our attention a problem with the        *;
*   RAND-HSI scoring.  IMPUTEd value needed to be rounded          *;                                                               
*   in order for sums that fell on boundaries to be                *;                                                               
*   classified properly.                                           *;     
*                                                                  *;                                                               
*   For example, in this situation:                                *;     
*                                                                  *;     
*   i3   i4   i5   i6   i7   i8   i9   i10  i11  i12               *;     
*   3    1    3    2    3    1    .    3    3    3                 *;     
*                                                                  *;
*   we get:                                                        *;
*   NEW3    100                                                    *;
*   NEW4    21                                                     *;
*   NEW5    50                                                     *;
*   NEW6    50                                                     *;
*   NEW7    44                                                     *;
*   NEW8    22                                                     *;
*   NEW9    44.1111                                                *;
*   NEW10   51                                                     *;
*   NEW11   35                                                     *;
*   NEW12   24                                                     *;
*   MISS    1                                                      *;
*   IMPUTE  44.1111                                                *;
*   PHYFUN  441.111                                                *;
*                                                                  *;
*   but 441.111 does not get classified properly:                  *;
*                                                                  *;
*   IF 433<=PHYFUN<=441  then TPF=43;                              *;
*   IF 442<=PHYFUN<=450  then TPF=44;                              *;
*                                                                  *;
*   The updated code now rounds the value to the nearest integer   *;
*   so that the classification can take place.                     *;
*                                                                  *;
********************************************************************;

data randhsi(keep=id tphc tmhc tghc); set main(keep=id i1 i3-i36); by id;

*****************************************************************;
*** CREATING RAND-36 HSI SCORES; ********************************;
*****************************************************************;
IF I1=1 THEN NEW1=100; ELSE 
IF I1=2 THEN NEW1= 79; ELSE 
IF I1=3 THEN NEW1= 46; ELSE 
IF I1=4 THEN NEW1= 18; ELSE 
IF I1=5 THEN NEW1=  0;

IF I3=1 THEN NEW3= 50; ELSE 
IF I3=2 THEN NEW3= 76; ELSE 
IF I3=3 THEN NEW3=100;

IF I4=1 THEN NEW4=21; ELSE 
IF I4=2 THEN NEW4=38; ELSE 
IF I4=3 THEN NEW4=56;

IF I5=1 THEN NEW5=17; ELSE 
IF I5=2 THEN NEW5=33; ELSE 
IF I5=3 THEN NEW5=50;

IF I6=1 THEN NEW6=28; ELSE 
IF I6=2 THEN NEW6=50; ELSE 
IF I6=3 THEN NEW6=72;

IF I7=1 THEN NEW7=13; ELSE 
IF I7=2 THEN NEW7=28; ELSE 
IF I7=3 THEN NEW7=44;

IF I8=1 THEN NEW8=22; ELSE 
IF I8=2 THEN NEW8=44; ELSE 
IF I8=3 THEN NEW8=67;

IF I9=1 THEN NEW9=31; ELSE 
IF I9=2 THEN NEW9=47; ELSE 
IF I9=3 THEN NEW9=65;

IF I10=1 THEN NEW10=19; ELSE 
IF I10=2 THEN NEW10=36; ELSE 
IF I10=3 THEN NEW10=51;

IF I11=1 THEN NEW11= 8; ELSE 
IF I11=2 THEN NEW11=21; ELSE 
IF I11=3 THEN NEW11=35;

IF I12=1 THEN NEW12= 0; ELSE 
IF I12=2 THEN NEW12=13; ELSE 
IF I12=3 THEN NEW12=24;

IF I13=1 THEN NEW13= 0; ELSE 
IF I13=2 THEN NEW13=44;

IF I14=1 THEN NEW14= 56; ELSE 
IF I14=2 THEN NEW14=100;

IF I15=1 THEN NEW15=30; ELSE 
IF I15=2 THEN NEW15=74;

IF I16=1 THEN NEW16=26; ELSE 
IF I16=2 THEN NEW16=70;

IF I17=1 THEN NEW17= 0; ELSE 
IF I17=2 THEN NEW17=41;

IF I18=1 THEN NEW18= 59; ELSE 
IF I18=2 THEN NEW18=100;

IF I19=1 THEN NEW19=13; ELSE 
IF I19=2 THEN NEW19=54;

IF I20=1 THEN NEW20=88; ELSE 
IF I20=2 THEN NEW20=70; ELSE 
IF I20=3 THEN NEW20=44; ELSE 
IF I20=4 THEN NEW20=18; ELSE 
IF I20=5 THEN NEW20= 0;

IF I21=1 THEN NEW21=100; ELSE 
IF I21=2 THEN NEW21= 78; ELSE 
IF I21=3 THEN NEW21= 51; ELSE 
IF I21=4 THEN NEW21= 34; ELSE 
IF I21=5 THEN NEW21= 15; ELSE 
IF I21=6 THEN NEW21=  6;

IF I22=1 THEN NEW22=61; ELSE 
IF I22=2 THEN NEW22=49; ELSE 
IF I22=3 THEN NEW22=32; ELSE 
IF I22=4 THEN NEW22=14; ELSE 
IF I22=5 THEN NEW22= 0;

IF I23=1 THEN NEW23=100; ELSE 
IF I23=2 THEN NEW23= 76; ELSE 
IF I23=3 THEN NEW23= 47; ELSE 
IF I23=4 THEN NEW23= 31; ELSE 
IF I23=5 THEN NEW23= 16; ELSE 
IF I23=6 THEN NEW23=  4;

IF I24=1 THEN NEW24= 8; ELSE 
IF I24=2 THEN NEW24=15; ELSE 
IF I24=3 THEN NEW24=23; ELSE 
IF I24=4 THEN NEW24=31; ELSE 
IF I24=5 THEN NEW24=46; ELSE 
IF I24=6 THEN NEW24=60;

IF I25=1 THEN NEW25= 5; ELSE 
IF I25=2 THEN NEW25=13; ELSE 
IF I25=3 THEN NEW25=21; ELSE 
IF I25=4 THEN NEW25=27; ELSE 
IF I25=5 THEN NEW25=36; ELSE 
IF I25=6 THEN NEW25=46;

IF I26=1 THEN NEW26=100; ELSE 
IF I26=2 THEN NEW26= 73; ELSE 
IF I26=3 THEN NEW26= 45; ELSE 
IF I26=4 THEN NEW26= 32; ELSE 
IF I26=5 THEN NEW26= 17; ELSE 
IF I26=6 THEN NEW26=  5;

IF I27=1 THEN NEW27=90; ELSE 
IF I27=2 THEN NEW27=70; ELSE 
IF I27=3 THEN NEW27=45; ELSE 
IF I27=4 THEN NEW27=30; ELSE 
IF I27=5 THEN NEW27=13; ELSE 
IF I27=6 THEN NEW27= 1;

IF I28=1 THEN NEW28= 4; ELSE 
IF I28=2 THEN NEW28=13; ELSE 
IF I28=3 THEN NEW28=22; ELSE 
IF I28=4 THEN NEW28=31; ELSE 
IF I28=5 THEN NEW28=47; ELSE 
IF I28=6 THEN NEW28=64;

IF I29=1 THEN NEW29= 0; ELSE 
IF I29=2 THEN NEW29=10; ELSE
IF I29=3 THEN NEW29=22; ELSE 
IF I29=4 THEN NEW29=35; ELSE
IF I29=5 THEN NEW29=56; ELSE 
IF I29=6 THEN NEW29=73;

IF I30=1 THEN NEW30=91; ELSE 
IF I30=2 THEN NEW30=64; ELSE 
IF I30=3 THEN NEW30=37; ELSE 
IF I30=4 THEN NEW30=26; ELSE 
IF I30=5 THEN NEW30=12; ELSE 
IF I30=6 THEN NEW30= 0;

IF I31=1 THEN NEW31= 0; ELSE 
IF I31=2 THEN NEW31=11; ELSE 
IF I31=3 THEN NEW31=25; ELSE 
IF I31=4 THEN NEW31=40; ELSE 
IF I31=5 THEN NEW31=71; ELSE 
IF I31=6 THEN NEW31=91;

IF I32=1 THEN NEW32= 27; ELSE 
IF I32=2 THEN NEW32= 38; ELSE 
IF I32=3 THEN NEW32= 53; ELSE 
IF I32=4 THEN NEW32= 79; ELSE 
IF I32=5 THEN NEW32=100;

IF I33=1 THEN NEW33=10; ELSE 
IF I33=2 THEN NEW33=20; ELSE 
IF I33=3 THEN NEW33=36; ELSE 
IF I33=4 THEN NEW33=52; ELSE 
IF I33=5 THEN NEW33=66;

IF I34=1 THEN NEW34=89; ELSE 
IF I34=2 THEN NEW34=67; ELSE 
IF I34=3 THEN NEW34=46; ELSE 
IF I34=4 THEN NEW34=33; ELSE 
IF I34=5 THEN NEW34=21;

IF I35=1 THEN NEW35=10; ELSE 
IF I35=2 THEN NEW35=25; ELSE 
IF I35=3 THEN NEW35=49; ELSE 
IF I35=4 THEN NEW35=70; ELSE 
IF I35=5 THEN NEW35=84;

IF I36=1 THEN NEW36=95; ELSE 
IF I36=2 THEN NEW36=69; ELSE 
IF I36=3 THEN NEW36=48; ELSE 
IF I36=4 THEN NEW36=36; ELSE 
IF I36=5 THEN NEW36=26;
*********************************************************;
*********************************************************;
MISS=NMISS(of I3-I12);
IF MISS>1 THEN PHYFUN=.; ELSE 
IF MISS=0 THEN PHYFUN=SUM(of NEW3-NEW12); ELSE 

IF MISS=1 THEN DO;
   IMPUTE=round(MEAN(of NEW3-NEW12),1);

        IF NEW3<=.Z AND IMPUTE<50  THEN NEW3=50;   
   ELSE IF NEW3<=.Z AND IMPUTE>100 THEN NEW3=100;  
   ELSE IF NEW3<=.Z                THEN NEW3=IMPUTE;
   
        IF NEW4<=.Z AND IMPUTE<21 THEN NEW4=21;  
   ELSE IF NEW4<=.Z AND IMPUTE>56 THEN NEW4=56;  
   ELSE IF NEW4<=.Z               THEN NEW4=IMPUTE; 
   
        IF NEW5<=.Z AND IMPUTE<17 THEN NEW5=17;  
   ELSE IF NEW5<=.Z AND IMPUTE>50 THEN NEW5=50;  
   ELSE IF NEW5<=.Z               THEN NEW5=IMPUTE;
   
        IF NEW6<=.Z AND IMPUTE<28 THEN NEW6=28;  
   ELSE IF NEW6<=.Z AND IMPUTE>72 THEN NEW6=72;  
   ELSE IF NEW6<=.Z               THEN NEW6=IMPUTE;
   
        IF NEW7<=.Z AND IMPUTE<13 THEN NEW7=13;  
   ELSE IF NEW7<=.Z AND IMPUTE>44 THEN NEW7=44;  
   ELSE IF NEW7<=.Z               THEN NEW7=IMPUTE;
   
        IF NEW8<=.Z AND IMPUTE<22 THEN NEW8=22;  
   ELSE IF NEW8<=.Z AND IMPUTE>67 THEN NEW8=67;  
   ELSE IF NEW8<=.Z               THEN NEW8=IMPUTE;
   
        IF NEW9<=.Z AND IMPUTE<31 THEN NEW9=31;  
   ELSE IF NEW9<=.Z AND IMPUTE>65 THEN NEW9=65;  
   ELSE IF NEW9<=.Z               THEN NEW9=IMPUTE;
   
        IF NEW10<=.Z AND IMPUTE<19 THEN NEW10=19;  
   ELSE IF NEW10<=.Z AND IMPUTE>51 THEN NEW10=51;  
   ELSE IF NEW10<=.Z               THEN NEW10=IMPUTE;
   
        IF NEW11<=.Z AND IMPUTE<8  THEN NEW11=8;   
   ELSE IF NEW11<=.Z AND IMPUTE>35 THEN NEW11=35;  
   ELSE IF NEW11<=.Z               THEN NEW11=IMPUTE;
   
        IF NEW12<=.Z AND IMPUTE<0  THEN NEW12=0;   
   ELSE IF NEW12<=.Z AND IMPUTE>24 THEN NEW12=24;  
   ELSE IF NEW12<=.Z               THEN NEW12=IMPUTE;
   
   PHYFUN=SUM(of NEW3-NEW12);
 END;
*********************************************************;
MISS=NMISS(of I13-I16);
IF MISS>1 THEN ROLEP=.; ELSE 
IF MISS=0 THEN ROLEP=SUM(of NEW13-NEW16); ELSE 

IF MISS=1 THEN DO;
   IMPUTE=round(MEAN(of NEW13-NEW16),1);
   
        IF NEW13<=.Z AND IMPUTE<0  THEN NEW13=0;   
   ELSE IF NEW13<=.Z AND IMPUTE>44 THEN NEW13=44;  
   ELSE IF NEW13<=.Z               THEN NEW13=IMPUTE;
    
        IF NEW14<=.Z AND IMPUTE<56  THEN  NEW14=56;  
   ELSE IF NEW14<=.Z AND IMPUTE>100 THEN NEW14=100;  
   ELSE IF NEW14<=.Z                THEN NEW14=IMPUTE;
    
        IF NEW15<=.Z AND IMPUTE<30 THEN NEW15=30;  
   ELSE IF NEW15<=.Z AND IMPUTE>74 THEN NEW15=74;  
   ELSE IF NEW15<=.Z               THEN NEW15=IMPUTE;
    
        IF NEW16<=.Z AND IMPUTE<26 THEN NEW16=26;  
   ELSE IF NEW16<=.Z AND IMPUTE>70 THEN NEW16=70;  
   ELSE IF NEW16<=.Z               THEN NEW16=IMPUTE;
    
   ROLEP=SUM(of NEW13-NEW16);
END;
*********************************************************;
MISS=NMISS(I21,I22);
IF MISS>1 THEN PAIN=.; ELSE 
IF MISS=0 THEN PAIN=SUM(NEW21,NEW22); ELSE 

IF MISS=1 THEN DO;
   IMPUTE=round(MEAN(NEW21,NEW22),1);

        IF NEW21<=.Z AND IMPUTE<6   THEN NEW21=6;    
   ELSE IF NEW21<=.Z AND IMPUTE>100 THEN NEW21=100;  
   ELSE IF NEW21<=.Z                THEN NEW21=IMPUTE;

        IF NEW22<=.Z AND IMPUTE<0  THEN NEW22=0;   
   ELSE IF NEW22<=.Z AND IMPUTE>61 THEN NEW22=61;  
   ELSE IF NEW22<=.Z               THEN NEW22=IMPUTE;

   PAIN=SUM(NEW21,NEW22);
END;
*********************************************************;
MISS=NMISS(of I1 I33-I36);
IF MISS>1 THEN GENH=.; ELSE 
IF MISS=0 THEN GENH=SUM(of NEW1 NEW33-NEW36); ELSE 

IF MISS=1 THEN DO;
   IMPUTE=round(MEAN(of NEW1 NEW33-NEW36),1);
   
        IF NEW1<=.Z AND IMPUTE<0   THEN NEW1=0;    
   ELSE IF NEW1<=.Z AND IMPUTE>100 THEN NEW1=100;  
   ELSE IF NEW1<=.Z                THEN NEW1=IMPUTE;
   
        IF NEW33<=.Z AND IMPUTE<10 THEN NEW33=10;  
   ELSE IF NEW33<=.Z AND IMPUTE>66 THEN NEW33=66;  
   ELSE IF NEW33<=.Z               THEN NEW33=IMPUTE;
   
        IF NEW34<=.Z AND IMPUTE<21 THEN NEW34=21;  
   ELSE IF NEW34<=.Z AND IMPUTE>89 THEN NEW34=89;  
   ELSE IF NEW34<=.Z               THEN NEW34=IMPUTE;
   
        IF NEW35<=.Z AND IMPUTE<10 THEN NEW35=10;  
   ELSE IF NEW35<=.Z AND IMPUTE>84 THEN NEW35=84;  
   ELSE IF NEW35<=.Z               THEN NEW35=IMPUTE;
   
        IF NEW36<=.Z AND IMPUTE<26 THEN NEW36=26;  
   ELSE IF NEW36<=.Z AND IMPUTE>95 THEN NEW36=95;  
   ELSE IF NEW36<=.Z               THEN NEW36=IMPUTE;
   
   GENH=SUM(of NEW1 NEW33-NEW36);
END;
*********************************************************;
MISS=NMISS(of I24-I26 I28 I30);
IF MISS>1 THEN EMOT=.; ELSE 
IF MISS=0 THEN EMOT=SUM(of NEW24-NEW26 NEW28 NEW30); ELSE 

IF MISS=1 THEN DO;
   IMPUTE=round(MEAN(of NEW24-NEW26 NEW28 NEW30),1);
  
        IF NEW24<=.Z AND IMPUTE<8  THEN NEW24=8;  
   ELSE IF NEW24<=.Z AND IMPUTE>60 THEN NEW24=60; 
   ELSE IF NEW24<=.Z               THEN NEW24=IMPUTE;
  
        IF NEW25<=.Z AND IMPUTE<5  THEN NEW25=5;  
   ELSE IF NEW25<=.Z AND IMPUTE>46 THEN NEW25=46; 
   ELSE IF NEW25<=.Z               THEN NEW25=IMPUTE;
  
        IF NEW26<=.Z AND IMPUTE<5   THEN NEW26=5;    
   ELSE IF NEW26<=.Z AND IMPUTE>100 THEN NEW26=100;  
   ELSE IF NEW26<=.Z                THEN NEW26=IMPUTE;
  
        IF NEW28<=.Z AND IMPUTE<4  THEN NEW28=4;   
   ELSE IF NEW28<=.Z AND IMPUTE>64 THEN NEW28=64;  
   ELSE IF NEW28<=.Z               THEN NEW28=IMPUTE;
  
        IF NEW30<=.Z AND IMPUTE<0  THEN NEW30=0;   
   ELSE IF NEW30<=.Z AND IMPUTE>91 THEN NEW30=91;  
   ELSE IF NEW30<=.Z               THEN NEW30=IMPUTE;
  
   EMOT=SUM(of NEW24-NEW26 NEW28 NEW30);
END;
*********************************************************;
MISS=NMISS(of I17-I19);
IF MISS>1 THEN ROLEE=.; ELSE 
IF MISS=0 THEN ROLEE=SUM(of NEW17-NEW19); ELSE 

IF MISS=1 THEN DO;
   IMPUTE=round(MEAN(of NEW17-NEW19),1);
   
        IF NEW17<=.Z AND IMPUTE<0  THEN NEW17=0;   
   ELSE IF NEW17<=.Z AND IMPUTE>41 THEN NEW17=41;  
   ELSE IF NEW17<=.Z               THEN NEW17=IMPUTE;
    
        IF NEW18<=.Z AND IMPUTE<59  THEN NEW18=59;  
   ELSE IF NEW18<=.Z AND IMPUTE>100 THEN NEW18=100; 
   ELSE IF NEW18<=.Z                THEN NEW18=IMPUTE;
    
        IF NEW19<=.Z AND IMPUTE<13 THEN NEW19=13;  
   ELSE IF NEW19<=.Z AND IMPUTE>54 THEN NEW19=54;  
   ELSE IF NEW19<=.Z               THEN NEW19=IMPUTE;
    
   ROLEE=SUM(of NEW17-NEW19);
END;
*********************************************************;
MISS=NMISS(I20,I32);
IF MISS>1 THEN SOCFUN=.; ELSE 
IF MISS=0 THEN SOCFUN=SUM(NEW20,NEW32); ELSE 

IF MISS=1 THEN DO;
   IMPUTE=round(MEAN(NEW20,NEW32),1);
   
        IF NEW20<=.Z AND IMPUTE<0  THEN NEW20=0;   
   ELSE IF NEW20<=.Z AND IMPUTE>88 THEN NEW20=88;  
   ELSE IF NEW20<=.Z               THEN NEW20=IMPUTE;
    
        IF NEW32<=.Z AND IMPUTE<27  THEN NEW32=27;  
   ELSE IF NEW32<=.Z AND IMPUTE>100 THEN NEW32=100; 
   ELSE IF NEW32<=.Z                THEN NEW32=IMPUTE;
    
   SOCFUN=SUM(NEW20,NEW32);
END;
*********************************************************;
MISS=NMISS(I23,I27,I29,I31);
IF MISS>1 THEN ENFAT=.; ELSE 
IF MISS=0 THEN ENFAT=SUM(NEW23,NEW27,NEW29,NEW31); ELSE 

IF MISS=1 THEN DO;
   IMPUTE=round(MEAN(NEW23,NEW27,NEW29,NEW31),1);
   
        IF NEW23<=.Z AND IMPUTE<4   THEN NEW23=4;   
   ELSE IF NEW23<=.Z AND IMPUTE>100 THEN NEW23=100;  
   ELSE IF NEW23<=.Z                THEN NEW23=IMPUTE;
    
        IF NEW27<=.Z AND IMPUTE<1  THEN NEW27=1;  
   ELSE IF NEW27<=.Z AND IMPUTE>90 THEN NEW27=90; 
   ELSE IF NEW27<=.Z               THEN NEW27=IMPUTE;
    
        IF NEW29<=.Z AND IMPUTE<0  THEN NEW29=0;   
   ELSE IF NEW29<=.Z AND IMPUTE>73 THEN NEW29=73;  
   ELSE IF NEW29<=.Z               THEN NEW29=IMPUTE;
    
        IF NEW31<=.Z AND IMPUTE<0  THEN NEW31=0;   
   ELSE IF NEW31<=.Z AND IMPUTE>91 THEN NEW31=91;  
   ELSE IF NEW31<=.Z               THEN NEW31=IMPUTE;
    
   ENFAT=SUM(NEW23,NEW27,NEW29,NEW31);
END;

****************************************************;
* Assign T-scores for scales;
****************************************************;

IF PHYFUN=209 then TPF=16;         ELSE
IF 210<=PHYFUN<=218  then TPF=17;  ELSE 
IF 219<=PHYFUN<=227  then TPF=18;  ELSE 
IF 228<=PHYFUN<=235  then TPF=19;  ELSE 
IF 236<=PHYFUN<=244  then TPF=20;  ELSE 
IF 245<=PHYFUN<=252  then TPF=21;  ELSE 
IF 253<=PHYFUN<=261  then TPF=22;  ELSE 
IF 262<=PHYFUN<=269  then TPF=23;  ELSE 
IF 270<=PHYFUN<=278  then TPF=24;  ELSE 
IF 279<=PHYFUN<=287  then TPF=25;  ELSE 
IF 288<=PHYFUN<=295  then TPF=26;  ELSE 
IF 296<=PHYFUN<=304  then TPF=27;  ELSE 
IF 305<=PHYFUN<=312  then TPF=28;  ELSE 
IF 313<=PHYFUN<=321  then TPF=29;  ELSE 
IF 322<=PHYFUN<=329  then TPF=30;  ELSE 
IF 330<=PHYFUN<=338  then TPF=31;  ELSE 
IF 339<=PHYFUN<=347  then TPF=32;  ELSE 
IF 348<=PHYFUN<=355  then TPF=33;  ELSE 
IF 356<=PHYFUN<=364  then TPF=34;  ELSE 
IF 365<=PHYFUN<=372  then TPF=35;  ELSE 
IF 373<=PHYFUN<=381  then TPF=36;  ELSE 
IF 382<=PHYFUN<=390  then TPF=37;  ELSE 
IF 391<=PHYFUN<=398  then TPF=38;  ELSE 
IF 399<=PHYFUN<=407  then TPF=39;  ELSE 
IF 408<=PHYFUN<=415  then TPF=40;  ELSE 
IF 416<=PHYFUN<=424  then TPF=41;  ELSE 
IF 425<=PHYFUN<=432  then TPF=42;  ELSE 
IF 433<=PHYFUN<=441  then TPF=43;  ELSE 
IF 442<=PHYFUN<=450  then TPF=44;  ELSE 
IF 451<=PHYFUN<=458  then TPF=45;  ELSE 
IF 459<=PHYFUN<=467  then TPF=46;  ELSE 
IF 468<=PHYFUN<=475  then TPF=47;  ELSE 
IF 476<=PHYFUN<=484  then TPF=48;  ELSE 
IF 485<=PHYFUN<=492  then TPF=49;  ELSE 
IF 493<=PHYFUN<=501  then TPF=50;  ELSE 
IF 502<=PHYFUN<=510  then TPF=51;  ELSE 
IF 511<=PHYFUN<=518  then TPF=52;  ELSE 
IF 519<=PHYFUN<=527  then TPF=53;  ELSE 
IF 528<=PHYFUN<=535  then TPF=54;  ELSE 
IF 536<=PHYFUN<=544  then TPF=55;  ELSE 
IF 545<=PHYFUN<=553  then TPF=56;  ELSE 
IF 554<=PHYFUN<=561  then TPF=57;  ELSE 
IF 562<=PHYFUN<=564  then TPF=58;  

IF 112<=ROLEP<=117  then TRLP=26; ELSE 
IF 118<=ROLEP<=123  then TRLP=27; ELSE
IF 124<=ROLEP<=129  then TRLP=28; ELSE
IF 130<=ROLEP<=135  then TRLP=29; ELSE
IF 136<=ROLEP<=141  then TRLP=30; ELSE
IF 142<=ROLEP<=147  then TRLP=31; ELSE
IF 148<=ROLEP<=153  then TRLP=32; ELSE
IF 154<=ROLEP<=158  then TRLP=33; ELSE

IF 159<=ROLEP<=164  then TRLP=34; ELSE
IF 165<=ROLEP<=170  then TRLP=35; ELSE
IF 171<=ROLEP<=176  then TRLP=36; ELSE
IF 177<=ROLEP<=182  then TRLP=37; ELSE
IF 183<=ROLEP<=188  then TRLP=38; ELSE
IF 189<=ROLEP<=194  then TRLP=39; ELSE
IF 195<=ROLEP<=199  then TRLP=40; ELSE

IF 200<=ROLEP<=205  then TRLP=41; ELSE
IF 206<=ROLEP<=211  then TRLP=42; ELSE
IF 212<=ROLEP<=217  then TRLP=43; ELSE
IF 218<=ROLEP<=223  then TRLP=44; ELSE
IF 224<=ROLEP<=229  then TRLP=45; ELSE
IF 230<=ROLEP<=235  then TRLP=46; ELSE
IF 236<=ROLEP<=240  then TRLP=47; ELSE

IF 241<=ROLEP<=246  then TRLP=48; ELSE
IF 247<=ROLEP<=252  then TRLP=49; ELSE
IF 253<=ROLEP<=258  then TRLP=50; ELSE
IF 259<=ROLEP<=264  then TRLP=51; ELSE
IF 265<=ROLEP<=270  then TRLP=52; ELSE
IF 271<=ROLEP<=276  then TRLP=53; ELSE
IF 277<=ROLEP<=281  then TRLP=54; ELSE

IF 282<=ROLEP<=287  then TRLP=55; ELSE
IF ROLEP=288        then TRLP=56;

IF 6<=PAIN<=9      then TPA=20; ELSE
IF 10<=PAIN<=13    then TPA=21; ELSE
IF 14<=PAIN<=17    then TPA=22; ELSE
IF 18<=PAIN<=21    then TPA=23; ELSE
IF 22<=PAIN<=25    then TPA=24; ELSE
IF 26<=PAIN<=28    then TPA=25; ELSE

IF 29<=PAIN<=32    then TPA=26; ELSE
IF 33<=PAIN<=36    then TPA=27; ELSE
IF 37<=PAIN<=40    then TPA=28; ELSE
IF 41<=PAIN<=44    then TPA=29; ELSE
IF 45<=PAIN<=48    then TPA=30; ELSE
IF 49<=PAIN<=52    then TPA=31; ELSE
IF 53<=PAIN<=55    then TPA=32; ELSE

IF 56<=PAIN<=59    then TPA=33; ELSE
IF 60<=PAIN<=63    then TPA=34; ELSE
IF 64<=PAIN<=67    then TPA=35; ELSE
IF 68<=PAIN<=71    then TPA=36; ELSE
IF 72<=PAIN<=75    then TPA=37; ELSE
IF 76<=PAIN<=79    then TPA=38; ELSE
IF 80<=PAIN<=82    then TPA=39; ELSE

IF 83<=PAIN<=86    then TPA=40; ELSE
IF 87<=PAIN<=90    then TPA=41; ELSE
IF 91<=PAIN<=94    then TPA=42; ELSE
IF 95<=PAIN<=98    then TPA=43; ELSE
IF 99<=PAIN<=102   then TPA=44; ELSE
IF 103<=PAIN<=106  then TPA=45; ELSE
IF 107<=PAIN<=110  then TPA=46; ELSE
IF 111<=PAIN<=113  then TPA=47; ELSE

IF 114<=PAIN<=117  then TPA=48; ELSE
IF 118<=PAIN<=121  then TPA=49; ELSE
IF 122<=PAIN<=125  then TPA=50; ELSE
IF 126<=PAIN<=129  then TPA=51; ELSE
IF 130<=PAIN<=133  then TPA=52; ELSE
IF 134<=PAIN<=137  then TPA=53; ELSE
IF 138<=PAIN<=140  then TPA=54; ELSE

IF 141<=PAIN<=144  then TPA=55; ELSE
IF 145<=PAIN<=148  then TPA=56; ELSE
IF 149<=PAIN<=152  then TPA=57; ELSE
IF 153<=PAIN<=156  then TPA=58; ELSE
IF 157<=PAIN<=160  then TPA=59; ELSE
IF PAIN=161        then TPA=60;

IF 67<=GENH<=74    then TGHP=20; ELSE
IF 75<=GENH<=83    then TGHP=21; ELSE
IF 84<=GENH<=91    then TGHP=22; ELSE
IF 92<=GENH<=99    then TGHP=23; ELSE
IF 100<=GENH<=108  then TGHP=24; ELSE
IF 109<=GENH<=116  then TGHP=25; ELSE
IF 117<=GENH<=124  then TGHP=26; ELSE
IF 125<=GENH<=132  then TGHP=27; ELSE
IF 133<=GENH<=141  then TGHP=28; ELSE
IF 142<=GENH<=149  then TGHP=29; ELSE
IF 150<=GENH<=157  then TGHP=30; ELSE
IF 158<=GENH<=166  then TGHP=31; ELSE
IF 167<=GENH<=174  then TGHP=32; ELSE
IF 175<=GENH<=182  then TGHP=33; ELSE
IF 183<=GENH<=190  then TGHP=34; ELSE
IF 191<=GENH<=199  then TGHP=35; ELSE
IF 200<=GENH<=207  then TGHP=36; ELSE
IF 208<=GENH<=215  then TGHP=37; ELSE
IF 216<=GENH<=223  then TGHP=38; ELSE
IF 224<=GENH<=232  then TGHP=39; ELSE
IF 233<=GENH<=240  then TGHP=40; ELSE
IF 241<=GENH<=248  then TGHP=41; ELSE
IF 249<=GENH<=257  then TGHP=42; ELSE
IF 258<=GENH<=265  then TGHP=43; ELSE
IF 266<=GENH<=273  then TGHP=44; ELSE
IF 274<=GENH<=281  then TGHP=45; ELSE
IF 282<=GENH<=290  then TGHP=46; ELSE
IF 291<=GENH<=298  then TGHP=47; ELSE
IF 299<=GENH<=306  then TGHP=48; ELSE
IF 307<=GENH<=315  then TGHP=49; ELSE
IF 316<=GENH<=323  then TGHP=50; ELSE
IF 324<=GENH<=331  then TGHP=51; ELSE
IF 332<=GENH<=339  then TGHP=52; ELSE
IF 340<=GENH<=348  then TGHP=53; ELSE
IF 349<=GENH<=356  then TGHP=54; ELSE
IF 357<=GENH<=364  then TGHP=55; ELSE
IF 365<=GENH<=373  then TGHP=56; ELSE
IF 374<=GENH<=381  then TGHP=57; ELSE
IF 382<=GENH<=389  then TGHP=58; ELSE
IF 390<=GENH<=397  then TGHP=59; ELSE
IF 398<=GENH<=406  then TGHP=60; ELSE
IF 407<=GENH<=414  then TGHP=61; ELSE
IF 415<=GENH<=422  then TGHP=62; ELSE
IF 423<=GENH<=431  then TGHP=63; ELSE
IF 432<=GENH<=434  then TGHP=64;

IF 22<=EMOT<=27    then TEWB=16; ELSE
IF 28<=EMOT<=34    then TEWB=17; ELSE
IF 35<=EMOT<=41    then TEWB=18; ELSE
IF 42<=EMOT<=47    then TEWB=19; ELSE
IF 48<=EMOT<=54    then TEWB=20; ELSE
IF 55<=EMOT<=61    then TEWB=21; ELSE
IF 62<=EMOT<=67    then TEWB=22; ELSE
IF 68<=EMOT<=74    then TEWB=23; ELSE
IF 75<=EMOT<=81    then TEWB=24; ELSE
IF 82<=EMOT<=87    then TEWB=25; ELSE
IF 88<=EMOT<=94    then TEWB=26; ELSE
IF 95<=EMOT<=101   then TEWB=27; ELSE
IF 102<=EMOT<=108  then TEWB=28; ELSE
IF 109<=EMOT<=114  then TEWB=29; ELSE
IF 115<=EMOT<=121  then TEWB=30; ELSE
IF 122<=EMOT<=128  then TEWB=31; ELSE
IF 129<=EMOT<=134  then TEWB=32; ELSE
IF 135<=EMOT<=141  then TEWB=33; ELSE
IF 142<=EMOT<=148  then TEWB=34; ELSE
IF 149<=EMOT<=154  then TEWB=35; ELSE
IF 155<=EMOT<=161  then TEWB=36; ELSE
IF 162<=EMOT<=168  then TEWB=37; ELSE
IF 169<=EMOT<=174  then TEWB=38; ELSE
IF 175<=EMOT<=181  then TEWB=39; ELSE
IF 182<=EMOT<=188  then TEWB=40; ELSE
IF 189<=EMOT<=194  then TEWB=41; ELSE
IF 195<=EMOT<=201  then TEWB=42; ELSE
IF 202<=EMOT<=208  then TEWB=43; ELSE
IF 209<=EMOT<=214  then TEWB=44; ELSE
IF 215<=EMOT<=221  then TEWB=45; ELSE
IF 222<=EMOT<=228  then TEWB=46; ELSE
IF 229<=EMOT<=234  then TEWB=47; ELSE
IF 235<=EMOT<=241  then TEWB=48; ELSE
IF 242<=EMOT<=248  then TEWB=49; ELSE
IF 249<=EMOT<=254  then TEWB=50; ELSE
IF 255<=EMOT<=261  then TEWB=51; ELSE
IF 262<=EMOT<=268  then TEWB=52; ELSE
IF 269<=EMOT<=275  then TEWB=53; ELSE
IF 276<=EMOT<=281  then TEWB=54; ELSE
IF 282<=EMOT<=288  then TEWB=55; ELSE
IF 289<=EMOT<=295  then TEWB=56; ELSE
IF 296<=EMOT<=301  then TEWB=57; ELSE
IF 302<=EMOT<=308  then TEWB=58; ELSE
IF 309<=EMOT<=315  then TEWB=59; ELSE
IF 316<=EMOT<=321  then TEWB=60; ELSE
IF 322<=EMOT<=328  then TEWB=61; ELSE
IF 329<=EMOT<=335  then TEWB=62; ELSE
IF 336<=EMOT<=341  then TEWB=63; ELSE
IF 342<=EMOT<=348  then TEWB=64; ELSE
IF 349<=EMOT<=355  then TEWB=65; ELSE
IF 356<=EMOT<=361  then TEWB=66;

IF 72<=ROLEE<=73    then TRLE=19; ELSE
IF 74<=ROLEE<=77    then TRLE=20; ELSE
IF 78<=ROLEE<=80    then TRLE=21; ELSE
IF 81<=ROLEE<=83    then TRLE=22; ELSE
IF 84<=ROLEE<=87    then TRLE=23; ELSE
IF 88<=ROLEE<=90    then TRLE=24; ELSE
IF 91<=ROLEE<=94    then TRLE=25; ELSE
IF 95<=ROLEE<=97    then TRLE=26; ELSE
IF 98<=ROLEE<=101   then TRLE=27; ELSE
IF 102<=ROLEE<=104  then TRLE=28; ELSE
IF 105<=ROLEE<=108  then TRLE=29; ELSE
IF 109<=ROLEE<=111  then TRLE=30; ELSE
IF 112<=ROLEE<=115  then TRLE=31; ELSE
IF 116<=ROLEE<=118  then TRLE=32; ELSE
IF 119<=ROLEE<=122  then TRLE=33; ELSE
IF 123<=ROLEE<=125  then TRLE=34; ELSE
IF 126<=ROLEE<=129  then TRLE=35; ELSE
IF 130<=ROLEE<=132  then TRLE=36; ELSE
IF 133<=ROLEE<=136  then TRLE=37; ELSE
IF 137<=ROLEE<=139  then TRLE=38; ELSE
IF 140<=ROLEE<=143  then TRLE=39; ELSE
IF 144<=ROLEE<=146  then TRLE=40; ELSE
IF 147<=ROLEE<=150  then TRLE=41; ELSE
IF 151<=ROLEE<=153  then TRLE=42; ELSE
IF 154<=ROLEE<=157  then TRLE=43; ELSE
IF 158<=ROLEE<=160  then TRLE=44; ELSE
IF 161<=ROLEE<=164  then TRLE=45; ELSE
IF 165<=ROLEE<=167  then TRLE=46; ELSE
IF 168<=ROLEE<=171  then TRLE=47; ELSE
IF 172<=ROLEE<=174  then TRLE=48; ELSE
IF 175<=ROLEE<=178  then TRLE=49; ELSE
IF 179<=ROLEE<=181  then TRLE=50; ELSE
IF 182<=ROLEE<=185  then TRLE=51; ELSE
IF 186<=ROLEE<=188  then TRLE=52; ELSE
IF 189<=ROLEE<=192  then TRLE=53; ELSE
IF 193<=ROLEE<=195  then TRLE=54;

IF 27<=SOCFUN<=28    then TSF=12; ELSE
IF 29<=SOCFUN<=32    then TSF=13; ELSE
IF 33<=SOCFUN<=35    then TSF=14; ELSE
IF 36<=SOCFUN<=39    then TSF=15; ELSE
IF 40<=SOCFUN<=43    then TSF=16; ELSE
IF 44<=SOCFUN<=46    then TSF=17; ELSE
IF 47<=SOCFUN<=50    then TSF=18; ELSE
IF 51<=SOCFUN<=53    then TSF=19; ELSE
IF 54<=SOCFUN<=57    then TSF=20; ELSE
IF 58<=SOCFUN<=61    then TSF=21; ELSE
IF 62<=SOCFUN<=64    then TSF=22; ELSE
IF 65<=SOCFUN<=68    then TSF=23; ELSE
IF 69<=SOCFUN<=72    then TSF=24; ELSE
IF 73<=SOCFUN<=75    then TSF=25; ELSE
IF 76<=SOCFUN<=79    then TSF=26; ELSE
IF 80<=SOCFUN<=82    then TSF=27; ELSE
IF 83<=SOCFUN<=86    then TSF=28; ELSE
IF 87<=SOCFUN<=90    then TSF=29; ELSE
IF 91<=SOCFUN<=93    then TSF=30; ELSE
IF 94<=SOCFUN<=97    then TSF=31; ELSE
IF 98<=SOCFUN<=100   then TSF=32; ELSE
IF 101<=SOCFUN<=104  then TSF=33; ELSE
IF 105<=SOCFUN<=108  then TSF=34; ELSE
IF 109<=SOCFUN<=111  then TSF=35; ELSE
IF 112<=SOCFUN<=115  then TSF=36; ELSE
IF 116<=SOCFUN<=119  then TSF=37; ELSE
IF 120<=SOCFUN<=122  then TSF=38; ELSE
IF 123<=SOCFUN<=126  then TSF=39; ELSE
IF 127<=SOCFUN<=129  then TSF=40; ELSE
IF 130<=SOCFUN<=133  then TSF=41; ELSE
IF 134<=SOCFUN<=137  then TSF=42; ELSE
IF 138<=SOCFUN<=140  then TSF=43; ELSE
IF 141<=SOCFUN<=144  then TSF=44; ELSE
IF 145<=SOCFUN<=148  then TSF=45; ELSE
IF 149<=SOCFUN<=151  then TSF=46; ELSE
IF 152<=SOCFUN<=155  then TSF=47; ELSE
IF 156<=SOCFUN<=158  then TSF=48; ELSE
IF 159<=SOCFUN<=162  then TSF=49; ELSE
IF 163<=SOCFUN<=166  then TSF=50; ELSE
IF 167<=SOCFUN<=169  then TSF=51; ELSE
IF 170<=SOCFUN<=173  then TSF=52; ELSE
IF 174<=SOCFUN<=176  then TSF=53; ELSE
IF 177<=SOCFUN<=180  then TSF=54; ELSE
IF 181<=SOCFUN<=184  then TSF=55; ELSE
IF 185<=SOCFUN<=187  then TSF=56; ELSE
IF SOCFUN=188        then TSF=57;

IF 5<=ENFAT<=11     then TEF=26; ELSE
IF 12<=ENFAT<=18    then TEF=27; ELSE
IF 19<=ENFAT<=26    then TEF=28; ELSE
IF 27<=ENFAT<=34    then TEF=29; ELSE
IF 35<=ENFAT<=42    then TEF=30; ELSE
IF 43<=ENFAT<=50    then TEF=31; ELSE
IF 51<=ENFAT<=58    then TEF=32; ELSE
IF 59<=ENFAT<=66    then TEF=33; ELSE
IF 67<=ENFAT<=74    then TEF=34; ELSE
IF 75<=ENFAT<=82    then TEF=35; ELSE
IF 83<=ENFAT<=90    then TEF=36; ELSE
IF 91<=ENFAT<=97    then TEF=37; ELSE
IF 98<=ENFAT<=105   then TEF=38; ELSE
IF 106<=ENFAT<=113  then TEF=39; ELSE
IF 114<=ENFAT<=121  then TEF=40; ELSE
IF 122<=ENFAT<=129  then TEF=41; ELSE
IF 130<=ENFAT<=137  then TEF=42; ELSE
IF 138<=ENFAT<=145  then TEF=43; ELSE
IF 146<=ENFAT<=153  then TEF=44; ELSE
IF 154<=ENFAT<=161  then TEF=45; ELSE
IF 162<=ENFAT<=168  then TEF=46; ELSE
IF 169<=ENFAT<=176  then TEF=47; ELSE
IF 177<=ENFAT<=184  then TEF=48; ELSE
IF 185<=ENFAT<=192  then TEF=49; ELSE
IF 193<=ENFAT<=200  then TEF=50; ELSE
IF 201<=ENFAT<=208  then TEF=51; ELSE
IF 209<=ENFAT<=216  then TEF=52; ELSE
IF 217<=ENFAT<=224  then TEF=53; ELSE
IF 225<=ENFAT<=232  then TEF=54; ELSE
IF 233<=ENFAT<=240  then TEF=55; ELSE
IF 241<=ENFAT<=247  then TEF=56; ELSE
IF 248<=ENFAT<=255  then TEF=57; ELSE
IF 256<=ENFAT<=263  then TEF=58; ELSE
IF 264<=ENFAT<=271  then TEF=59; ELSE
IF 272<=ENFAT<=279  then TEF=60; ELSE
IF 280<=ENFAT<=287  then TEF=61; ELSE
IF 288<=ENFAT<=295  then TEF=62; ELSE
IF 296<=ENFAT<=303  then TEF=63; ELSE
IF 304<=ENFAT<=311  then TEF=64; ELSE
IF 312<=ENFAT<=319  then TEF=65; ELSE
IF 320<=ENFAT<=326  then TEF=66; ELSE
IF 327<=ENFAT<=334  then TEF=67; ELSE
IF 335<=ENFAT<=342  then TEF=68; ELSE
IF 343<=ENFAT<=350  then TEF=69; ELSE
IF 351<=ENFAT<=354  then TEF=70;
*******************************************;

PPHC = (.2712*TPF) + (.3487*TRLP) + (.2755*TPA) + (.2931*TGHP);

MMHC = (.4333*TEWB) + (.1623*TRLE) + (.3112*TSF) + (.3136*TEF);

GGHC = (.1103*TPF)  + (.1775*TRLP) + (.1446*TPA) + (.1621*TGHP)
     + (.2651*TEWB) + (.1013*TRLE) + (.2016*TSF) + (.1911*TEF);

*********************************************************;
PHC=ROUND(PPHC);
MHC=ROUND(MMHC);
GHC=ROUND(GGHC);
*********************************************************;
IF 1<=PHC<=25         THEN TPHC=15;     ELSE 
IF PHC>=26 & PHC <=70 THEN TPHC=PHC-10; ELSE 
IF PHC>=71            THEN TPHC=61;
*********************************************************;
IF 1<=MHC<=22         THEN TMHC=11;     ELSE 
IF MHC>=23 & MHC <=76 THEN TMHC=MHC-11; ELSE 
IF MHC>=77            THEN TMHC=66;
*************************************;
IF 1<=GHC<=26          THEN TGHC=8;      ELSE 
IF GHC >=27 & GHC <=82 THEN TGHC=GHC-18; ELSE 
IF GHC>=83             THEN TGHC=65;

 label tphc="Physical health composite t-score";
 label tmhc="Mental health composite t-score";
 label tghc="Global health composite t-score";

run;