\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;
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.
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;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.