NC STATE University
SAS Consulting, Department of Statistics 
SAS version 8.2, UNIX and PC

Using wildcards to read many files into one SAS data set.

You can now use wildcards on the FILENAME and INFILE statements. This makes reading multiple files simple in comparison with the old methods.

Code Sample 1:

This code will read all the files in the data subdirectory of the Current Folder into the data set Weather.

  data Weather;
  infile 'data/*.*' dlm='09'x dsd missover firstobs=2;
  input station week time tmax tmin prec snow;
  run;

Code Sample 2:

This code will read all the files in the data subdirectory of the Current Folder that have the extension txt into the data set Weather.

  data Weather;
  infile 'data/*.txt' dlm='09'x dsd missover firstobs=2;
  input station week time tmax tmin prec snow;
  run;

Code Sample 3:

This code will read all the files in the data subdirectory of the Current Folder that have the extension txt into the data set Weather. This example uses the wildcard on the filename statement instead of the infile statement.

filename dat 'data/*.txt';
  data Weather;
  infile dat dlm='09'x dsd missover firstobs=2;
  input station week time tmax tmin prec snow;
  run;

Maintained by:Sandy Donaghy and Joy Smith
Last Modified:
Filename: