BookmarkSubscribeRSS Feed
texasmfp
Lapis Lazuli | Level 10

I'd like to automate the downloading and unzipping of a zipped file from the web.  I read Chris Hemedinger's blog post and can successfully download the file.  However, it resides in the SAS Temporary folder.  I need to unzip all files to a specific directory, such as W:\Data\2024-07.  Does SAS have a function to extract everything in a zipped file?  Note that I am not trying to use any of the extracted files, simply extracting all files to a library folder.  Thanks

 

/* detect proper delim for UNIX vs. Windows */
%let delim=%sysfunc(ifc(%eval(&sysscp. = WIN),\,/));

/* create a name for our downloaded ZIP */
%let ziploc =
	%sysfunc(getoption(work))&delim.datafile.zip;
filename download "&ziploc";

/* Download the ZIP file from the Internet*/
proc http
	method='GET'
	url="https://www.census.gov/trade/downloads/2024/Textile_summary_m/TEXSUMM2401.ZIP"
	out=download;
run;

/* Assign a fileref wth the ZIP method */
filename inzip zip "&ziploc";

/* Read the "members" (files) from the ZIP file */
data contents(keep=memname);
	length memname $200;
	fid=dopen("inzip");

	if fid=0 then
		stop;
	memcount=dnum(fid);

	do i=1 to memcount;
		memname=dread(fid,i);
		output;
	end;

	rc=dclose(fid);
run;

 

2 REPLIES 2
rudfaden
Lapis Lazuli | Level 10

I do not think SAS can unzip files directly. But you can run a x command to make the terminal unzip files and move them to another folder.

Tom
Super User Tom
Super User

All you did so far was find the list of files inside the ZIP file.  Now use that list to generate the code to copy out the files.

 

There are a lot of examples out there:  https://www.google.com/search?q=%40sas.com+unzip+macro

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1046 views
  • 1 like
  • 3 in conversation