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

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 319 views
  • 1 like
  • 3 in conversation