BookmarkSubscribeRSS Feed
vxhong17
Calcite | Level 5

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,

9 REPLIES 9
Reeza
Super User

Does it work in dos/command line?

vxhong17
Calcite | Level 5

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

Patrick
Opal | Level 21

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.

Tom
Super User Tom
Super User

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.

vxhong17
Calcite | Level 5

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)) ;

Patrick
Opal | Level 21

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  ;

Tom
Super User Tom
Super User

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.

vxhong17
Calcite | Level 5

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,

Tom
Super User Tom
Super User

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.

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!

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.

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
  • 9 replies
  • 3907 views
  • 6 likes
  • 4 in conversation