Add files to Zip Folder

Reply
Contributor
Posts: 52

Add files to Zip Folder

I've a loop program that creates several CSV files and I need to add these CSV files to the zip folder in SAS. How can I accomplish adding the files in loop.


I'm creating 10 CSV files when 10 loops are executed. Every time loops ends, it creates a file that needs to be zipped and added to zip folder.   How can I accomplish this ?

 

I'm using the following syntax within the loop but it's just adding the last file and it seems every time loop executes, it's just over-writing it - but I need to add them.

 

filename file&i "&dir1\&_stmt_out." ;

ods package(zipfile) open nopf;
ods package(zipfile) add file =file&i;
ods package(zipfile) publish archive properties (archive_name="Stmt_Zip" archive_path="&dir\zip\");
ods package(zipfile) close;

 

Any suggestions are appreciated !

 

Thanks in advance !

Super User
Posts: 19,105

Re: Add files to Zip Folder

You need to move things to the correct location. 

 

Ods package open should be before the macro starts or before the loop. 

ODS publish and close goes after the macro ends or end of the loop. 

Within the loop you have each iteration adding a file to the still open package. 

Think of it as an order of operations issue. 

 

AFAIK

you can't add files to an already created ZIP.  So once you've closed the output you can no longer add files, changing when you close it gets around this. 

http://www.lexjansen.com/nesug/nesug07/ff/ff17.pdf

Contributor
Posts: 52

Re: Add files to Zip Folder

Thank you Reeza,
Your solution was great and it's working !
Cheers,
Ask a Question
Discussion stats
  • 2 replies
  • 257 views
  • 2 likes
  • 2 in conversation