BookmarkSubscribeRSS Feed
wellsfargo123
Fluorite | Level 6

sas_program= "test_sas.sas"

log_file ="test_sas.log"

sas $sas_program -log $log_file

if [$? -eq 0]; then

STATUS="success"

else

STATUS="failed"  

# I would like to handle  the exit status of program completed execution as per  "%abort cancel" statements in sas program

# What will be the exit status if the program execution  ended due to "%abort cancel" or "%abort return"? The program is running on Linux.

fi

15 REPLIES 15
Quentin
Super User

The documentation will tell you what it exit status should be, but since you've got a test program, probably easier to just test it out and see what you get.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
wellsfargo123
Fluorite | Level 6

In the above code Exit status 2 is always a system reported sas error ?

Quentin
Super User

I believe so.  See this doc page: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostunx/p0h28whoxxvtztn15wqqvv9o41py.htm

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Tom
Super User Tom
Super User

Save the status code into your own environment variable.

sas $sas_program -log $log_file
rc=$?
echo rc=$rc

Then try running different programs to see what return code you get.

Try one with no warnings or errors. One with just warnings. One with errors.  One that used ABORT ABEND to force a return code.

Spoiler
If memory serves me you should find that 0 is returned when there are no warnings. 1 when there are warnings only and 2 when there are errors. And that you can use ABORT ABEND to return any other code you want.
wellsfargo123
Fluorite | Level 6

I have test th eprogram with %abort, %abort cancel , %abort return

 

 

When the program stopped execution after %abort cancel -- the exit status =2

For erros int he program, for example, I  made the the path to a dataset toa different location where the dataset does not exist.

 

Thee   exit stats was 2

 

%abort return -- exit status =4

%abort exit status =3.

 

 

So there is no was of distingushing errors and %abort cancel, as both of return exit stat =2 in LINUX.

 

Any ideas to distingush between %abort cancel statement and errors in sas program ?

 

 

Tom
Super User Tom
Super User

Works for me with the actual ABORT statement.

>echo 'data _null_; abort 100; run;' > abort.sas
>sas -noautoexec abort.sas; echo rc=$?
rc=100
wellsfargo123
Fluorite | Level 6

Currently the program is using %abort  cancel in the existng programs. To implement the below solution around 300 programs are to be modified. So this solution is not applicable.

 

Tom
Super User Tom
Super User

@wellsfargo123 wrote:

Currently the program is using %abort  cancel in the existng programs. To implement the below solution around 300 programs are to be modified. So this solution is not applicable.

 


If the programs aren't doing what you want then you will have to change them (or live with them).

Specifying the return code works with %ABORT CANCEL also.

>echo '%macro x; %abort cancel 100; %mend x; %x;' > abort.sas
>sas -noautoexec abort.sas; echo rc=$?
rc=100
wellsfargo123
Fluorite | Level 6

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostunx/p0h28whoxxvtztn15wqqvv9o41py.htm

 

As per this link the exits status 2 is specifically for  sas errors . Appreciate your work around. Hope this will be fixed in the next versions as per the documentation.  

 

Kurt_Bremser
Super User

When you issue the %ABORT CANCEL statement, an error message is written to the log, so it's only logical that the program also terminates with the error exit code.

 

If you want all your programs to terminate with the same code when %ABORT CANCEL is used, change the statements. On UNIX, awk is the perfect tool for this. But you can also write a SAS program to do that.

Tom
Super User Tom
Super User

If the goal is to treat the %ABORT CANCEL as NOT being an error you can set the exit code to 1 (warning).  Note you cannot set it to 0 (no error).  If you try to set it to 0 it just ends up being set to 2 (not sure why).

wellsfargo123
Fluorite | Level 6
That solution is not feasibile.
Tom
Super User Tom
Super User

@wellsfargo123 wrote:
That solution is not feasibile.

No idea what that means.

You want to distinguish between errors caused by normal SAS errors (bad code, missing files, etc) and those caused by programmed ABORT statements.  The way to do that is to set your own exit code in the ABORT statement.  If you do not make that change there is no way to tell the difference.

 

I guess you could try to read the LOG and guess what happened.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 15 replies
  • 1061 views
  • 0 likes
  • 4 in conversation