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;
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;
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;
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;
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.
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.