data sf36a(keep=id phyfun10 rolep4 pain2 sfpain genh5 
                emot5 rolee3 socfun2 enfat4 sfgenh5 age male i1-i36 i1sf i21sf i22sf
                qwb qwb100); 
                set main; by id;

*********************************************************;
ARRAY RFIVEPT (I) I1 I2 I20 I22 I34 I36;
ARRAY THREEPT (I) I3 I4 I5 I6 I7 I8 I9 I10 I11 I12;
ARRAY TWOPT   (I) I13 I14 I15 I16 I17 I18 I19;
ARRAY RSIXPT  (I) I21 I23 I26 I27 I30;
ARRAY SIXPT   (I) I24 I25 I28 I29 I31;
ARRAY FIVEPT  (I) I32 I33 I35;
*****************************************************************;
I1SF=I1;I21SF=I21;I22SF=I22;
DO OVER RFIVEPT;
 IF RFIVEPT=1 THEN RFIVEPT=100;
 ELSE IF RFIVEPT=2 THEN RFIVEPT=75;
 ELSE IF RFIVEPT=3 THEN RFIVEPT=50;
 ELSE IF RFIVEPT=4 THEN RFIVEPT=25;
 ELSE IF RFIVEPT=5 THEN RFIVEPT=0;END;
DO OVER THREEPT;
 IF THREEPT=1 THEN THREEPT=0;
 ELSE IF THREEPT=2 THEN THREEPT=50;
 ELSE IF THREEPT=3 THEN THREEPT=100;END;

DO OVER TWOPT;
 IF TWOPT=1 THEN TWOPT=0;
 ELSE IF TWOPT=2 THEN TWOPT=100;END;
DO OVER RSIXPT;
 IF RSIXPT=1 THEN RSIXPT=100;
 ELSE IF RSIXPT=2 THEN RSIXPT=80;
 ELSE IF RSIXPT=3 THEN RSIXPT=60;
 ELSE IF RSIXPT=4 THEN RSIXPT=40;
 ELSE IF RSIXPT=5 THEN RSIXPT=20;
 ELSE IF RSIXPT=6 THEN RSIXPT=0;END;
DO OVER SIXPT;
 IF SIXPT=1 THEN SIXPT=0;
 ELSE IF SIXPT=2 THEN SIXPT=20;
 ELSE IF SIXPT=3 THEN SIXPT=40;
 ELSE IF SIXPT=4 THEN SIXPT=60;
 ELSE IF SIXPT=5 THEN SIXPT=80;
 ELSE IF SIXPT=6 THEN SIXPT=100;END;
DO OVER FIVEPT;
 IF FIVEPT=1 THEN FIVEPT=0;
 ELSE IF FIVEPT=2 THEN FIVEPT=25;
 ELSE IF FIVEPT=3 THEN FIVEPT=50;
 ELSE IF FIVEPT=4 THEN FIVEPT=75;
 ELSE IF FIVEPT=5 THEN FIVEPT=100;END;
*****************************************************************;
IF I1SF=1 THEN I1SF=5.0;
 ELSE IF I1SF=2 THEN I1SF=4.4;
 ELSE IF I1SF=3 THEN I1SF=3.4;
 ELSE IF I1SF=4 THEN I1SF=2.0;
 ELSE IF I1SF=5 THEN I1SF=1.0;
I1SF=(I1SF-1)*25;
IF I21SF>.Z AND I22SF>.Z THEN DO;
 IF I22SF=1 AND I21SF=1 THEN I22SF=6;
   ELSE IF I22SF=1 AND 7>I21SF>1 THEN I22SF=5;
   ELSE IF I22SF=2 AND 7>I21SF>0 THEN I22SF=4;
   ELSE IF I22SF=3 AND 7>I21SF>0 THEN I22SF=3;
   ELSE IF I22SF=4 AND 7>I21SF>0 THEN I22SF=2;
   ELSE IF I22SF=5 AND 7>I21SF>0 THEN I22SF=1;END;
IF I21SF<=.Z AND I22SF>.Z THEN DO;
 IF I22SF=1 THEN I22SF=6.0;
  ELSE IF I22SF=2 THEN I22SF=4.75;
  ELSE IF I22SF=3 THEN I22SF=3.5;
  ELSE IF I22SF=4 THEN I22SF=2.25;
  ELSE IF I22SF=5 THEN I22SF=1.0;END;
IF I21SF=1 THEN I21SF=6.0;
 ELSE IF I21SF=2 THEN I21SF=5.4;
 ELSE IF I21SF=3 THEN I21SF=4.2;
 ELSE IF I21SF=4 THEN I21SF=3.1;
 ELSE IF I21SF=5 THEN I21SF=2.2;
 ELSE IF I21SF=6 THEN I21SF=1.0;
I21SF=(I21SF-1)*20;I22SF=(I22SF-1)*20;
***************************************************;

PHYFUN10=MEAN(I3,I4,I5,I6,I7,I8,I9,I10,I11,I12);
ROLEP4=MEAN(I13,I14,I15,I16);
PAIN2=MEAN(I21,I22);
SFPAIN=MEAN(I21SF,I22SF);
GENH5=MEAN(I1,I33,I34,I35,I36);
SFGENH5=MEAN(I1SF,I33,I34,I35,I36);
EMOT5=MEAN(I24,I25,I26,I28,I30);
ROLEE3=MEAN(I17,I18,I19);
SOCFUN2=MEAN(I20,I32);
ENFAT4=MEAN(I23,I27,I29,I31);

label phyfun10="Physical functioning scale";
label rolep4="Physical health problems scale";
label pain2="Pain scale";
label sfpain="SF-36 pain scale";
label genh5="General health perceptions scale";
label emot5="Emotional well-being scale";
label rolee3="Emotional health problems scale";
label socfun2="Social functioning scale";
label enfat4="Energy/fatigue scale";
label sfgenh5="SF-36 general health perceptions scale";

** include fryback.sas to compute QWB score;
%include 'fryback.sas' /source2;
run;
****************************************************;