SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
PriyaL
Fluorite | Level 6

Hi,

 

I am trying to Unzip some files in a location connected to UNIX.

However there are several to Unzip and I thought it will be easier to code using a macro.

 

But I am not sure how to alter the "x" command or use the following statement in the macro

 

x "gunzip /sas/data/...."

 

Would anyone have any ideas of how to implement this code in the macro.

 

Thanks.

6 REPLIES 6
Reeza
Super User

EG typically doesn't allow for X commands unless you've overridden the default settings. 

 

Whats the parameter for your macro? The filenames? Or will you automatically scan a folder for zip files and unzip them all? 

 

Before writing a macro first get base code working. Then determine your parameters, and then convert. 

Kurt_Bremser
Super User

First of all, gunzip accepts a list of files on the commandline. Therefore you can use wildcard characters to name a group or groups of files.

 

Second, you need to have the XCMD system option enabled at startup; there is an option for that in the metadata of workspace servers. You cannot change this option during SAS runtime.

 

Third, you can run your gunzip command repeatedly from a dataset containing filenames with call system(). No need for a macro, unless you want to automate that (parameterized filename patterns, directories).

rogerjdeangelis
Barite | Level 11
If you have IML Studio then you should have a bridge to R you can then do the following

    library(R.utils);                                                                                                                                                 
    wd<-getwd();                                                                                                                                                      
    setwd("c:\\temp");                                                                                                                                                
    gunzip("class.sas7bdat.gz",remove=FALSE,overwrite=TRUE);                                                                                                          
    setwd(wd);    

Note gunzip removes the gz file and creates c:/temp/class.sas7bdat         
Tom
Super User Tom
Super User

You can call the X command in a macro the same way you would call it outside of a macro.

%macro gunzip(filename);
x "gunzip &filename" ;
%mend gunzip;

But I find it is usually better to use a pipe to run commands since you can then capture any responses the command might make.

%macro gunzip(filename);
data _null_;
  infile "gunzip &filename" pipe;
  input;
  put _infile_;
run;
%mend gunzip;
rogerjdeangelis
Barite | Level 11
Curious if the IML bridge to R works with NOXCMD
Patrick
Opal | Level 21

Have you considered using the Filename ZIP engine? Here how this could work: 

http://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in-...

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 6 replies
  • 4756 views
  • 0 likes
  • 6 in conversation