Add files to Zip Folder

Posts: 67

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: 23,721

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. 



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.

Posts: 67

Re: Add files to Zip Folder

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