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 ;
INFILE in obs=20;
INPUT a 8 b $ 1-46 c $ 6;
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.
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.
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.
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.
Thursday - last edited Thursday
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;