- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! I did it!