********************************************************************************
*                                                                              *
*         SAS Program to Score the TIMSS Advanced 2015 Adv Math Items          *
*                        TIMSS Advanced 2015 User Guide                        *
*                                                                              *
********************************************************************************.

SET MPRINT=ON .

DEFINE SCOREIT (TYPE  = !CHAREND('/') /
                ITEM  = !CHAREND('/') /
                RIGHT = !CHAREND('/') /
                NR    = !CHAREND('/') /
                NA    = !CHAREND('/') /
                OM    = !CHAREND('/') /
                OTHER = !CHAREND('/') ) .

  * Code for multiple-choice items .

  !IF (!UPCASE(!TYPE)=MC) !THEN
    !DO !I !IN (!ITEM) .
      RECODE !I (!RIGHT     = 1      ) /* Item Key         */
                (!NR        = 0      ) /* Not Reached      */
                (!NA        = SYSMIS ) /* Not Administered */
                (!OM        = 0      ) /* Omitted          */
                (!OTHER     = 0      ) /* Other Missing    */
                (ELSE       = 0      ) .
    !DOEND .
  !IFEND .

  * Code for constructed-response items .

  !IF (!UPCASE(!TYPE)=CR) !THEN
    !DO !I !IN (!ITEM) .
      RECODE !I (20 THRU 29 = 2      ) /* Full Credit      */
                (10 THRU 19 = 1      ) /* Partial Credit   */
                (70 THRU 79 = 0      ) /* No Credit        */
                (!NR        = 0      ) /* Not Reached      */
                (!NA        = SYSMIS ) /* Not Administered */
                (!OM        = 0      ) /* Omitted          */
                (!OTHER     = 0      ) /* Other Missing    */
                (ELSE       = 0      ) .
    !DOEND .
  !IFEND .

!ENDDEFINE .

DEFINE DOIT (INDIR  = !CHAREND('/') /
             OUTDIR = !CHAREND('/') /
             INFILE = !CHAREND('/') ) .

  * Get the student achievement data .

  GET FILE = !QUOTE(!CONCAT(!INDIR,'\',!INFILE,'.SAV')) .

  * Score multiple-choice items with A key .

  SCOREIT TYPE = MC / ITEM = MA13011   MA33086   MA33225A  MA33225D  MA33007   MA33182   MA23185
                             MA23064   MA23082   MA33201   MA33202   MA33118A  MA33011   MA33077
                             MA33132   MA33236C  /
          RIGHT = 1 / NR = 6 / NA = SYSMIS / OM = 9 / OTHER = 7 .

  * Score multiple-choice items with B key .

  SCOREIT TYPE = MC / ITEM = MA13018   MA13019   MA33225B  MA33225C  MA33225E  MA33076   MA23005
                             MA23176   MA33162   MA33198   MA33137   MA33212   MA33106   MA33126
                             MA33118C  MA33236B  MA33236D  MA33169   /
          RIGHT = 2 / NR = 6 / NA = SYSMIS / OM = 9 / OTHER = 7 .

  * Score multiple-choice items with C key .

  SCOREIT TYPE = MC / ITEM = MA13012   MA13015   MA13020   MA33044   MA33171   MA23076   MA23098
                             MA33046   MA23144   MA23045   MA33016   MA33079   MA33150   MA33186
                             MA33027   MA33118B  MA33115   MA33236A  MA33181   /
          RIGHT = 3 / NR = 6 / NA = SYSMIS / OM = 9 / OTHER = 7 .

  * Score multiple-choice items with D key .

  SCOREIT TYPE = MC / ITEM = MA13016   MA33140   MA23206   MA33050   MA33163   MA33066   MA23020
                             MA33157   MA33123   MA33075   MA33054   MA33085   /
          RIGHT = 4 / NR = 6 / NA = SYSMIS / OM = 9 / OTHER = 7 .

  * Score multiple-choice items with E key .

  SCOREIT TYPE = MC / ITEM = MA13013   MA13017   /
          RIGHT = 5 / NR = 6 / NA = SYSMIS / OM = 9 / OTHER = 7 .

  * Score Constructed-Response Items .

  SCOREIT TYPE = CR / ITEM = MA33225   MA33142   MA33179   MA33214   MA33039   MA33180   MA23145
                             MA23187   MA23201   MA23154   MA23166   MA23043   MA33008   MA33121
                             MA33240   MA33232   MA33178   MA23054   MA23131A  MA23131B  MA23157
                             MA23094   MA33083   MA33143   MA33227   MA33220   MA33233   MA33155
                             MA33042   MA33094   MA33067   MA33012   MA33239   MA33038   MA33091
                             MA33090   MA33118   MA33243   MA33229   MA33159   MA33190   MA33237
                             MA33218   MA33236   MA33002   MA33235   /
          RIGHT = 0 / NR = 96 / NA = SYSMIS / OM = 99 / OTHER = 90 .

  EXECUTE .

  * Save the student data .

  SAVE OUTFILE = !QUOTE(!CONCAT(!OUTDIR,'\',!INFILE,'_SCR.SAV')) .

  NEW FILE .

!ENDDEFINE .

DOIT INDIR  = <Specify location of input SAS data file using format "x:\xxx"> /
     OUTDIR = <Specify location of output SAS data file using format "x:\xxx"> /
     INFILE = <Specify name of merged SAS student achievement data file> .
