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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.