BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shasank
Quartz | Level 8

Hi Community, 

 

I need your help with the above mentioned task. I have surfed the internet to find answers for this and was not much of a help. 

 

Please advise. 

data _null_ ;
 unzipcmd='"C:\Program Files\WinZip\Winzip64.exe" -min -e -o -s' ;
 pw='"qwerty"' ;
 zipfile="O:\Data\20220205.zip" ;
 whereto='C:\' ;
cmd=unzipcmd || pw || ' ' || zipfile || ' ' || whereto  ;
putlog "NOTE-Processing command " cmd ;
 call system( cmd ) ;
run ; 
options noxwait;
%LET PASS =qwerty; x unzip -o -P &PASS. "O:\Data\20220205.zip" -d "O:\Data";

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

It may well be that you use a server-based SAS (through SAS Studio or Enterprise Guide) where the server does not yet have unzip installed.

Check with your SAS admins

  • where SAS is installed (local or remote)
  • which operating system (if remote)
  • which zip/unzip program to use
  • which path to use (if remote)

View solution in original post

8 REPLIES 8
shasank
Quartz | Level 8
20220205.zip is a password protected zip file that has around 15 SAS datasets. I am trying to extract the SAS datasets and automate the process.
Tom
Super User Tom
Super User
  • Figure out the command that works from the DOS/CMD window prompt.
  • Make sure it runs on the machine where SAS is running when logged in as the user that is running the SAS code. For example if you are using SAS/Studio or Enterprise Guide to submit your SAS code then it might be running on a different machine than the one you are using to run your front end tool.  That machine might not even be running Windows, or have the WinZip.exe command on it, or even have access to the O drive where your file is.
  • Try running a static version of the code.

 

Once you have code that works Then figure out how to create it with SAS code.

 

I recommend NOT using the X command.  Instead just use the PIPE engine to run the command you have generated.

shasank
Quartz | Level 8
Thank you for your reply @Tom. Is there is way to perform this using a regular Filename statements??
Kurt_Bremser
Super User

Running an external command via pipe goes like this:

filename oscmd pipe "unzip -o -P &PASS. O:\Data\20220205.zip -d O:\Data 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

Since you do not have blanks in your path names, quotes are not needed there.

The "2>&1" reroutes stderr to stdout, so SAS can catch all eventual messages that come back from the external command.

Inspect the SAS log to see what happened.

shasank
Quartz | Level 8
@Kurt_Bremser. Thank you so much for your time!!!!. I have tried the above code and got a message that
*
'unzip' is not recognized as an internal or external command,
operable program or batch file.
*
Do I have to install anything before I run this.
Kurt_Bremser
Super User

It may well be that you use a server-based SAS (through SAS Studio or Enterprise Guide) where the server does not yet have unzip installed.

Check with your SAS admins

  • where SAS is installed (local or remote)
  • which operating system (if remote)
  • which zip/unzip program to use
  • which path to use (if remote)
shasank
Quartz | Level 8
Hi Kurt_Bremser,
Thank you!! I have cross checked and I am using SAS 9.4 installed on a windows machine. It is installed locally. I keep getting an error that UNZIP is not a built-in windows function. I will try to find if there is a similar function for windows.
Tom
Super User Tom
Super User

@shasank wrote:
Hi Kurt_Bremser,
Thank you!! I have cross checked and I am using SAS 9.4 installed on a windows machine. It is installed locally. I keep getting an error that UNZIP is not a built-in windows function. I will try to find if there is a similar function for windows.

So you appear stuck on the first step.  What DOS/Windows command can you run to unzip a file on machine.

Try using Google to see if there is something available to you.  If you have local system support ask them for help also.

 

https://www.google.com/search?q=unzipping+password+protected+zip+file+on+windows

 

Looks like a lot of users are using 7-Zip which does have a command line option you can get.

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
  • 8 replies
  • 3012 views
  • 0 likes
  • 3 in conversation