/******************************************************************************/
/*                                                                            */
/*                SAS Program to Score the TIMSS Advanced 1995                */
/*                         Advanced Mathematics Items                         */
/*                       TIMSS Advanced 2008 User Guide                       */
/*                                                                            */
/******************************************************************************/

OPTIONS NONOTES ;

* Specify the path for the SAS data files following the format x:\xxx\ ;
* <path> must be edited ;

LIBNAME LIBDAT "<path>" ;

* Specify the list of countries to be processed ;

%LET COUNTRY = AUS AUT CAN CYP CZE FRA DEU DNK GRC ISR
               ITA LTU RUS SVN SWE CHE USA ;

* List of multiple-choice items with A key ;

%LET ARIGHT = MA13002  MA13007  MA13011  MA13021  MA13065  MA13068  MA13084
              MA13090  MA13093  ;

* List of multiple-choice items with B key ;

%LET BRIGHT = MA13004  MA13018  MA13019  MA13024  MA13067  MA13070  MA13082
              MA13086  MA13087  ;

* List of multiple-choice items with C key ;

%LET CRIGHT = MA13009  MA13012  MA13015  MA13020  MA13066  MA13073  MA13085
              MA13088  ;

* List of multiple-choice items with D key ;

%LET DRIGHT = MA13001  MA13006  MA13008  MA13016  MA13069  MA13074  MA13083  ;

* List of multiple-choice items with E key ;

%LET ERIGHT = MA13003  MA13013  MA13017  M013064  M013089  ;

* List of constructed-response items ;

%LET CONSTR = MA13025A MA13025B MA13026A MA13026B MA13027  MA13028  MA13029
              MA13075  MA13076  MA13077  MA13078  MA13079  MA13080  MA13081
              MA13094  MA13095  MA13097  MA13098  MA13099  ;

%MACRO SCOREIT (ITEM, TYPE, RIGHT, NR, NA, OM, OTHER) ;

   * Code for multiple-choice items ;

   %IF %UPCASE(&TYPE) = "MC" %THEN %DO ;
      SCORE = 0 ;
         IF &ITEM = &RIGHT THEN SCORE = 1 ;
         IF &ITEM = &NR    THEN SCORE = 0 ; * Not Reached ;
         IF &ITEM = &NA    THEN SCORE = . ; * Not Administered ;
         IF &ITEM = &OM    THEN SCORE = 0 ; * Omitted ;
         IF &ITEM = &OTHER THEN SCORE = 0 ; * Other Missing ;
      &ITEM = SCORE ;
   %END ;

   * Code for constructed-response items ;

   %IF %UPCASE(&TYPE) = "CR" %THEN %DO ;
      SCORE = 0 ;
         IF &ITEM >= 20 AND &ITEM < 30 THEN SCORE = 2 ;
         IF &ITEM >= 10 AND &ITEM < 20 THEN SCORE = 1 ;
         IF &ITEM >= 70 AND &ITEM < 80 THEN SCORE = 0 ;
         IF &ITEM = &NR    THEN SCORE = 0 ; * Not Reached ;
         IF &ITEM = &NA    THEN SCORE = . ; * Not Administered ;
         IF &ITEM = &OM    THEN SCORE = 0 ; * Omitted ;
         IF &ITEM = &OTHER THEN SCORE = 0 ; * Other Missing ;
      &ITEM = SCORE ;
   %END ;

%MEND SCOREIT ;

%MACRO DOIT ;

   * Start of country processing loop ;

   %LET I = 1 ;
   %DO %WHILE(%LENGTH(%SCAN(&COUNTRY,&I))) ;
      %LET CTRY = %SCAN(&COUNTRY,&I) ;

      * Get the student achievement data ;

      DATA LIBDAT.MSC&CTRY.M1; * Output File ;
           SET LIBDAT.MSA&CTRY.M1; * Input File  ;

           ARRAY ARIGHT &ARIGHT ;
           ARRAY BRIGHT &BRIGHT ;
           ARRAY CRIGHT &CRIGHT ;
           ARRAY DRIGHT &DRIGHT ;
           ARRAY ERIGHT &ERIGHT ;
           ARRAY CONSTR &CONSTR ;

           DO OVER ARIGHT ; %SCOREIT (ARIGHT, "MC", 1, .R, .A, ., .I) ; END ;
           DO OVER BRIGHT ; %SCOREIT (BRIGHT, "MC", 2, .R, .A, ., .I) ; END ;
           DO OVER CRIGHT ; %SCOREIT (CRIGHT, "MC", 3, .R, .A, ., .I) ; END ;
           DO OVER DRIGHT ; %SCOREIT (DRIGHT, "MC", 4, .R, .A, ., .I) ; END ;
           DO OVER ERIGHT ; %SCOREIT (ERIGHT, "MC", 5, .R, .A, ., .I) ; END ;
           DO OVER CONSTR ; %SCOREIT (CONSTR, "CR",  , .R, .A, ., .I) ; END ;

      RUN ;

      * End of country processing loop ;

      %LET I = %EVAL(&I + 1) ;
   %END ;

%MEND DOIT ;

%DOIT ;
