Importing multiple files into SAS
Importing multiple files into SAS
(OP)
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?
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?
RE: Importing multiple files into SAS
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
http://sites.google.com/site/sasbuddy/
RE: Importing multiple files into SAS
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