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.
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') ;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.