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

I have a zipped file with thousands of text files, and just need readin a few of them. 

 

How to readin text file inside a zipped file without zipping?! Is that possible?

Say the zipped file name is filezipped.zip and the file inside need be readin is file_0001.txt. 

What would be the sample code?!

 

I know how to unzip the file within SAS and readin text file. 

1 ACCEPTED SOLUTION
5 REPLIES 5
Kurt_Bremser
Super User

First, define a file reference for the zip archive, then use this with a member name in the DATA step.

filename zipfile zip "/path_to_file/filezipped.zip";

data want;
infile zip(file_0001.txt) /* other options */;
length ....;
format ....;
input ....;
run;
Tom
Super User Tom
Super User

You can read it using the ZIP fileref engine.

 

Either directly in the INFILE statement.

infile 'filezipped.zip' zip member='file_0001.txt' ;

Or by first creating a FILEREF .

filename file1 zip 'filezipped.zip' member='file_0001.txt' ;

and then using the fileref in the INFILE statement

infile file1 ;

You could also use the fileref in other places where you might have used a physical filename. Such as PROC IMPORT.

proc import file=file1 .....;

 

You could also make a fileref that does not specify which member of the ZIP file to read.

filename zipfile zip 'filezipped.zip' ;

That is the same as pointing a fileref at a directory .

 

In the INFILE statement you can then select which member you want using the normal old fashion SAS syntax:

infile zipfile('file_0001.txt') ;

 

 

ballardw
Super User

How good is the documentation of the  file you want to read? As in do you know the variable type, length and possibly the needed Informat such as for dates, times or currency and matching display Format?

ChrisHemedinger
Community Manager

For reference, we have several examples here: How to work with ZIP files in SAS programs 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 324 views
  • 3 likes
  • 5 in conversation