Sample 45256: How to zip all data sets in a directory using ODS
ODS PACKAGES can be used to zip text files as well as SAS files such as SAS data sets. Macro logic can be used to pass every SAS data set within a directory to ODS Packages, where the data sets are added and published to the zip file.
The sample code on the Full Code tab enables you to create zip files from all of the data sets within a specified directory. The macro has three parameters. DIR= is the directory in which to look for the data sets. ZIPNAME= is the name of the zip file that is created. ZIPLOC is where we want to store the zip file.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The macro below has three parameters. DIR= is the directory in which to look for the data sets. ZIPNAME= is the name of the zip file that is created. ZIPLOC is where we want to store the zip file.
%macro drive(dir=c:\temp\sas\,zipname=example.zip,ziploc=c:\temp);
%let filerf=mydir;
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));
%let memcnt=%sysfunc(dnum(&did));
%let cnt=0;
%do i = 1 %to &memcnt;
%let ext=%upcase(%scan(%qsysfunc(dread(&did,&i)),2));
%let fname=%scan(%qsysfunc(dread(&did,&i)),1);
%if &ext=SAS7BDAT %then %do;
%let cnt=%eval(&cnt+1);
%let name&cnt=&fname..&ext;
%end;
%end;
ods package open nopf;
%do j = 1 %to &cnt;
ods package add file="&dir.&&name&j" mimetype="application/x-compress";
ods package publish archive properties(archive_name="&zipname" archive_path="&ziploc");
%end;
ods package close;
%let rc=%sysfunc(dclose(&did));
%mend drive;
%drive();
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample illustrates how to zip all data sets in a directory using ODS.
Date Modified: | 2012-07-06 11:44:22 |
Date Created: | 2011-12-31 23:12:40 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.2 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
Microsoft® Windows® for x64 | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |
Microsoft Windows XP Professional | 9.2 TS1M0 | |
Windows Vista | 9.2 TS1M0 | |
Windows Vista for x64 | 9.2 TS1M0 | |
64-bit Enabled AIX | 9.2 TS1M0 | |
64-bit Enabled HP-UX | 9.2 TS1M0 | |
64-bit Enabled Solaris | 9.2 TS1M0 | |
HP-UX IPF | 9.2 TS1M0 | |
Linux | 9.2 TS1M0 | |
Linux for x64 | 9.2 TS1M0 | |
OpenVMS on HP Integrity | 9.2 TS1M0 | |
Solaris for x64 | 9.2 TS1M0 | |