DATA Step, Macro, Functions and more

Problem reading gz zipped file

Frequent Contributor
Posts: 99

Problem reading gz zipped file

Hi everyone,
I have a file "test.txt.gz". I want to create a SAS dataset. I am using SAS 9.2 for Linux and Unix.

1> How do I unzip the file.
2> Find out what variables are in the file and the delimiter
3> Create SAS dataset.


Super Contributor
Super Contributor
Posts: 3,174

Re: Problem reading gz zipped file

I would expect you have some information about the zip contents, to be provided by the individual sending the information.

Have you searched the Internet using the file extension "gz" and some other related keywords? That approach may provide some revealing information.

Once you get the file unzipped, you can code a simple SAS DATA step to interrogate the first few rows, as shown below:

filename indata '<_your_input_data_file_named_here_';
data _null_;
infile indata;
if _n_ = 10 then stop;

From there, you have some options for importing the data, depending on the file-layout and field-delimiter structure. Suggest you look at SAS PROC IMPORT and also the SAS DATA step approach (more control, but requires more coding). The SAS Support website has SAS-hosted Documentation and also supplemental technical / conference papers on this type of topic for your reference.

Scott Barry
SBBWorks, Inc.
Posts: 0

Re: Problem reading gz zipped file

If you are on a Unix/Linux system, gz files can be read in using a 'pipe' type of filename statement. Using a pipe you can use the file directly and do not have to unzip the file on disk to use it. This technique also works with .zip files.

Sample for reading in a :

filename filein pipe "gunzip -c ~/some_dirname/some_filename.csv.gz" ;

data mydata ;

infile filein DSD ;

input field1
field2 $
field3 $
fieldn ;
run ;
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation