Desktop productivity for business analysts and programmers

SAS UNZIP command

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 341
Accepted Solution

SAS UNZIP command

Hello friends - please help me on how i can unzip files using sas 9.1 on win 2003 server? below code is not working so far, 

 

data _null_;
x unzip "d:\test\*.zip" "d:\test\";
run;


Accepted Solutions
Solution
‎11-15-2015 01:42 PM
Super User
Posts: 5,371

Re: SAS UNZIP command

I agree with Patrick ... NOXWAIT is required, and may be all that is missing at this point.  If the results are still not successful, I would try breaking the steps into pieces as follows:

 

options noxwait;

x 'cd d:\test';

x 'dir';

x 'unzip *.zip';

 

The DIR command isn't really necessary once things are working properly, but it may help diagnose what is happening.  I'm hoping this works, because after this I'm out of ideas.

View solution in original post


All Replies
Super User
Super User
Posts: 6,850

Re: SAS UNZIP command

Do you actually have an unzip command installed on your server?

Most unzip commands I have seen can only operate on one zip file at a time so you could not use a wildcard in the name of the zip file.

If you do not know the name of your ZIP file then perhaps you want to first use the DIR command to find the name.

 

Wrapping the X command with a null data step does nothing for either of them.  Try using the PIPE engine on an INFILE statement instead. That way your data step can read any messages that the command generates.

 

data _null_;
   infile "unzip d:\myarchive.zip" pipe ;
   input ;
   put _infile_;
run;
Super Contributor
Super Contributor
Posts: 341

Re: SAS UNZIP command

so can we use wildcard with this?  and we will also need to provide destination directory too, right? i tried below code but its not unzipping files - thanks 

 

 

data _null_;
   infile "unzip d:\test\*.zip d:\test\" pipe ;
   input ;
   put _infile_;
run;

 

Super User
Super User
Posts: 6,850

Re: SAS UNZIP command


woo wrote:

so can we use wildcard with this?  and we will also need to provide destination directory too, right? i tried below code but its not unzipping files - thanks 

 

data _null_;
   infile "unzip d:\test\*.zip d:\test\" pipe ;
   input ;
   put _infile_;
run;

 


You need to tell use what SAS wrote in the log when you ran that command?  Did you get an error that the PIPE engine is not allowed? Did you get an error message from DOS/Windows that the UNZIP command was not found?  Did you get an error message from the UNZIP command?

Super User
Posts: 5,371

Re: SAS UNZIP command

Getting the quotes right with an X command can be tricky.  Try switching to %SYSEXEC, which doesn't need as many quotes:

 

%sysexec unzip "d:\test\*.zip" "d:\test\";

Super Contributor
Super Contributor
Posts: 341

Re: SAS UNZIP command

sorry but it didn't work somehow, 

 

%sysexec unzip "d:\test\*.zip" "d:\test\";

Super User
Posts: 5,371

Re: SAS UNZIP command

Have you tried the simple version?  This is the sort of command I would expect to work.

 

Directly:

 

unzip d:\test\*.zip

 

From SAS:

 

%sysexec unzip d:\test\*.zip;

 

Which command works directly from the operating system when you are not trying to add SAS to the mix?

Respected Advisor
Posts: 4,137

Re: SAS UNZIP command

Can you remote desktop onto your server? It's normally easiest to get the zip command right out of a dos prompt and only then incorporate it into SAS.

Super User
Super User
Posts: 7,725

Re: SAS UNZIP command

Hi,

 

What is the purpose - i.e. are you trying to create some sort of automation?  Describe the scenario, will this be a once off, routine, what happens to existing files, how do you want to handle exceptions etc.  If its a once off then there is no point coding it.  If it is a routine automation, then speak to your IT group who will likely have some sort of ftp + unpack script and should be able to help with setting it up.  

Super Contributor
Super Contributor
Posts: 341

Re: SAS UNZIP command

[ Edited ]

yes i can remote server from my local machine, that is how i am accessing server...Also this will be daily script, 

 

 

Super Contributor
Super Contributor
Posts: 341

Re: SAS UNZIP command

@Astounding

 

This is not working from SAS

 

%sysexec unzip d:\test\*.zip;

Super User
Posts: 5,371

Re: SAS UNZIP command

OK, so what works from a DOS prompt?

 

 

Find a working DOS command, then we can make it executable from a SAS program.

Super Contributor
Super Contributor
Posts: 341

Re: SAS UNZIP command

i tried running below command from cmd prompt and its unzipping files, 

 

command exactly looks like this

 

d:\test>unzip *.zip

 

 

Super User
Posts: 5,371

Re: SAS UNZIP command

Assuming that you re-zip a file or two in that folder, what happens when you try either of these:

 

x 'unzip d:\test\*.zip';

 

%sysexec unzip d:\test\*.zip;

 

Do you get an error message?  Does nothing happen?

Super Contributor
Super Contributor
Posts: 341

Re: SAS UNZIP command

 

 

I ran both command one by one and for both command line its prompting 2 windows, "The SAS system x command window is active" window and "cmd command prompt" windows. sas system x command window saying - the X command is active. Enter EXIT at the promt in the X command window to reactivate this SAS session. 

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 18 replies
  • 1368 views
  • 1 like
  • 5 in conversation