02-03-2015 10:18 AM
Can I access the contents of this file (a .csv) :
for example, with the ZIP engine directly, without downloading it first?
I'm using SAS 9.4 on Windows 7.
02-04-2015 02:52 PM
02-03-2015 08:02 PM
The contents of the file (referenced by the URL) is a zip-archive container, with a "CSV" file inside, which must be processed after retrieving from the foreign/remote site. Explore SAS 9.4 with the FILENAME ZIP engine, possibly, after retrieving the container file, using SAS FILENAME, PROC DOWNLOAD, possibly.
02-04-2015 02:08 PM
Recommend native SAS function/facility here with FILENAME / FTP engine to retrieve the file, followed by SAS ODS PACKAGE to extract from the zip-archive.
02-03-2015 08:22 PM
You can do it with a pipe (which will be system dependent). The following would be an example for linux.
filename x pipe 'wget -qO- http://donnees.ville.montreal.qc.ca/storage/f/2013-10-05T17%3A49%3A08.194Z/l2p-801-15052013-leplatea... | funzip';
02-03-2015 09:49 PM
Thank you both.
I was naively hoping to wrap the URL into a Windows UNC, somehow, and use that as the 'external-file' physical name in the FILENAME statement. That way I could access the contents of the zip archive directly. Just a dream...
02-03-2015 11:06 PM
In windows you could try something like the following:
filename x pipe 'cmd /C "pushd \\myshare\folder\unc && C:\PROGRA~1\7-Zip\7z.exe x -so foo.zip 2> _garbage.txt && del _garbage.txt && popd"';
02-04-2015 01:30 PM
Thank you Matt,
I cannot use your suggestion unless I understand what it does. Would you please explain the OS commands feeding that pipe? Can foo.zip be a URL?
02-04-2015 01:56 PM
You said you are wanting to use UNC path, not URL, very different.
- starts a new instance of the command interpreter and carries out the following command string and stops
- assigns a UNC path a temporary drive letter and changes directory to this location
C:\PROGRA~1\7-Zip\7z.exe x -so foo.zip 2> _garbage.txt
- 7-zip is a open source file archiver that has the ability to output the contents of a ZIP archive to STDOUT
x - denotes to eXtract from the archive
-so - write contents of archive to STDOUT
foo.zip - is the name of the file contained in the UNC path assigned with PUSHD
2> _garbage.txt - this redirects the other messages produced by 7z.exe to a junk file, redirecting to NUL doesn't work, for some reason
- Delete the file we had to create with 7z.exe to get the STDOUT write to work
- Removes the temporary drive-letter assignment created with pushd and returns to the original working directory
The double ampersand (&&) command separator strings all these commands together, with error checking (only running one after the previous runs without error
If you are wanting to use a proper URL in Windows it would be a different set of commands and different tools.
02-04-2015 02:03 PM
If you want to use URL then:
Get Wget for Windows
Get bsdtar for Windows with LibArchive for Windows
filename x pipe 'wget -qO- http://donnees.ville.montreal.qc.ca/storage/f/2013-10-05T17%3A49%3A08.194Z/l2p-801-15052013-leplatea... | bsdtar -xvf-';
wget downloads the zipfile
-q sets the wget command to be quiet
-O- sets the output to be directed to STDOUT
bsdtar reads the zip file from the pipe and extracts the contents, again to STDOUT
-v tells bsdtar to operate verbosely
-f- indicates to operate on the file coming from STDIN
02-04-2015 02:52 PM
02-04-2015 01:26 AM
This could not possibly be done in one step .
firstly proc http + TEMP engine download this ZIP file ,then use filename's ZIP engine.
Need further help from the community? Please ask a new question.