SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Combining Multiple Text Files without Formatting

Reply
Contributor
Posts: 34

Combining Multiple Text Files without Formatting

Hi all,

 

I am working with Daily data which comes in a Text File. The files have a row for each observation and are formatted in based on character length. So each row has the same length in terms of characters and using infile I am able to seperate the rows into distinct columns based on the position of the characters. 

 

However, I would like to combine these files into weekly or monthly files without disturbing the formmating of these files. All I would like to do is have SAS read Files A, B, C, etc. and append them one on top of the other and then resave this file as a text file without having manipulated or formatted the files one bit.

 

When I use the point and click method to import the files, I am able to get them into SAS without manipulating the files but I cannot figure out how to code the system to read these files without it wanting some sort of formating to be done. 

 

Garrett

Super User
Posts: 11,343

Re: Combining Multiple Text Files without Formatting

Posted in reply to SmcGarrett

The result you are asking for, appending files could well be better done with operating system tools but if your really need a SAS solution something like this:

First a FILENAME statement to reference your files. If the files have a name that matches your sort order that you want for output you might be able to use wildcard but this is the base idea:

 

Filename input ("C:\path\Firstfile.txt" "C:\path\Secondfile.txt" ...);  repeat the file names

IF all the files are in the same folder you might be able to use:

Filename input "C:\path\*.txt";

data _null_;
   infile input lrecl=10000;
   file "C:\Outpat\COMBINED.txt" lrecl=10000;
   input;
   put _infile_;
run;

the Lrecl needs to be as long as the longest line you expect.

 

NOTE: This does not create a SAS dataset, just reads lines and then writes them out again.

Super User
Posts: 19,822

Re: Combining Multiple Text Files without Formatting

Posted in reply to SmcGarrett

This question was asked last week by someone else and I posted an OS based solution.

If UNIX command is cat, I can't recall Windows command but you should be able to find it via a search. 

 

Ask a Question
Discussion stats
  • 2 replies
  • 212 views
  • 2 likes
  • 3 in conversation