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?
&& 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;
&& 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;
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 25. 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.