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
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.
In SAS 9.4, FILENAME ZIP was introduced to read and import ZIP files.
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;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.
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;
- 'gzip' is not recognized as an internal or external command, operable program or batch file
- 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;SAS 9.4 : Steps to unzip ZIP files
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;
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;
Doesn't SAS 9.4 include a built-in method to read ZIP files without external ZIP software?
ReplyDeleteYes 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.
DeleteI have a .gz file on my server (linux) and have 7z on my local machine , can i will be able to read the .gz file. task is to read the no. of file inside it and i am willing to use dopen , DNUM AND DREAD to get it done.
ReplyDeleteI have a .gz file on my server (linux) and have 7z on my local machine , can i will be able to read the .gz file. task is to read the no. of file inside it and i am willing to use dopen , DNUM AND DREAD to get it done.
ReplyDelete