BookmarkSubscribeRSS Feed
philjones820
Fluorite | Level 6

Hello, I have a folder of 14 text delimited files that I need to import into SAS. Is it possible to import them all in at the same time rather than one at a time and is there any sample code and macro that anyone could recommend? Is there possibly a way to loop through each file from 1 to 14 and pull all 14 of the files in simultaneously?

1 REPLY 1
mkeintz
PROC Star

Are the files identically formatted?  That would make it a far simpler programming structure to process all of them in a single data step.

 

If they are all the same format then you could list all 14 filenames in a single FILENAME statement.  The list would be a comma-separated list of file names, all wrapped in parentheses:

 

filename inall ('c:\temp\t1.txt','c:\temp\t2.txt');
data want;
  infile inall;
  input a b c .... ;
run;

BTW, I don't know what "text delimited" means. Comma delimited, TAB delimited yes - but text delimited?   I suppose you mean you have field delimiters in the 14 files.  If so, then modify the INFILE statement accordingly - using whatever options you would use for any single file (again, assuming all files have the same delimiter).

 

There is no doubt a limit on the length of the delimited file list, but I assume SAS will tolerate a list of 14 files.  

 

I put the INPUT statement there as a placeholder for whatever variables you will be sasifying.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

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
  • 1 reply
  • 321 views
  • 0 likes
  • 2 in conversation