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
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
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.
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
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.
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,
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.