How to uncompress a zip file? give your suggestion.

Reply
Occasional Contributor
Posts: 9

How to uncompress a zip file? give your suggestion.

Hi All,

I am facing an issue in reading zip file. i want to read a zip file and want to place the content of zip file at different location so that i can use that file by data step or other procedures.

can anybody help me to resolve this problem?

My email id is : sanjayahir001@gmail.com

Thanks,

Sanjay

Frequent Contributor
Posts: 88

Re: How to uncompress a zip file? give your suggestion.

Hi Sanjay,

 

Sometimes data sets are compressed or archived in ZIP files. You can read such a file format directly from SAS without having to decompress the file first. SAS will first unzip the file and then input the data set through the SASZIPAM engine:

FILENAME ZIPFILE SASZIPAM 'C:\Temp\filename.zip';

DATA newdata;

INFILE ZIPFILE(dataset.csv) DLM=',' FIRSTOBS=2;

INPUT var1 $ var2 $ var3 $ var4;

RUN;

The FILENAME statement specifies the type of file you wish to unzip (e.g., ZIPFILE), the engine SASZIPAM to be used to decompress the file, and the directory and name of the file to be unzipped (e.g., 'C:\Temp\filename.zip'). The DATA statement names the data set that will be read in (e.g., newdata).

The INFILE statement gives information about the data set within the ZIP file. First, ZIPFILE indicates which file should be unzipped (e.g., dataset.csv), since there may be multiple files in filename.zip. Second, DLM signals which character is used as a delimiter in the data set. Finally, FIRSTOBS indicates that the first line in the data set contains the variable names, and that therefore SAS will begin reading the second line as data. In the INPUT statement, indicate which variable(s) should be transferred to the new data set.

Note: Large compressed data files (e.g., .txt and .csv formats) are not suited for use with the SASZIPAM engine because they will employ all computer memory and considerably delay all processes. Moreover, the SASZIPAM engine does not decompress all zip files (e.g., zip files created by 7-zip are not compatible). Consider first decompressing the file, and then compressing it with WinZIP, which is compatible with SASZIPAM.

SASZIPAM is available on SAS 9. In addition to data files, you may also use SASZIPAM to unzip log files.

Regards,

Tushar J.

Valued Guide
Posts: 3,208

Re: How to uncompress a zip file? give your suggestion.

Is available wiht 9.4, see: SAS(R) 9.4 Statements: Reference (filename zip)

The other way is using X commands, I prefer the piping method because of synchronisation and output messages, in a way handling the zip with command (dos-box) options. Alle dependends on your system environment (Windows/Unix) and the 3-party tools you have.

Using Zip in this way (one paragraph): http://www2.sas.com/proceedings/forum2008/017-2008.pdf

 

Fot the fun. most files (docx, srx egp etc) are essential a zip file.

45256 - How to zip all data sets in a directory using ODS

(in addition cross post)

http://www2.sas.com/proceedings/sugi31/155-31.pdf  (saszipam)

---->-- ja karman --<-----
Trusted Advisor
Posts: 1,621

Re: How to uncompress a zip file? give your suggestion.

As I read the docs for SAS 9.4, it does not appear that this allows you to determine what files are stored in the ZIP file (in other words, read the directory of files contained in the .zip archive, rather than read specific files). Is this possible in SAS 9.4 (or otherwise)?

Super User
Super User
Posts: 6,502

Re: How to uncompress a zip file? give your suggestion.

Did you try using DOPEN() and DREAD() functions?  I don't have 9.4 to test.

Trusted Advisor
Posts: 1,621

Re: How to uncompress a zip file? give your suggestion.

Using DOPEN() and DREAD() seems to work in SAS 9.4; I am able to read the members of a .zip file, but I can only read the member name and not the date or size.

Thus, I still prefer using the macros at:

http://www.lexjansen.com/phuse/2006/cc/cc01.pdf

which allows me to read the member name and member size, even though these macros require downloading an executable file from winzip.com

Ask a Question
Discussion stats
  • 5 replies
  • 2036 views
  • 0 likes
  • 5 in conversation