/******************************************************************************/
/*                                                                            */
/*         SAS Program to Convert SAS Export Files to SAS Data Files          */
/*                           PIRLS 2016 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 PIRLS 2016 countries ;

    %LET COUNTRY = AUS AUT AZE BHR BFL BFR BGR CAN CHL TWN
                   CZE DNK ENG FIN FRA GEO DEU HKG HUN IRN
                   IRL ISR ITA KAZ LVA LTU MAC MLT MAR NLD
                   NZL NIR NOR OMN POL PRT QAT RUS SAU SGP
                   SVK SVN ESP SWE TTO ARE USA
                   ABA COT CQU NO4 RMO ZA5 EAN EMA AAD ADU ;

  * Start of country processing loop ;

    %DO I = 1 %TO %SYSFUNC(COUNTW(&COUNTRY)) ;
      %LET CTRY = %SCAN(&COUNTRY,&I) ;

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

      * End of country processing loop ;

    %END ;

    * End of file type processing loop ;

  %END ;

%MEND DOIT ;

%DOIT (TYPE   = ACG ASA ASG ASH ASR AST ATG ,
       INDIR  = <specify location of SAS export files using format "x:\xxx"> ,
       OUTDIR = <specify location of SAS data files using format "x:\xxx"> ) ;
