BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

If I use systask to run two linux commands on one line, e.g.:

systask command "gzip ~/notthere.txt; touch ~/foo.txt" status=mystatus shell wait;
%put >>&mystatus<< ;

The status returned is the status of the second command (touch in this case).  So even if the first command (gzip) fails, my status will be set to 0 because the second (touch) succeeded.  I recognize it's linux setting the exit code, not SAS. 

 

Is there an easy way to grab the maximum status from all the commands that were submitted?

 

Okay, I googled, looks like using the && operator could work for what I want.  If the first command fails, the second command won't be executed and I'll get the exit code from the first command:

systask command 'gzip ~/notthere.txt && touch ~/foo.txt' status=mystatus shell wait;
%put >>&mystatus<< ;

Is there a better way?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

&& is the UNIX way to do this; you'll see it in all kinds of setup/installation and other shell scripts.

You can, of course, always catch the exit codes separately:

filename os pipe 'gzip ~/notthere.txt; RC1=$?; touch ~/foo.txt; RC2=$?; echo "rc1=$RC1 rc2=$RC2"';

data retcode;
infile os end=done;
length retcodes $20;
input;
if done;
retcodes = _infile_;
run;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

&& is the UNIX way to do this; you'll see it in all kinds of setup/installation and other shell scripts.

You can, of course, always catch the exit codes separately:

filename os pipe 'gzip ~/notthere.txt; RC1=$?; touch ~/foo.txt; RC2=$?; echo "rc1=$RC1 rc2=$RC2"';

data retcode;
infile os end=done;
length retcodes $20;
input;
if done;
retcodes = _infile_;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1166 views
  • 1 like
  • 2 in conversation