/******************************************************************************/
/*                                                                            */
/*         SAS Program to Convert SAS Export Files to SAS Data Files          */
/*                       TIMSS Advanced 2015 User Guide                       */
/*                                                                            */
/******************************************************************************/

OPTIONS NONOTES MPRINT ;

%MACRO DOIT (TYPE   = ,
             INDIR  = ,
             OUTDIR = ) ;

  LIBNAME OUTDIR "&OUTDIR" ;

  * Start of file type processing loop ;

  %DO  F = 1 %TO %SYSFUNC(COUNTW(&TYPE)) ;
    %LET FTYPE = %SCAN(&TYPE,&F) ;

    * List of TIMSS Advanced 2015 advanced mathematics countries ;

    %IF %UPCASE(%SUBSTR(&FTYPE,1,1)) = M %THEN %DO ;

      %LET COUNTRY = FRA ITA LBN NOR PRT RUS RTR SVN SWE USA ;

    %END ;

    * List of TIMSS Advanced 2015 physics countries ;

    %IF %UPCASE(%SUBSTR(&fTYPE,1,1)) = P %THEN %DO ;

      %LET COUNTRY = FRA ITA LBN NOR PRT RUS SVN SWE USA ;

    %END ;

  * Start of country processing loop ;

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

      PROC CIMPORT FILE="&INDIR.\&FTYPE&CTRY.M3.EXP"
                   DATA=OUTDIR.&FTYPE&CTRY.M3 ;
      RUN ;

      * End of country processing loop ;

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

    * End of file type processing loop ;

  %END ;

%MEND DOIT ;

%DOIT (TYPE   = MCG MSA MSG MSR MST MTG
                PCG PSA PSG PSR PST PTG ,
       INDIR  = <specify location of SAS export files using format "x:\xxx"> ,
       OUTDIR = <specify location of SAS data files using format "x:\xxx"> ) ;
