I am trying to automate a process that involves receiving several text files with dates in the filename (AAYYYYMMDD.TXT format). I am attempting to iteratively:
1. Read the file into SAS for processing
2. Archive the file in a ZIPX archive
3. Delete or move the file from the working directory so that it is not processed again.
The filename zip method is only documented to read the text file into a data step and write sas datasets to a zip archive. I can not find any documentation on writing text files to a zip archive.
I also attempted to use the ODS package method, but it seems to overwrite existing files in the archive when I access the package. I need to be able to append new text files as they are processed and retain any exisitng files in the ZIP archive. I will keep testing veriations on these methods, but any assistance would be appreciated.
Without X command you'll have to read the data into SAS before writing it to a zip file which is not an ideal situation as this could alter your data (i.e. change the end-of-line indicator from CR to CRLF).
If such changes are acceptable (or controllable) then below code sample could show you the way.
/* create sample text file */
proc export
data=sashelp.class
dbms=csv
outfile="c:\temp\testtext.csv"
replace;
run;quit;
/* create and add members to zip archive */
filename foo ZIP 'c:\temp\testzip.zip' lrecl=1000000;
data _null_;
infile "c:\temp\testtext.csv";
file foo(test3.csv);
input;
put _infile_;
run;
data _null_;
infile "c:\temp\testtext.csv";
file foo(test4.csv);
input;
put _infile_;
run;
Do you have x command enabled?
Honeslty this is easier to accomplish via line commands.
Reeza,
Unfortunately, no. Our environment is a client server configuration and the security protocols don't allow the business users to run the command line on production servers. ODS package and FILENAME ZIP seem to be enabled, but not the X command. That was my first thought as well having built SAS projects in the past.
Without X command you'll have to read the data into SAS before writing it to a zip file which is not an ideal situation as this could alter your data (i.e. change the end-of-line indicator from CR to CRLF).
If such changes are acceptable (or controllable) then below code sample could show you the way.
/* create sample text file */
proc export
data=sashelp.class
dbms=csv
outfile="c:\temp\testtext.csv"
replace;
run;quit;
/* create and add members to zip archive */
filename foo ZIP 'c:\temp\testzip.zip' lrecl=1000000;
data _null_;
infile "c:\temp\testtext.csv";
file foo(test3.csv);
input;
put _infile_;
run;
data _null_;
infile "c:\temp\testtext.csv";
file foo(test4.csv);
input;
put _infile_;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.