BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
supersasnewbie
Calcite | Level 5

Hello,

I received a request to review some reporting that my predecessor left behind years ago, and I'm not familiar at all with how to manage this. Within the "datamart" library, there is an item named "filename.sas7bdat.gz". To my understanding, this is a gzipped file which would contain some of the information that I need to view in order to (hopefully) retrace the steps used to build this report. My predecessor also left some code, as follows, which I've run but does not actually open any tables, or seem to do anything at all. Help!

 

/*Unzip SAS7BDAT File*/
x "gunzip &datamart/filename.sas7bdat";

run;

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

A gz file is a compressed single file, usually on a Unix/Linux system. In this case you have a SAS data set file that has been compressed with gzip.

 

gunzip is a tool that can uncompress  it. You can also accomplish this directly in SAS code with the FILENAME ZIP method and GZIP option. See this article for background and examples.

 

Example:

/* The expands the GZ data to a WORK data set */
filename zipdata ZIP "&datamart/filename.sas7bdat.gz" GZIP;
filename unzip "%sysfunc(getoption(WORK))/filename.sas7bdat";
 
data _null_;
   infile zipdata
       lrecl=256 recfm=F length=length eof=eof unbuf;
   file unzip lrecl=256 recfm=N;
   input;
   put _infile_ $varying256. length;
   return;
 eof:
   stop;
run;
 
proc print data=work.filename(obs=5);
run;

 

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

View solution in original post

4 REPLIES 4
ChrisHemedinger
Community Manager

A gz file is a compressed single file, usually on a Unix/Linux system. In this case you have a SAS data set file that has been compressed with gzip.

 

gunzip is a tool that can uncompress  it. You can also accomplish this directly in SAS code with the FILENAME ZIP method and GZIP option. See this article for background and examples.

 

Example:

/* The expands the GZ data to a WORK data set */
filename zipdata ZIP "&datamart/filename.sas7bdat.gz" GZIP;
filename unzip "%sysfunc(getoption(WORK))/filename.sas7bdat";
 
data _null_;
   infile zipdata
       lrecl=256 recfm=F length=length eof=eof unbuf;
   file unzip lrecl=256 recfm=N;
   input;
   put _infile_ $varying256. length;
   return;
 eof:
   stop;
run;
 
proc print data=work.filename(obs=5);
run;

 

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
supersasnewbie
Calcite | Level 5

Thanks for the response. Here's what I did, where "Import" is my library that corresponds to "drivename". However, at the proc print step, I am getting the error message 'IMPORT.filename.data is shorter than expected use PROC DATASETS; REPAIR to fix it. What should I do to fix this?

 

filename zipdata ZIP "drivename/filename.sas7bdat.gz" GZIP;
filename unzip "drivename/filename.sas7bdat";
 
data _null_;
   infile zipdata
       lrecl=256 recfm=F length=length eof=eof unbuf;
   file unzip lrecl=256 recfm=N;
   input;
   put _infile_ $varying256. length;
   return;
 eof:
   stop;
run;
 
proc print data=import.filename(obs=5);
run;

 

Tom
Super User Tom
Super User

Try actually using gunzip to expand the file and see if that works.  If it does not work then the original gz file is corrupted.

 

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @supersasnewbie 

 

As it says, use Proc datasets with Repair:

 

libname mylib "c:\testdata";

proc datasets lib=mylib;
   repair myfile;
run;
quit;

In most cases, running a Proc Content on the library will also do the trick, but Proc Datasets is the secure way.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2642 views
  • 0 likes
  • 4 in conversation