I've written extensively about using FILENAME ZIP to read and write ZIP archives with SAS. The latest version of SAS adds support for GZIP by extending the FILENAME ZIP method. When working with GZIP files, simply add the GZIP keyword to the FILENAME statement. Example:
filename my_gz ZIP "path-to-file/compressedfile.txt.gz" GZIP;
Here's an example that creates a compressed version of a log file:
filename source "C:\Logs\SEGuide_log.10168.txt"; filename tozip ZIP "C:\Logs\SEGuide_log.10168.txt.gz" GZIP; data _null_; infile source; file tozip ; input; put _infile_ ; run;
In my test here, the result represents a significant size difference, with the compressed file occupying just 14% of the space.
filename target "C:\LogsExpanded\SEGuide_log.10168.txt" encoding='utf-8'; filename fromzip ZIP "C:\Logs\SEGuide_log.10168.txt.gz" GZIP; data _null_; infile fromzip; file target ; input; put _infile_ ; run;
You don't have to explicitly expand a compressed text file in order to read it with SAS. You can use the GZIP method to read and parse a .gz file directly, similar to the zcat command that you might be familiar with from the Unix shell:
filename fromzip ZIP "C:\Logs\SEGuide_log.10168.txt.gz" GZIP; data logdata; infile fromzip; /* read directly from compressed file */ input date : yymmdd10. time : anydttme. ; format date date9. time timeampm.; run;
If your file is in a binary format such as a SAS data set (sas7bdat) or Excel (XLS or XLSX), you probably will need to expand the file completely before reading it as data. These files are read using special drivers that don't process the bytes sequentially, so you need the entire file available on disk.
Note: Because each GZIP file represents just one compressed file, the MEMBER= option doesn't apply. When dealing with ZIP file archives that contain multiple files, you could use the MEMBER= option on FILENAME ZIP to address a specific file that you want. My recent example about FINFO and file details relies heavily on that approach. However, the GZIP option and MEMBER= options are mutually exclusive. In that way, it's much simpler...just like its Unix shell equivalent.