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.
For reference, see Example 3 of FILENAME Statement: ZIP Access Method
(Maxim 1: Read the Documentation)
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;
For reference, see Example 3 of FILENAME Statement: ZIP Access Method
(Maxim 1: Read the Documentation)
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') ;
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?
For reference, we have several examples here: How to work with ZIP files in SAS programs
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.