BookmarkSubscribeRSS Feed
bhca60
Quartz | Level 8
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? I am
Trying to save space which is why I need it to stay zipped unless there are other solutions.
9 REPLIES 9
yabwon
Onyx | Level 15

Yes, you need to unzip the file.

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



bhca60
Quartz | Level 8

 

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?

 

andreas_lds
Jade | Level 19

Could you share the complete log of the code?

Have you verified that file1.sas7bdat exists in the directory used in the libname statement?

 

yabwon
Onyx | Level 15
gunzip <file.gz>
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Tom
Super User Tom
Super User

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;
Reeza
Super User
*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;
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Sajid01
Meteorite | Level 14

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1783 views
  • 2 likes
  • 6 in conversation