Hi,
I have a PKZIP file(attached) which I manually unzip and read a particular file into SAS. I'm wondering if there a work around in SAS to unzip the file via data step and read the contents. In this case, I want to read dec12.cpt.
PS: I'm using PC SAS on windows to run the above process.
Thanks in advance for your help!
You can use a VB script to have it done.
Here is the code.
Fname = ("C:\Users\Desktop\manual\2CBM00176.zip") /* your zip file folder*/
DirName = ("C:\Users\Desktop\manual") /* your targer folder*/
Dim oApp As Object
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(DirName).CopyHere oApp.Namespace(Fname).items
Set oApp = Nothing
save it as .vbs file and call it from sas
data _null_;
x "C:\Users\O568484\Desktop\manual_Marketing\test.vbs";
run;
filename test "C:\Users\Desktop\manual\dec12.cpt";
%include test;
I hope this will help
Devnand - Thanks for your reply. I followed your instructions but I am getting error message which is as follows.
Line : 3
Char: 14
Error: expected end of statement
code: 800A0401
Source: Microsoft VBscript compliation error
My VB script
Fname = ("C:\ARM\ARMfile.zip")
DirName = ("C:\TEMP")
Dim oApp As Object
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(DirName).CopyHere oApp.Namespace(Fname).items
Set oApp = Nothing
It is a popular practice for SAS users to use PIPE for this kind of task, http://www2.sas.com/proceedings/sugi31/155-31.pdf
While this paper does not specifically spell out how to do it using PKZIP, but it should be easy enough to find it out the right command by typing pkunzip or pkunzip /? or look it up online.
Something along the line of the following may work for you:
filename pkzip pipe 'pkunzip.exe c:\test.zip -c' ;
data want ;
infile pkzip ;
input var & $200. ;
run ;
Haikuo
Hai.Kuo,
I tried your approach before posting the question in this forum and i got the below error
Stderr output:
'pkunzip.exe' is not recognized as an internal or external command,
operable program or batch file.
I tried my best to search online but couldn't find the right pipe command for pkunzip. i even tried the below but getting same error
filename pkzip pipe 'PKUNZIP C:\ARM\ARMfile.zip C:\TEMP -c';
Thanks!
Please remove as object from line 3 of the code.
different error this time:
Line : 5
Char: 5
Error: The system cannot find the file specified
code: 80070002
Source: (null)
Fname = ("C:\Users\\Desktop\New\2CBM00176.zip")
DirName =("C:\Users\\Desktop\New\")
Dim oApp
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(DirName).CopyHere oApp.Namespace(Fname).items
Set oApp = Nothing
Please make sure that your code exactly looks like the same. I see backslash missing in the 2nd line of your code.
I hope this will help
For some reason I'm getting the same error again.Below is my code. Can you do a quick check on my code to make sure i am not missing anything?
Fname = ("C:\TEMP\zipcode_Apr13.zip")
DirName = ("C:\TEMP\")
Dim oApp
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(DirName).CopyHere oApp.Namespace(Fname).items
Set oApp = Nothing
I see double backslash in your code in Fname and Dirname? Is that something i should also have in my code?
The pipe commands are specific to PKZIP and assume that it is installed on your machine (as opposed to WinZIp which requires a command line add on and different syntax).
Here is some more reference for the VB script (which assumes you are trying to use the built in windows compression). I seem to remember there are compression algortihms that windows can not uncompress so if the files were not compressed use the default options that may cause trouble.
http://support.sas.com/resources/papers/proceedings12/057-2012.pdf
Hope that helps.
EJ
Thanks for the insight!
In your first post, you mentioned that you manually unzip the file. Which program you were using to do that? If it is not pkunzip, then PIPE whatever program available on your machine.
Haikuo
Hai.kuo- I would just right click on the zip file and do extract to manually unzip the file.
SAS ADMIRER:
I am not sure what you are doing wrong. I copied the above code and execute it and it ran like a champ.
Sorry it did not help you.
Devnand- There must be something wrong in my system. Thanks for all your help though!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.