DATA Step, Macro, Functions and more

Writing text Files to a ZIP archive using SAS ODS Package or FILENAME ZIP

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Writing text Files to a ZIP archive using SAS ODS Package or FILENAME ZIP

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.


Accepted Solutions
Solution
‎01-22-2017 09:52 AM
Respected Advisor
Posts: 3,887

Re: Writing text Files to a ZIP archive using SAS ODS Package or FILENAME ZIP

[ Edited ]

@Jim_Cooper_hmsa

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;

 

View solution in original post


All Replies
Super User
Posts: 17,785

Re: Writing text Files to a ZIP archive using SAS ODS Package or FILENAME ZIP

Do you have x command enabled? 

Honeslty this is easier to accomplish via line commands. 

New Contributor
Posts: 3

Re: Writing text Files to a ZIP archive using SAS ODS Package or FILENAME ZIP

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.

 

Solution
‎01-22-2017 09:52 AM
Respected Advisor
Posts: 3,887

Re: Writing text Files to a ZIP archive using SAS ODS Package or FILENAME ZIP

[ Edited ]

@Jim_Cooper_hmsa

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;

 

New Contributor
Posts: 3

Re: Writing text Files to a ZIP archive using SAS ODS Package or FILENAME ZIP

Patrick,
I was hoping to avoid converting the data for the reason that you had identified. However, Your solution is acceptable.
Thanks
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 160 views
  • 0 likes
  • 3 in conversation