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
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.
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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.