BookmarkSubscribeRSS Feed
jammy
Calcite | Level 5


Hi,

Due to my lack / limited use of macro's, I'm hoping someone would be kind enough to help me out.

I have a number of files saved in a folder:

Folder:

Beacon_Data\data\sas\

Files:

ERCH_1.txt

ERCH_2.txt

:::::::::::::::::

:::::::::::::::::

ERCH_50.txt

I have used a basic proc input to bring in one file (I can format after) but I've searched the web on how to read all the files in & I fail when I get to reading the what files are in the directory..

PROC IMPORT OUT= WORK.All_ERCH

DATAFILE= "\data\sas\ERCH_1.txt" dbms=dlm    replace; delimiter= ';'

getnames=yes;

run;

Instead of confusing matters with the code I have copied from various sites, I hope this is a easy program to help with.

Many thaanks

5 REPLIES 5
Reeza
Super User

You don't need a macro, you can use a wildcard to import the files. Import once and get your file structure.

http://listserv.uga.edu/cgi-bin/wa?A2=ind1210a&L=sas-l&H=1&F=&S=&P=1046


jammy
Calcite | Level 5

I have tried using the wildcard, if you mean:

PROC IMPORT OUT= WORK.All_ERCH

DATAFILE= "\beacon_data\sas\*.txt" dbms=dlm    replace; delimiter= ';'

getnames=yes;

run;

This does import all the tables, it includes all the headers from each table.  I can clean the data, but I'd like a more efficient way to do the import.

Ksharp
Super User

How about this. Or you can use it to write a macro. they are the same.

data have;
 input file : $20.;
cards;
ERCH_1.txt
ERCH_2.txt
;
run;
data _null_;
 set have;
 call execute('proc import datafile="c:\temp\'||strip(file)||'" out='||strip(scan(file,1,'.'))||' dbms=dlm replace; delimiter=";" ;
getnames=yes;run;');
run;


Ksharp

Reeza
Super User

24707 - Reading multiple files with PROC IMPORT

Click on the full code tab to get the code.

There is also a second option (linked from the first page) that shows how to import it all into one dataset.

Good luck.

sas4ml
Fluorite | Level 6

Here is a link to read multiple raw data files with the same structure in one data step. Hope this helps.

http://www.ats.ucla.edu/stat/sas/faq/multi_file_read.htm

Thanks,

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 6812 views
  • 0 likes
  • 4 in conversation