11-28-2016 06:41 AM
If you tweak my code very slightly, you preserve the first header line:
filename have ("$HOME/sas/customer1.csv","$HOME/sas/customer2.csv","$HOME/sas/customer3.csv"); filename want "$HOME/sas/customer.csv"; data _null_; infile have; file want; input; if (substr(_infile_,1,4)) ne 'Name' or _n_ = 1; put _infile_; run;
11-17-2016 04:04 AM
You can combine multiple external files into one fileref:
filename inpfile ("filename1","filename2","filename3");
11-17-2016 11:31 AM
Thank you for the reply. However once again I need little help to accomplish this task.When I tried the following code, headers of each file is getting concatenated in the final output (want) file. I just wanted to combine values of each file with one header as headers are same across the file.
filename have ("/sas/customer1.csv", "/sas/customer2.csv", "/sas/customer3.csv"); filename want '/sas/customer.csv'; data _null_; file want infile have input; put _infile_; run;
11-17-2016 11:55 AM
You need to identify (with a proper substring) the header records and omit them with a subsetting if.
11-17-2016 12:16 PM
I couldn't understand. Appriciate if you could provide some outline in terms of program to achieve this.
Assume I've the output file as follows.
I'm looking for output like,
Thanks in advance for any inputs you offer me.
11-17-2016 12:46 PM
The second example explicitly deals with multiple files, that have multiple headers.
Read through it
11-18-2016 05:36 PM
You want to skip reading the header row. This can be done in a data step with the EOV option and some additional coding.
A very rough skeleton of the program would look like this:
data want; infile "C:\Path\*.csv" delimiter=',' DSD lrecl=32767 firstobs=2 eov=skip missover; /*anything else you may want befor the input such as Informat statements*/ input @; /*this reads in the "current" line and holds. This sets the value of the EOV (End Of file Variable) */ if Skip then do; skip = 0; end; else do; input /* input variable list*/ ; /* any other code you may need*/ output; /* explicitly write to the output set*/ end; run;
The resetting of the variable Skip, my name nothing magical, is required otherwise you can end up in an infinite loop.
The example requires you to put the variable names and such code.
11-17-2016 02:26 PM
if substr(_infile_,1,4) ne 'Name';
11-23-2016 01:28 PM
Still I'm not getting the desired output. There is no change in the output file after adding the if clause before put statement. My code is
filename have ("/sas/customer1.csv", "/sas/customer2.csv", "/sas/customer3.csv"); filename want '/sas/customer.csv'; data _null_; file want infile have input; if substr(_infile_,1,4) ne 'Name'; put _infile_; run;
11-23-2016 04:36 PM - edited 11-23-2016 04:37 PM
The code you've posted will read the 3 .csv from source and write all the records except the ones having "Name" at the beginning of a line to a single output file named customer.csv
Your code as such will work IF you add semicolons after "file want" and "infile have"....
11-28-2016 04:22 AM - edited 11-28-2016 04:23 AM
Define "not working".
If you get errors,
Need further help from the community? Please ask a new question.