options ls=78 ps=56 nocenter;

/*  SF-36 v1 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_sf36v1_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 sf20 sf22 sf32-sf36;
array three sf3-sf12;
array six sf21 sf23-sf31;
array two sf13-sf19;

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;
do over six;
if six not in (1,2,3,4,5,6) then six=.;
end;
do over two;
if two not in (1,2) then two=.;
end;
run;
*------------------------------------------------------------------------;

data test ; set test;

/* Since V2, items 24, 27, and 28 do not have the version 1 option
  "a good bit of the time" then randomly map this to version 2's
  response of 2 (most of the time)  or 3 (a little of the time).
*/

rand1=uniform(-1);
rand2=uniform(-1);
rand3=uniform(-1);

sf24r=sf24;
if (sf24=2)              then sf24r=2 ;
if (sf24=3 & rand1 <0.5) then sf24r=2 ;
if (sf24=3 & rand1>=0.5) then sf24r=3 ;
if (sf24=4)              then sf24r=3 ;
if (sf24=5)              then sf24r=4 ;
if (sf24=6)              then sf24r=5 ;

sf27r=sf27;
if (sf27=2)              then sf27r=2 ;
if (sf27=3 & rand2 <0.5) then sf27r=2 ;
if (sf27=3 & rand2>=0.5) then sf27r=3;
if (sf27=4)              then sf27r=3 ;
if (sf27=5)              then sf27r=4;
if (sf27=6)              then sf27r=5 ;

sf28r=sf28;
if (sf28=2)              then sf28r=2 ;
if (sf28=3 & rand3 <0.5) then sf28r=2 ;
if (sf28=3 & rand3>=0.5) then sf28r=3 ;
if (sf28=4)              then sf28r=3 ;
if (sf28=5)              then sf28r=4 ;
if (sf28=6)              then sf28r=5 ;

/** end recode mapping **/

/*** score dimensions ***/

/* 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=2 & sf18=2)  then SFRole = 1 ;
if (sf15=1 & sf18=2)  then SFRole = 2 ;
if (sf15=2 & sf18=1)  then SFRole = 3 ;
if (sf15=1 & sf18=1)  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 (sf24r=5) & (sf28r=5)            then SFMental=1 ;
if (sf24r=4) & (sf28r in (4,5))    then SFMental=2 ;
if (sf28r=4) & (sf24r=5)            then SFMental=2 ;
if (sf24r=3) & (sf28r in (3,4,5))  then SFMental=3 ;
if (sf28r=3) & (sf24r in (4,5))    then SFMental=3 ;
if (sf24r=2) & (sf28r in (2,3,4,5)) then SFMental=4 ;
if (sf28r=2) & (sf24r in (3,4,5))  then SFMental=4 ;
if (sf24r=1)                        then SFMental=5 ;
if (sf28r=1)                        then SFMental=5 ;

/* Vitality */
SFVital=.;
if (sf27r=1) then SFVital = 1 ;
if (sf27r=2) then SFVital = 2 ;
if (sf27r=3) then SFVital = 3 ;
if (sf27r=4) then SFVital = 4 ;
if (sf27r=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 SF36v1 (US)";
proc means data=test maxdec=4;
var pf1 rl1 sc1 pn1 mh1 v1 mst1 Sfindex;
run;