BookmarkSubscribeRSS Feed
Obsidian | Level 7
Hi All,

I have been searching for almost a day now for some example code that I can use to create a stored process that will zip files. I tried the simple x command

x 'winzip -a "&tofile" "&fromfile"';

However receive the error that it is not allowed to perform that action (I am guessing that SP's act like EG in that x commands can not be executed).

I have also tried a suggestion to use the file and pipe command and receive an error that I do not have proper authorization to use pipe. I have tried a third example of a VB Script which keeps giving me errors of the VB kind. I also wanted to include some sort of message back so that if a person was running this stored process from within one of the AMO options they would see something returned when it was completed.

Has anyone created a stored process yet that performs zipping files. The reason we are looking at this as a stored process is that SAS and the files that people most commonly need to zip are on the save remote server. No one has actual rights to login and do the zip from a command line. We are looking for a more automated way of doing it and SAS seemed like a good choice.
If you set your stored process result type to "PERMANENT" package, then you can get the RESULTS put into a SAS Package file (an .spk file). When you register the SP -- you have 2 choices for where the .spk file should reside -- you can put it into a webDAV location or you can write it to the server file system.

An SPK file is VERY similar to a zip file -- it is a compressed, binary format that can be "unpackaged" with the SAS package reader, which is freely downloadable and distributable. I actually CAN open an SPK file with WinZip -- but the PackageMetaData file is unreadable -- this is the SAS Package Reader stuff -- but still the HTML and PNG file in my package were extractable with WinZip. This may not be true (that WinZip will work) on ALL instances of an SPK file.

The only method that I've used to successfully create a ZIP file with SAS did involve using an X command, where I had a TXT file with the list of files that needed to be zipped together:
x 'c:\progra~1\winzip\winzip32.exe -min -a -p c:\ @c:\temp\zipfiles.txt';

*** step 6: Now, email the zip file;
(but it was NOT in a stored process). I understand that there is a similar command to use TAR on a file on UNIX.

You might consider contacting Tech Support. There may be a way to turn on the X command on the server. Or, they may know of other methods to zip files. Or, they may know of a way for you to write your files to another platform or server without using zip technology.

Obsidian | Level 7
Thanks, Cynthia, for the suggestion to use SPK files. I have finally figured out the code and can get it to work as a stored process! One question ... is it possible to pass multiple file names to a single member name so that the spk file has more than just one file, or even a wildcard to do all the datasets in one directory? If you would like to see what I have so for just let me know. I can copy it for you.

Thanks again!

There is a syntax which allows you to publish packages using DATA step syntax. I have not done much with that. I've never had the need to create multiple SPK files from one stored process.

I guess I also don't understand what you mean..."so that the spk file has more than just one file". If I create this stored process:

%let _odsoptions= newfile=proc;


proc print data=sashelp.class noobs;
title 'one output';

proc print;
title 'shoes';

proc freq;
tables region;
title 'freq';

And then I register the SP to create a permanent file called try_pkg.spk -- when I run the SP and then look inside the SPK file, I have 3 separate HTML files: SASHTML.HTM (contains the first proc print), SASHTML1.HTM (contains the second proc print) and SASHTML2.HTM (contains the proc freq output). At this point if I go to save them from the SAS package, I can name them anything I want.

However, if you are going to publish to a permanent package and want to control each item that gets put into the package and set the name for each item that gets put into the package, then you may have to use the PUBLISH syntax. For example, the CALL INSERT_FILE statement, as described here:

But, as I said, I have not worked enough with this syntax to be sure of how to help you. You are better off working with Tech Support on this question.




Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.


Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 


Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2 in conversation