/******************************************************************************/
/*                                                                            */
/*                SAS Program to Score the TIMSS Advanced 1995                */
/*                               Physics 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
               LVA NOR RUS SVN SWE CHE USA ;

* List of multiple-choice items with A key ;

%LET ARIGHT = PA13001  PA13009  PA13021  PA13050  PA13053  PA13057  PA13070
              PA13071  ;

* List of multiple-choice items with B key ;

%LET BRIGHT = PA13002  PA13011  PA13014  PA13019  PA13055  PA13058  PA13072
              PA13074  PA13076  ;

* List of multiple-choice items with C key ;

%LET CRIGHT = PA13003  PA13005  PA13012  PA13013  PA13015  PA13018  PA13049
              PA13068  PA13073  PA13077  ;

* List of multiple-choice items with D key ;

%LET DRIGHT = PA13004  PA13006  PA13016  PA13017  PA13051  PA13054  PA13069
              PA13075  ;

* List of multiple-choice items with D key ;

%LET ERIGHT = PA13056  ;

* List of constructed-response items ;

%LET CONSTR = PA13022  PA13023  PA13024  PA13025  PA13026  PA13027A PA13059
              PA13060  PA13062  PA13063  PA13064  PA13065  PA13066  PA13067
              PA13079  PA13080  PA13081  PA13083  PA13084  PA13085  PA13086A
              PA13086B  ;

%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.PSC&CTRY.M1; * Output File ;
           SET LIBDAT.PSA&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 ;
