Import CSV, DBF, and xlsx datasets with data compression

  1. Import table1.xlsx
PROC IMPORT OUT= WORK.table1
DATAFILE= "X:\GROUPS\Surveys\
results\4. Data\table1.xlsx"
DBMS=EXCEL REPLACE;
RANGE="table1$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
  1. Import table1.csv. Data file is systematically saved in the year folder

Method 1:

%macro survey (strtyear, stopyear);
%do yr= &strtyear %to &stopyear;
%put &yr.;
data WORK.table_&yr. ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile "X:\GROUPS\Surveys\&yr.\results\4. Data\table1.csv" delimiter = ',' TRUNCOVER DSD lrecl=32767
firstobs=2 ;
informat field1 $1. ;
informat field2 $4. ;

format field1 $1. ;
format field2 $4. ;

input
field1 $
field2 $;

label
field1 = "Label 2"
field2= "Label 2"

if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
%end;
%mend survey;
%survey (2007, 2011);

Method 2:

PROC IMPORT OUT= WORK.table_2013
DATAFILE= “L:\GROUPS\Surveys\2013\Results\4. Data\table1.csv”
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;

  1. Import dbf dataset
PROC IMPORT OUT= WORK.table_2013 (compress=yes)
DATAFILE= "L:\GROUPS\Surveys\2013\Results\4. Data\table1.dbf"
DBMS=DBF REPLACE;
GETDELETED=NO;
RUN;

Compression datasets

  1. Compressing Text data

(compress = yes)

  1. Compressing Numeric data

(compress=binary)