BookmarkSubscribeRSS Feed

proc import multiple csv files

Started ‎09-02-2014 by
Modified ‎10-05-2015 by
Views 6,949

\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

 

DBMS=CSV REPLACE;

 

GETNAMES=YES;

 

DATAROW=2;

 

 

run;

Comments

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.

Tom

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_;

   eov=0;

run;

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 ;

input FIRSTVAR -- LASTVAR ;

run;

Version history
Last update:
‎10-05-2015 03:42 PM
Updated by:

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags