×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Importing multiple files into SAS

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?

RE: Importing multiple files into SAS

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
http://sites.google.com/site/sasbuddy/
 

RE: Importing multiple files into SAS

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
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close