options ls=78 ps=56 nocenter;
 
 /*  SF-36 v2 US version */

/*
Weighting of domain scores from Brazier JE, Roberts JR, (2004) 
The estimation of a preference-based index from the SF-12. 
Medical Care, 42: 851-859. 

Karen Spritzer for Ron Hays 5/2012.
Based on Brazier's sf6d_sf36v2_US_mod.sas.
Every effort made to test and verify accuracy of results.
*/ 

*-------------------------------------------------------------------;
/* INPUT A FEW DUMMY TEST CASES */

DATA test;
INPUT sf1-sf36 AGE MALE;
CARDS;
4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 42 1
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 33 1
3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 0
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 45 0
4 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 19 0
2 1 1 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 67 1
1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 2 1 1 1 1 1 1 1 1 2 2 2 1 1 2 1 1 1  . 1
1 1 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 1 1 1 1 5 5 1 1 5 5 1 5 5 5 1 5 1 77 1
1 1 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 1 1 1 1 6 6 1 1 6 6 1 6 5 5 1 5 1 56 0
5 5 1 1 1 . . . . . . . 1 1 1 1 1 1 1 5 6 5 6 1 1 6 6 1 1 6 1 1 . . . 5 48 1
;
RUN; 

/* clean out-of-range values */
data test; set test;
array five sf1 sf2 sf13-sf20 sf22-sf36;
array three sf3-sf12;
array six sf21;
do over five;
if five not in (1,2,3,4,5) then five=.;
end;
do over three;
if three not in (1,2,3) then three=.;
end;
if sf21 not in (1,2,3,4,5,6) then sf21=.;
run;
*------------------------------------------------------------------------;

data test ; set test;

/* Physical functioning */
SFPhys=.;
if (sf3=3 & sf4=3 & sf12=3)              then SFPhys = 1 ;
if (sf3=1 or sf3=2) & (sf4=3) & (sf12=3) then SFPhys = 2 ;
if (sf4=2 & sf12=3)                      then SFPhys = 3 ;
if (sf4=1 & sf12=3)                      then SFPhys = 4 ;
if (sf12=2)                              then SFPhys = 5 ;
if (sf12=1)                              then SFPhys = 6 ;

/* Role limitations */
SFRole=.;
if (sf15=5 & sf18=5)                         then SFRole = 1 ;
if (sf15 in (1,2,3,4) & sf18=5)              then SFRole = 2 ;
if (sf18 in (1,2,3,4) & sf15=5)              then SFRole = 3 ;
if (sf15 in (1,2,3,4) & (sf18 in (1,2,3,4))) then SFRole = 4 ;

/* Social functioning */
SFSocial=.;
if (sf32=5) then SFSocial = 1 ;                              
if (sf32=4) then SFSocial = 2 ;
if (sf32=3) then SFSocial = 3 ;
if (sf32=2) then SFSocial = 4 ;
if (sf32=1) then SFSocial = 5 ;

/* Bodily pain */
SFpain=.;
if (sf21=1 & sf22=1)              then SFPain = 1 ;    
if (sf21 in (2,3,4,5,6) & sf22=1) then SFPain = 2 ;
if (sf22=2)                       then SFPain = 3 ;
if (sf22=3)                       then SFPain = 4 ;
if (sf22=4)                       then SFPain = 5 ;
if (sf22=5)                       then SFPain = 6 ;

/* Mental health */
SFMental=.; 
if (sf24=5) & (sf28=5)            then SFMental=1 ;                                     
if (sf24=4) & (sf28 in (4,5))     then SFMental=2 ;                                     
if (sf28=4) & (sf24=5)            then SFMental=2 ;                                     
if (sf24=3) & (sf28 in (3,4,5))   then SFMental=3 ;                                     
if (sf28=3) & (sf24 in (4,5))     then SFMental=3 ;                                     
if (sf24=2) & (sf28 in (2,3,4,5)) then SFMental=4 ;                                     
if (sf28=2) & (sf24 in (3,4,5))   then SFMental=4 ;                                     
if (sf24=1)                       then SFMental=5 ;                                     
if (sf28=1)                       then SFMental=5 ;                                     

/* Vitality */
SFVital=.;
if (sf27=1) then SFVital = 1 ;                               
if (sf27=2) then SFVital = 2 ;
if (sf27=3) then SFVital = 3 ;
if (sf27=4) then SFVital = 4 ;
if (sf27=5) then SFVital = 5 ;

most=0;
if SFPhys   in (4,5,6) or 
   SFRole   in (3,4)   or
   SFSocial in (4,5)   or
   SFPain   in (5,6)   or
   SFMental in (4,5)   or
   SFVital  in (4,5)   then most=1;

/* Weighting */

if (SFPhys=1) then pf1 =     0 ; 
if (SFPhys=2) then pf1 = -.035 ; 
if (SFPhys=3) then pf1 = -.035 ; 
if (SFPhys=4) then pf1 = -.044 ; 
if (SFPhys=5) then pf1 = -.056 ; 
if (SFPhys=6) then pf1 = -.117 ; 

if (SFRole=1) then rl1 =     0 ;
if (SFRole=2) then rl1 = -.053 ;
if (SFRole=3) then rl1 = -.053 ;
if (SFRole=4) then rl1 = -.053 ;

if (SFSocial=1) then sc1 =     0 ;
if (SFSocial=2) then sc1 = -.057 ;
if (SFSocial=3) then sc1 = -.059 ;
if (SFSocial=4) then sc1 = -.072 ;
if (SFsocial=5) then sc1 = -.087 ;

if (SFPain=1) then pn1 =     0 ;
if (SFPain=2) then pn1 = -.042 ;
if (SFPain=3) then pn1 = -.042 ;
if (SFPain=4) then pn1 = -.065 ;
if (SFPain=5) then pn1 = -.102 ;
if (SFPain=6) then pn1 = -.171 ;

if (SFMental=1) then mh1 =     0 ;
if (SFMental=2) then mh1 = -.042 ;
if (SFMental=3) then mh1 = -.042 ;
if (SFMental=4) then mh1 = -.1   ;
if (SFMental=5) then mh1 = -.118 ;

if (SFVital=1) then v1 =     0 ;
if (SFVital=2) then v1 = -.071 ;
if (SFVital=3) then v1 = -.071 ;
if (SFVital=4) then v1 = -.071 ;
if (SFVital=5) then v1 = -.092 ;

if most=0 then mst1 =     0;
if most=1 then mst1 = -.061;

/* index */

SFIndex = 1 + pf1+rl1+sc1+pn1+mh1+v1+mst1 ;
run; 
*-------------------------------------------------------------------;
TITLE "SF6d using SF36v2 (US)";
proc means data=test maxdec=4;
var pf1 rl1 sc1 pn1 mh1 v1 mst1 Sfindex;
run;