DATA Step, Macro, Functions and more

infile multiple data one at a time

Posts: 20

infile multiple data one at a time


I would like to read in multiple data into SAS.

But the problem is that.. my data has no extension

(eg. drug_15_16, gorc_15_16), so I can only use infile statement to read them into SAS.

I already have a macro for reading multiple files into SAS, but it uses proc import statement.

So I need to change some parts of the macro.

Could you help me with this?

(I am using Linux operating system)

%macro data;

%do j=9 %to 10;

%let subdir=/usr17/jhhuh/year&j/toi;

filename dir pipe "ls &subdir/*.dat";

data A;

infile dir truncover end=last expandtabs ;

input filename : $100. @@;

f=scan(filename,1,'.') ;

call symputx(cats('dsn',_n_),f);


call symputx(cats('path',_n_),filename);

if last then call symputx('nobs',_n_);


%put _user_;

%macro import;

%do i=1 %to &nobs;

proc import datafile="&&path&i" out=&&dsn&i dbms=csv replace;

       getnames=no; run;


%mend import;



%mend data;


The infile statement is..

data a;

infile "path/filenema" firstbos=2;

input v1 v2 v3 v4 v6;


I am struggling with this code for almost one week..

so any advice would be really appreciated!

Super User
Posts: 17,786

Re: infile multiple data one at a time

Its rare to have files without extensions, but assuming its true, you could read all the file names in and then parse out only the ones you want.

Feed that to your input statement or proc import instead.

This doc shows how to create the file list in a dataset and read them in using a macro loop.

Posts: 20

Re: infile multiple data one at a time

Thanks! I did it!

Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation