\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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.