We’re smarter together. Learn from this collection of community knowledge and add your expertise.

proc import multiple csv files

by Contributor sundeep23 on ‎09-02-2014 04:07 PM - edited on ‎10-05-2015 03:42 PM by Community Manager (1,954 Views)

\Hi all,

         I am trying to import and merge multiple csv files in to one and I cant use infile statement as I dont know the format of the variables yet .I have tried the below code and the problem I am getting in that it is taking the variable names in the second file as data. Is there a way that to skip the header of the second file.Thansk for the help.




filename csvs ('file1.csv', 'file2.csv');


proc import out=work.data


datafile = csvs










by Super User
on ‎09-02-2014 06:41 PM

Ask a question instead of posting an article.

Use ONE of the files in the filename and then look at the code that proc import generates, either copy from log or use F4 key to recall the submitted code.

Edit as needed.

by Super User
on ‎09-02-2014 07:27 PM

You should make this a question instead of an article. It might require that you re-post the message.

One suggestion is to run a simple data step to copy the two files into one and exclude the header line from the second file.

filename single temp;

data _null_;

   infile csvs eov=eov lrecl=30000 ;

   file single lrecl=30000 ;

   input ;

   if not eov then put _infile_;



Here is another suggestion that works ok for a small number of files.  Import one of the files. Then use the result as a template to read the second file.  You will need to either manually enter the first and last variable names or you could pull that information from the metadata.

data two ;

if 0 then set one ;

infile "file2.csv" dsd firstobs=2 trunover ;



Your turn
Sign In!

Want to write an article? Sign in with your profile.

Looking for the Ask the Expert series? Find it in its new home: communities.sas.com/askexpert.