SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Unable to read .sas7bdat.gz file from Unix in SAS EG 7.1

Reply
New Contributor
Posts: 2

Unable to read .sas7bdat.gz file from Unix in SAS EG 7.1

Hello all,

 

I am new to the community so may not be very clear. I have a sas data file that is zipped in unix environment like data.sas7bdat.gz, which is a huge file. I want to directly read this file into SAS EG as a dataset. I researched online and tried using PIPE and ZIP in FILENAME, but both don't work. PIPE would show all special characters for these fields. ZIP shown ERROR. Can you guys help me with this?

 

FILENAME in PIPE "gunzip -c /unixserver/data.sas7bdat.gz" LRECL=80 ;

DATA test;

INFILE in obs=20;

INPUT a 8 b $ 1-46 c $ 6;

RUN;

 

 

 

 

Super User
Posts: 8,302

Re: Unable to read .sas7bdat.gz file from Unix in SAS EG 7.1

First run this:

filename oscmd pipe 'cd directory; gzip -d data.sas7bdat.gz 2>&1';

data _null_;
infile oscmd;
input;
put _infile_;
run;

Replace "directory" withe the location of the gzipped file.

Then do

libname datalib 'directory';

and you should be able to access dataset datalib.data.

If the unzip step fails, you'll see it in the SAS log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 2

Re: Unable to read .sas7bdat.gz file from Unix in SAS EG 7.1

I think I did not make my question clearly. I want to read the .sas7bdat.gz file into SAS EG without unzipping it. Thank you.

Super User
Posts: 8,302

Re: Unable to read .sas7bdat.gz file from Unix in SAS EG 7.1


qhty wrote:

I think I did not make my question clearly. I want to read the .sas7bdat.gz file into SAS EG without unzipping it. Thank you.


Is not possible. The file needs to exist as a .sas7bdat before SAS can access it. What you want to do would only be possible for external sequential files.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 20,688

Re: Unable to read .sas7bdat.gz file from Unix in SAS EG 7.1

Are you using SAS 9.4TS1M5? If so, that finally added support for GZ, but I'm not sure that will work with a SAS data set either. 

 

Another option is to compress the file using SAS compress option rather than gz. 

Super User
Super User
Posts: 7,252

Re: Unable to read .sas7bdat.gz file from Unix in SAS EG 7.1

[ Edited ]

SAS datasets are a binary file format. You cannot expect to read them using an INFILE statement as if they were just a simple text file.

You need to first uncompress the file and then SAS will recognize it as a SAS dataset.  

Here is a way you could uncompress it into the WORK library.  Make sure the create a filename that is all lowercase letters.

 

data _null_;
  infile "gunzip -c /unixserver/data.sas7bdat.gz >%sysfunc(pathname(work))/test.sas7bdat" pipe ;
  input;
  put _infile_;
run;

You can then just use it directly like any other work dataset.

proc contents data=test;
run;
Ask a Question
Discussion stats
  • 5 replies
  • 112 views
  • 0 likes
  • 4 in conversation