BookmarkSubscribeRSS Feed
jhhuh
Calcite | Level 5

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!

2 REPLIES 2
Reeza
Super User

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

jhhuh
Calcite | Level 5

Thanks! I did it!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 843 views
  • 3 likes
  • 2 in conversation