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.
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.
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.
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.
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.
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.
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: