BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

18 REPLIES 18
Tom
Super User Tom
Super User

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;
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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;

 

Tom
Super User Tom
Super User

@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?

Astounding
PROC Star

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\";

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

sorry but it didn't work somehow, 

 

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

Astounding
PROC Star

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?

Patrick
Opal | Level 21

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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

 

 

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

@Astounding

 

This is not working from SAS

 

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

Astounding
PROC Star

OK, so what works from a DOS prompt?

 

 

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

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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

 

command exactly looks like this

 

d:\test>unzip *.zip

 

 

Astounding
PROC Star

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?

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

 

 

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. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 18 replies
  • 16122 views
  • 1 like
  • 5 in conversation