BookmarkSubscribeRSS Feed
vicky07
Quartz | Level 8

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!

14 REPLIES 14
devnand
Obsidian | Level 7

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

vicky07
Quartz | Level 8

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

Haikuo
Onyx | Level 15

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

vicky07
Quartz | Level 8

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!

devnand
Obsidian | Level 7

Please remove as object from line 3 of the code.

vicky07
Quartz | Level 8


different error this time:

Line : 5

Char: 5

Error: The system cannot find the file specified

code: 80070002

Source: (null)

devnand
Obsidian | Level 7

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

vicky07
Quartz | Level 8

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?

esjackso
Quartz | Level 8

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

vicky07
Quartz | Level 8

Thanks for the insight!

Haikuo
Onyx | Level 15

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

vicky07
Quartz | Level 8

Hai.kuo- I would just right click on the zip file and do extract to manually unzip the file.

devnand
Obsidian | Level 7

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.

vicky07
Quartz | Level 8

Devnand- There must be something wrong in my system. Thanks for all your help though!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 14 replies
  • 2993 views
  • 8 likes
  • 4 in conversation