how to uncompress a file in SAS?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

how to uncompress a file in SAS?

[ Edited ]

i am using this library "LibABC" which contains many datasets in an unix server. some datasets in this library are zipped (for ex- file1.sas7bdat.Z) and some are unzipped(file2.sas7bdat).

i am not able to access those zipped datasets from the server through my sas code.

kindly help me how can i resolve this issue.

if there is any code in sas to access zipped files from unix server share it with me


Accepted Solutions
Solution
2 weeks ago
Super User
Super User
Posts: 6,330

Re: how to unzip a file in sas?

[ Edited ]

.Z is the extension used by the compress command, not ZIP or GZIP.

Use the uncompress command to expand the file and then SAS will be able to read it.

 

Editor's note: included some additional details from SAS support doc:

Here's a SAS Note with an example (which assumes the data was compressed via SAS and the compress command). It relies on FILENAME PIPE, which will require privileges to run shell commands (XCMD):

 

Creating the compressed data set: http://support.sas.com/kb/25/199.html

Reading the compressed data set: http://support.sas.com/kb/25/214.html

 

View solution in original post


All Replies
Super Contributor
Posts: 276

Re: how to unzip a file in sas?

Hi,

Hope this helps.

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

Regards,

Sanjeev.K

Occasional Contributor
Posts: 12

Re: how to unzip a file in sas?

Sanjeev,

i am not allowed to install any additional tools or software , the pdf u wanted me to refer suggests installation of some tools. So can you suggest if there is some piece of code to unzip files in sas.

Super Contributor
Posts: 276

Re: how to unzip a file in sas?

Hi ,

Generally I do use bellow method to read data in zip format.

FILENAME ZIPFILE SASZIPAM 'C:\Users\sanjeev\Desktop\t.zip';

DATA mydata;

  INFILE ZIPFILE(t.txt) DLM=',' FIRSTOBS=2;

  INPUT var1 $ var2 $ var3 $ var4;

RUN;

You can apply the same for your scenario.

Thanks,

Sanjeev.K

Respected Advisor
Posts: 3,831

Re: how to unzip a file in sas?

I had mixed experiences with SASZIPAM in the past. New with SAS 9.4 is a zip engine available (filename myfile zip ....).

I've done some "Googling" as I didn't know what the file extension .Z stands for and found the following File Extension Z « Avanquest

It appears that GZIP is eventually able to deal with it. Ideally the person who created the .Z file tells you what tool they've used and you're using the same to un-compress the data sets.

The exact syntax you need to use - eg. for GZIP - is something you need to look up, but the general principle is as described under the link posted (http://www2.sas.com/proceedings/sugi31/155-31.pdf)

.

Trusted Advisor
Posts: 1,496

Re: how to unzip a file in sas?

Solution
2 weeks ago
Super User
Super User
Posts: 6,330

Re: how to unzip a file in sas?

[ Edited ]

.Z is the extension used by the compress command, not ZIP or GZIP.

Use the uncompress command to expand the file and then SAS will be able to read it.

 

Editor's note: included some additional details from SAS support doc:

Here's a SAS Note with an example (which assumes the data was compressed via SAS and the compress command). It relies on FILENAME PIPE, which will require privileges to run shell commands (XCMD):

 

Creating the compressed data set: http://support.sas.com/kb/25/199.html

Reading the compressed data set: http://support.sas.com/kb/25/214.html

 

Occasional Contributor
Posts: 12

Re: how to unzip a file in sas?

thanks all

Respected Advisor
Posts: 3,831

Re: how to unzip a file in sas?

If this is resolved for you then could you please mark this question as answered?

New Contributor CCW
New Contributor
Posts: 2

Re: how to unzip a file in sas?

I searched for the method for our purpose and the best answer I got for a dumb programer like me is from a SAS paper, Paper 057-2012
A SAS® Macro to Zip and Unzip Files in MS Windows without Additional External Data Archiving Software, Kai Koo, Abbott Laboratories, Santa Clara, CA

The paper is attached if you don't want to search it online.

 

I can skip the concept of this method and just use its macro program. It becomes extremely easy and useful. Hope you like it.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 13546 views
  • 3 likes
  • 6 in conversation