BookmarkSubscribeRSS Feed
AmitKB
Fluorite | Level 6
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.

Thanks,

Amit
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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;
input;
list;
if _n_ = 10 then stop;
run;

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 http://support.sas.com/ website has SAS-hosted Documentation and also supplemental technical / conference papers on this type of topic for your reference.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
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 ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 1821 views
  • 0 likes
  • 3 in conversation