BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
arbnmedic33
Calcite | Level 5

Hello all; Thanks in advance for any assistance. Self taught, novice SAS programmer here, working with 'x' commands, running SAS in Linux. My issue is zipping various types of data files using the 'tar' command in a SAS program and placing those files in the correct directory.

In the program, lines 1-51 work fine, no issues. Problem starts at line 57 with the 'x tar...' statements. The files are zipping, but they are being placed in the incorrect location and not the "...EDA_PROCESS_OUTPUT_1X, 2X, 3X, etc..." as the 'tar' command lines direct. Most likely I am incorrect on the syntax for that action.

As a work around, I added a series of 'cp' statements to copy the files to the correct location(s). I get a 'cannot stat' from Linux for each one of those 'cp' commands.

Once again, thanks for any assistance, actual SAS program is attached.

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

This statement:

x tar -czvf "&path2/EDA_PROCESS_OUTPUT_1X.tar.gz" "&path2/EDA_PROCESS_OUTPUT_1X";

I think tells tar to make a file EDA_PROCESS_OUTPUT_1X.tar.gz and put it in the directory &path2. 

 

Are you saying you want a file named tar.gz in the directory &path2/EDA_PROCESS_OUTPUT_1X ?   Then I think just add a slash:

x tar -czvf "&path2/EDA_PROCESS_OUTPUT_1X/tar.gz" "&path2/EDA_PROCESS_OUTPUT_1X";

It's probably odd to have a file named tar.gz, you might want to give it a more descriptive name.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.

View solution in original post

6 REPLIES 6
Quentin
Super User

Assuming you have terminal access to the linux server (via putty or whatever), I would first get the tar command to work like you want it in the terminal.  Then once you have that working, I would go back to SAS and work on getting the X statement to issue that exact command.

 

Similar to how with the macro language, most people advise starting with working SAS code before trying to write a macro to generate that code.

 

If you get to the point where a command works on the terminal, but doesn't work when called via X statement, then would suggest posting both the command you submit on the terminal and your X statement.  

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Quentin
Super User

Glanced at your code.  I think in the tar command:

x tar '-czvf EDA_PROCESS_OUTPUT_1X.tar.gz' '/sasstor1/downloads/ASL_Execute/ILAP_EXTRACT_FILES/ILAP_ZIP_FILES/EDA_PROCESS_OUTPUT_1X';

you should specify the path to the tar file, e..g.:

x tar '-czvf /please/put/this/somehwere/special/EDA_PROCESS_OUTPUT_1X.tar.gz' '/sasstor1/downloads/ASL_Execute/ILAP_EXTRACT_FILES/ILAP_ZIP_FILES/EDA_PROCESS_OUTPUT_1X';

Without that, I would guess tar will put the .tar.gz file into your working directory perhaps.

 

Also, the X statement is not part of a DATA step, it's a global statement.  So you don't need to put them inside data _null_ step.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
arbnmedic33
Calcite | Level 5

Well it's getting one step closer, briefly:

 

%let prepath = /sasstor1/downloads;

%let path2 = &prepath/ASL_Execute/ILAP_EXTRACT_FILES/ILAP_ZIP_FILES;

x cd "&path2/EDA_PROCESS_OUTPUT_1X";
x tar -czvf "&path2/EDA_PROCESS_OUTPUT_1X.tar.gz" "&path2/EDA_PROCESS_OUTPUT_1X";

 

However it's now placing the '.tar.gz' files at "&path2", not at "&path2/EDA_PROCESS_OUTPUT_1X".  The files I need to zip are already in the EDA_PROCESS_OUTPUT_1X directory, looking to zip them and place in the same location.  Seems like that last 'x tar..." statement would do that.

 

Quentin
Super User

This statement:

x tar -czvf "&path2/EDA_PROCESS_OUTPUT_1X.tar.gz" "&path2/EDA_PROCESS_OUTPUT_1X";

I think tells tar to make a file EDA_PROCESS_OUTPUT_1X.tar.gz and put it in the directory &path2. 

 

Are you saying you want a file named tar.gz in the directory &path2/EDA_PROCESS_OUTPUT_1X ?   Then I think just add a slash:

x tar -czvf "&path2/EDA_PROCESS_OUTPUT_1X/tar.gz" "&path2/EDA_PROCESS_OUTPUT_1X";

It's probably odd to have a file named tar.gz, you might want to give it a more descriptive name.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
arbnmedic33
Calcite | Level 5

That got it, just had to drill down one more level, which actually doesn't match the way it has been done in the past via pasting one line at at time into Linux.

Thanks for the help, have a great weekend.

Quentin
Super User

Probably before it might have been counting on being in the correct working directly.  I tend to always specify full directory paths when I'm generating linux commands from SAS, just to avoid having to keep track of the working directory.  For example, if you issue a CD statement with one X command, and then issue the TAR statement with a second command, I'm not sure the working directory from the first command will be remembered.  I haven't tested it.  Since I usually have a macro variable with the path, like you do, it just seems clearer to me to always specify the path.  Glad you got it working.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.

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
  • 6 replies
  • 1302 views
  • 2 likes
  • 2 in conversation