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
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.
In the above code Exit status 2 is always a system reported sas error ?
I believe so. See this doc page: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/hostunx/p0h28whoxxvtztn15wqqvv9o41py.htm
Not Solved yet
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.
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 ?
Works for me with the actual ABORT statement.
>echo 'data _null_; abort 100; run;' > abort.sas >sas -noautoexec abort.sas; echo rc=$? rc=100
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.
@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
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.
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.
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 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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.