Your SAS programs, embedded in web apps and elsewhere

Creating a SP that zips files without using the x command

Reply
Occasional Contributor
Posts: 12

Creating a SP that zips files without using the x command

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.
SAS Super FREQ
Posts: 8,740

Re: Creating a SP that zips files without using the x command

Hi:
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:
[pre]
*** PASS THE NEWLY-CREATED TEXT FILE IN AS AN ARGUMENT TO WINZIP.;
x 'c:\progra~1\winzip\winzip32.exe -min -a -p c:\test.zip @c:\temp\zipfiles.txt';

*** step 6: Now, email the zip file;
[/pre]
(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.

cynthia
Occasional Contributor
Posts: 12

Re: Creating a SP that zips files without using the x command

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!
SAS Super FREQ
Posts: 8,740

Re: Creating a SP that zips files without using the x command

Hi:

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:
[pre]

*ProcessBody;
%let _odsoptions= newfile=proc;

%stpbegin;

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

proc print data=sashelp.shoes(obs=10);
title 'shoes';
run;

proc freq data=sashelp.shoes;
tables region;
title 'freq';
run;

%stpend;
[/pre]
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: http://support.sas.com/rnd/itech/doc/app/pkgintf/ins_file.html.

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.

cynthia
Ask a Question
Discussion stats
  • 3 replies
  • 318 views
  • 0 likes
  • 2 in conversation