DATA Step, Macro, Functions and more

Reading SAS Datasets directly from a zip file...

Reply
Frequent Contributor
Posts: 76

Reading SAS Datasets directly from a zip file...

Dear All,

I'm using SAS Enterprise Guide 4.1 and I was wondering if this version can read datasets from a zip file. I have nearly 2000 large size datasets which I would prefer to read without extracting them.

Googled plenty of sites but did not find any direct solution. Experts request you to advise on this.

Thanks, Manthan.

Super User
Posts: 19,849

Re: Reading SAS Datasets directly from a zip file...

AFAIK you need to unzip, read file and then delete in all versions of SAS. You can store them with the compress option but I don't believe that's as efficient as ZIP.

Contributor
Posts: 28

Re: Reading SAS Datasets directly from a zip file...


Manthan,

I believe this article shows what you want:

http://blogs.sas.com/content/sasdummy/2014/01/29/using-filename-zip/

Super User
Posts: 19,849

Re: Reading SAS Datasets directly from a zip file...

The method is in the comments to access a SAS datasets, but does require copying the file out.

Respected Advisor
Posts: 4,173

Re: Reading SAS Datasets directly from a zip file...

In SAS9.4 there is a zip engine for the Libname statement which would give you direct access to a zip archive. Comment added: This was dreaming. There is a zip engine for filename not for libname.

I believe EG4.1 goes with SAS9.1.3 so there you need to first extract the SAS file. What you could do: Extract the file into WORK and then use it from there like any other SAS table in work.

Below sample code uses zip file "c:\temp\ziptest.zip". This archive contains file "class.sas7bdat". The program extracts the file to the SAS Work folder. 7-zip is used for extracting the file. You will need to figure out what's available in your environment and how the exact command syntax needs to look like.

proc sql noprint;

  select path into Smiley Tongueathname

  from dictionary.libnames

  where libname='WORK';

quit;

data _null_;

  rc=system('"C:\Program Files\7-Zip\7z.exe" e "c:\temp\ziptest.zip"  -o"'||strip(symget("pathname"))||'" class.* -r -y');

  if rc ne 0 then put "return code is " rc /"Process not successful";

  stop;

run;

proc print data=work.class;

run;

Super User
Posts: 7,832

Re: Reading SAS Datasets directly from a zip file...

Instead of the proc sql,

%let pathname=%sysfunc(pathname(work));

will also work.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,832

Re: Reading SAS Datasets directly from a zip file...

To directly read a SAS dataset, you need to have it in a library, which in the case of zipped files would mean that the libname statement supports a "zip" engine. Since this is not (yet?) implemented, you can only decompress the files with an external command (from SAS 9.4 you could also use the filename zip access method to unpack the file), read them and delete them afterwards.

On which operating system platform does your SAS workspace server run?

You could post an idea about implementing a zip engine for the libname statement in future SAS releases.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 6 replies
  • 5266 views
  • 0 likes
  • 5 in conversation