Read ZIP or GZ Files in SAS


SAS Analytics : Practical SAS, Statistics & Analysis Course

This tutorial describes how to read or unzip .ZIP or .GZ files in SAS. When i tried to unzip files in SAS first time, i struggled a lot. It's a little bit tricky to read .GZ files into SAS directly.

Steps to unzip GZ files in SAS

1. Download GZIP software
2. Extract file and copy path of gzip.exe
3. Replace the highlighted line of code below with your path
filename foo pipe '"C:\Users\Deepanshu\Downloads\gzip124xN\gzip.exe" -cd C:\Users\Deepanshu\Downloads\Newfolder\20090827.gz' ; 
DATA mydata;
INFILE foo dlm='|' lrecl=32767 dsd;
length sym $ 10 se $ 2 cf $ 2;
input sym $ se $ OP HP LP CP LTP TQ VS NT  cf$ ;
RUN;
If you encounter the following issues while importing zipped files in SAS, it means either you have not downloaded GZIP software or you have not assigned path of executable GZIP file.

  1. 'gzip' is not recognized as an internal or external command, operable program or batch file
  2. cannot locate the end of the central directory 


Prior to SAS 9.4 : Steps to unzip ZIP files

Download WINZIP software.

The following example reads the cars.txt file from the cars.zip file.
filename foo pipe '"C:\Users\Deepanshu\Winzip\winzip.exe" -o -c
                     c:\cars.zip   cars.txt' ;
DATA mydata;
INFILE foo dlm='|' lrecl=32767 dsd;
length sym $ 10 se $ 2 cf $ 2;
input sym $ se $ OP HP LP CP LTP TQ VS NT  cf$ ;
RUN;
SAS 9.4  : Steps to unzip ZIP files

In SAS 9.4, FILENAME ZIP was introduced to read and import ZIP files.

filename foo ZIP 'C:\cars.zip' member="cars.txt" ;
DATA mydata;
INFILE foo dlm='|' lrecl=32767 dsd;
length sym $ 10 se $ 2 cf $ 2;
input sym $ se $ OP HP LP CP LTP TQ VS NT  cf$ ;
RUN;
Coursera Data Science

SAS Tutorials : 100 Free SAS Tutorials

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

3 Responses to "Read ZIP or GZ Files in SAS"

  1. Doesn't SAS 9.4 include a built-in method to read ZIP files without external ZIP software?

    ReplyDelete
    Replies
    1. Yes you are right. SAS 9.4 includes a built-in method to read ZIP files. As most of SAS users are still using version of SAS prior to 9.4, it would be required to have external ZIP software. I have also added FILENAME ZIP method for SAS 9.4 users.

      Delete

Next → ← Prev