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

How to read how to read dat.z file and .sas7bdat.z file without unzipping it

 

/folder1/haauto.prm.oct1995.dat.Z

/folder2/avr1991.sas7bdat.Z

 

Please provide SAS code example.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The -c option directs the uncompress to send the result to stdout instead of a file, that's how my INFILE PIPE works.

You also use the same option to create the file elsewhere:

uncompress -c /folder1/source.Z > /folder2/target

The original file will stay as it is.

View solution in original post

11 REPLIES 11
SASKiwi
PROC Star

You can find the answer yourself by going to the SAS doc: https://documentation.sas.com./doc/en/helpcenterwlcm/1.0/home.htm

 

Then search using the key word ZIP and you will find this: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsglobal/n1dn0f61yfyzton1l2ngsa1clllr.ht...

 

There is example code in the above link.

 

Tom
Super User Tom
Super User

You cannot.

You will need to uncompress both of those files before SAS will be able to read them.

 

If you have permission to run operating system commands (and you are running SAS on Unix) you could use a PIPE to read the .dat file.

data want;
  infile 'uncompress -c /folder1/haauto.prm.oct1995.dat.Z' pipe;
  input .....

But for the SAS dataset you will have to store the uncompressed file somewhere for SAS to be able to read it.

 

 

alepage
Barite | Level 11

Hello,

 

our operating system is Unix and I am interested by a pipe command to read the file directly.

Could you please provide an example.

 

I the same line of though, it is possible to retreive a line into a dataset without unzipping it?

 

Kurt_Bremser
Super User

The .Z extension points to the use of the UNIX compress utility, which uses a different algorithm than the ZIP and gzip methods built into SAS. Therefore you have to use the external command for both files. The .dat.Z file can be read into SAS through a PIPE (if it is text), but the .sas7bdat.Z has to be uncompressed in place before SAS can use it as a dataset.

alepage
Barite | Level 11

Hello Kurt,

I have use the uncompress unix command directly to the terminal to see how the file react.

 

uncompress /folder1/aou1991.sas7bdat.z
un compress /folder1/belair.ontprime.sep92.dat.z

 

after I am obtaining the two files below

 

/folder1/aou1991.sas7bdat

/folder1/belair.ontprime.sep92.dat

 

The first one is a SAS dataset, the second one look like a standard text file.

 

In reality, the source of those two files are in folder2 (production environment) where I am not authorize to manipulate the files.

So I moving these file from folder2 to p drive (windows env) then move from p to folder1 (unix env, but where I can do what I want)

 

So I wonder if there is a way to uncompress a file from its source to a specific destination or in the work library ?

Kurt_Bremser
Super User

The -c option directs the uncompress to send the result to stdout instead of a file, that's how my INFILE PIPE works.

You also use the same option to create the file elsewhere:

uncompress -c /folder1/source.Z > /folder2/target

The original file will stay as it is.

alepage
Barite | Level 11

This unix command works:

 

uncompress -c /folder1/aou2000.sas7bdat.Z > /folder2/aou2000.sas7bdat

 

I am surprise that we don't see the above example into the documentation:

https://www.computerhope.com/unix/uuncompr.htm

 

It is possible to send the uncompress file into the work library and if it is possible , how ?

 

 

 

 

Tom
Super User Tom
Super User

If you only need to uncompressed files during your SAS session just write them into the WORK directory.

%let work=%sysfunc(pathname(work));
data _null_;
  infile 
"cd &work
;uncompress -c /folder1/haauto.prm.oct1995.dat.Z  haauto.prm.oct1995.dat
;uncompress -c /folder2/avr1991.sas7bdat.Z  avr1991.sas7bdat
" pipe;
  input;
  put _infile_;
run;

You can then use the DAT file from the &WORK directory and see the SAS dataset in the WORK library.

alepage
Barite | Level 11

Both version below are working:

 

%let work=%sysfunc(pathname(work));

filename oscmd pipe "uncompress -c /folder1/aou2000.sas7bdat.Z > &work./aou2000.sas7bdat 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

%let work=%sysfunc(pathname(work));

filename oscmd pipe "cd &work. ; uncompress -c /folder1/aou2000.sas7bdat.Z > aou2000.sas7bdat 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 11 replies
  • 2260 views
  • 0 likes
  • 4 in conversation