Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing multiple files into SAS

Status
Not open for further replies.

sap1958

Technical User
Oct 22, 2009
138
US
Here is my code to import one file.
data many;
infile 'v:\pcsas_export_files\many\file_1.txt';
input Code $2. /
Acct $9. /
AcctName $30. //
ID $3. /
Reg $10. /
City $15.//;
run;

In the pcsas_export_files\many I have several text files (ie file_1, file_2, file_3). The data positioning is the same and I need to import all files at the same time. Is there a procedure (ie macro) that can handle this?
 
Hi,
The solution for this is to use FILEVAR option of SAS.
For this
either you should have all the file Names listed in one text files.
or the sas dataset having filenames listed as observations.

sample code for the demo is as below;
1. Case when you have list of file names stored in other text file

DATA output_data_set;
INFILE ‘path of a file in which file names have been stored’
/* read the file references in variable called file_names */
INPUT file_names $20.;
INFILE IN FILEVAR = file_names END = end_of_file;
DO WHILE (end_of_file = 0)
INPUT ………;
OUTPUT;
END;
RUN;

2. Case when you have list of file names stored in sas dataset
DATA output_data_set;
SET data_set_name_inwhich_filenames_are_stored;
INFILE IN FILEVAR = FILE_NAMES END = end_of_file;
DO WHILE (end_of_file = 0)
INPUT ………;
OUTPUT;
END;
RUN;


Hopefully this will work.



sasbuddy
 
You can use the infile statement to specify wildcards within the filename statement.

I.e.

Data Out ;
Infile "c:\users\amit\test*.csv" ;
Input A : $4. B C D ;
Run ;

This would read in test1.csv test2.csv etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top