How to read zip files in SAS?

You can read zip files in SAS without having to decompress the file first. SAS will first unzip the file and then input the data set through the zip engine.

Let’s say that we have some CSV files stored in a ZIP folder. We want SAS to extract these files and use them as data sets.

As an example, we created a ZIP file with three files :
  |__ class.csv
  |__ cars.csv
  |__ prdsale.csv

Read zip files in SAS using Proc Infile

filename inzip ZIP '/home/9to5sas/inputs/';
data newdata;
infile inzip(class.csv) firstobs=2 dlm=",";
input Name $ Sex $ Age Height Weight;

Read zip files in SAS using Proc Import

To read zip files in SAS using Proc Import does require an extra step. Proc Import cannot access the content directly while it’s in the archive.

So, the additional step is to copy the file to another location like in the temporary work location and then extracting it from the ZIP file.

You can even read xlsx file using this method.
  |__ class.xlsx
  |__ cars.xlsx
  |__ prdsale.xlsx
filename inzip ZIP '/home/9to5sas/inputs/';

/* copy the file to working directory and then load it */
filename readExcel "%sysfunc(getoption(work))/class.xlsx" ;

data _null_;
infile inzip(class.xlsx) 
lrecl=256 recfm=F length=length eof=eof unbuf;
file readExcel lrecl=256 recfm=N;
put _infile_ $varying256. length;

proc import datafile=readExcel out=label dbms=xlsx replace;

We hoped this article helped you to read zip files in SAS. Moreover, if you have any other suggestions, suggest them in the comment section. We would really take those lists in our further blog post.

Thanks for reading!

You may also want to read How to zip and Unzip files in SAS?

Every week we'll send you SAS tips and in-depth tutorials



Subhro provides valuable and informative content on SAS, offering a comprehensive understanding of SAS concepts. We have been creating SAS tutorials since 2019, and 9to5sas has become one of the leading free SAS resources available on the internet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.