Yes, you need to unzip the file.
As an option you can consider using those two macros from the BasePlus package:
1) https://github.com/SASPAC/baseplus/blob/main/baseplus.md#ziplibrary-macro
2) https://github.com/SASPAC/baseplus/blob/main/baseplus.md#unziplibrary-macro
The first can sip the library content for you (each separate file as a separate zip)
The second allows you to unzip the content.
Bart
x "gzip /abc/123/gdr/file1.sas7bdat";
libname get "/abc/carib/process/data";
data test;
set get.file1;
run;
file1.sas7bdat.gz is now the name of the file but when doing this test run, I am getting ERROR: FILE1 does not exist.
Is there something I have to do to get this to be read as if it were an unzipped file?
Could you share the complete log of the code?
Have you verified that file1.sas7bdat exists in the directory used in the libname statement?
gunzip <file.gz>
SAS will not read a .gz file as if it was a .sas7bdat file. You will first have to uncompress it.
You could expand it into the WORK directory and use it from there.
So let's assume you have a file named /abc/123/gdr/file1.sas7bdat.gz. You could do something like this:
%let gzipfile=/abc/123/gdr/file1.sas7bdat.gz;
%let dsname=%sysfunc(lowcase(%scan(&gzipfile,-3,/.)));
data _null_;
infile "gzip -o -d &gzipfile > %sysfunc(pathname(work))/&dsname..sas7bdat" pipe;
input;
put _infile_;
run;
proc contents data=&dsname;
run;
*unzip gzip file using SAS commands, requires 9.4M5+;
filename target "/abc/carib/process/data/file1.sas7bdat" ;
filename fromzip ZIP "/abc/123/gdr/file1.sas7bdat.gz" GZIP;
data _null_;
infile fromzip;
file target ;
input;
put _infile_ ;
run;
libname get "/abc/carib/process/data/";
data test;
set get.file1;
run;
I would go with "binary" copying:
filename target "/abc/carib/process/data/file1.sas7bdat" lrecl=1 recfm=n;
filename fromzip ZIP "/abc/123/gdr/file1.sas7bdat.gz" GZIP lrecl=1 recfm=n;
data _null_;
rc = fcopy('fromzip','target');
run;
Bart
Hello @bhca60
1.When you compressed the file using the command (x "gzip /abc/123/gdr/file1.sas7bdat";). a new file file1.sas7bdat.gz would be created at the location /abc/123/gdr and the orignal dataset file.sas7bdat would be deleted.
2. Subsequently you are creating the libref get (libname get "/abc/carib/process/data";). This location does not contain the dataset fi1e1.sas7bdat.
This is the reason you see the error message (ERROR: FILE1 does not exist.)
3. The file needs to be copied to the location pointed by your libref. You can use the code by @Reeza OR @yabwon to perform this action..
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.