use winrar to unzip files!

Reply
Contributor
Posts: 51

use winrar to unzip files!

I used the following command to unzip the file. However, it did not work.

Could you help me out?

X "'c:\Program files\WinRar\Rar.exe' D:\Aging\data\2011\code\SF20111YR_SAS.rar e D:\Aging\data\2011\code";

Thank you so much,

Super User
Posts: 17,963

Re: use winrar to unzip files!

Does it work in dos/command line?

Contributor
Posts: 51

Re: use winrar to unzip files!

Hi Reeza.  i want it work in command line. Thank you!

Respected Advisor
Posts: 3,908

Re: use winrar to unzip files!

For debugging you try to break up things into little chunks. So in your case first make the command work in dos/command line. Once that works use it from within SAS.

In doing so you would realise that 'c:\Program files\WinRar\Rar.exe' already isn't working on a dos command line as Windows requires that you're using double quotes.

Super User
Super User
Posts: 6,502

Re: use winrar to unzip files!

Get the command to work from an actual command line and then paste it into SAS.

If you are going to use the X command and the DOS command contains double quote characters then you should use the QUOTE() function to double them up for you.

%let doscmd="c:\Program files\WinRar\Rar.exe" "D:\Aging\data\2011\code\SF20111YR_SAS.rar" e D:\Aging\data\2011\code  ;

X %sysfunc(quote(&doscmd)) ;

Or just use %SYSEXEC(&doscmd) since that it doesn't require the quotes since it has () around the command.

Contributor
Posts: 51

Re: use winrar to unzip files!

Hi Tom,

Thank you so much for your help,

I downloaded zip files and used your command to unzip files. However, It did not work.

Thank you,

%let httpcode = http://www2.census.gov/acs2011_1yr/summaryfile/UserTools/;

%let zipcode = SF20111YR_SAS.zip ;

filename Downcode url "&httpcode&zipcode";

filename zipcode  "D:\Aging\data\2011\code\&zipcode";

data _null_;

   nbyte=-1;

   infile downcode nbyte=nbyte recfm=s;

   input;

   file zipcode recfm=n;

   put _infile_;

run;

%let doscmd="c:\Program files\WinRar\Rar.exe" "D:\Aging\data\2011\code\SF20111YR_SAS.rar" e D:\Aging\data\2011\code  ;

X %sysfunc(quote(&doscmd)) ;

Respected Advisor
Posts: 3,908

Re: use winrar to unzip files!

I'm still with Reeza and Tom

"Get the command to work from an actual command line..."

For example here:

%let zipcode = SF20111YR_SAS.zip

%let doscmd="c:\Program files\WinRar\Rar.exe" "D:\Aging\data\2011\code\SF20111YR_SAS.rar" e D:\Aging\data\2011\code  ;

Super User
Super User
Posts: 6,502

Re: use winrar to unzip files!

Another trick to use is to use PIPE instead of X or SYSTEM command.  Then you should be able to see in your SAS log all of the messages that the command you are trying to run is sending out.

data _null_;

  infile %sysfunc(quote(&doscmd)) pipe ;

  input;

  put _infile_;

run;

You should try the steps independently to make sure that the download step is not corrupting the zip file.  Did you try using that RAR command on other files? Are you sure it is working at all?  Once you can use RAR to unzip the file from the command prompt WITHOUT using SAS then you are ready to try to get SAS to run the command for you.

Contributor
Posts: 51

Re: use winrar to unzip files!

Hi Patrick, and Reeza,

Thank you so much for your help.

Hi Tom,

I can learn a lot from your response. Your explanation is very comprehensive.

I can use Winzip with all your suggestions to unzip files. I finally decide to use sample code from the following link to unzip files without any unzip applications.

http://support.sas.com/resources/papers/proceedings12/057-2012.pdf

Thank you so much,

Super User
Super User
Posts: 6,502

Re: use winrar to unzip files!

Glad you go it working, but it still looks like you are calling some external ZIP program.  You just switched from calling winzip or rar to calling some visual basic program instead.

Ask a Question
Discussion stats
  • 9 replies
  • 2064 views
  • 6 likes
  • 4 in conversation