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?

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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