DATA Step, Macro, Functions and more

infile multiple data one at a time

Reply
Contributor
Posts: 20

infile multiple data one at a time

Hi,

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);

filename=cats("&subdir",filename);

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

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

run;

%put _user_;

%macro import;

%do i=1 %to &nobs;

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

       getnames=no; run;

%end;

%mend import;

%import

%end;

%mend data;

%data

The infile statement is..

data a;

infile "path/filenema" firstbos=2;

input v1 v2 v3 v4 v6;

run;

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

so any advice would be really appreciated!

Super User
Posts: 19,770

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.

http://www2.sas.com/proceedings/sugi29/057-29.pdf

Contributor
Posts: 20

Re: infile multiple data one at a time

Thanks! I did it!

Ask a Question
Discussion stats
  • 2 replies
  • 186 views
  • 3 likes
  • 2 in conversation