I set the code to "abort return 4", but it did not set overall sas program RC=2. How can I set the RC=2 when I abort the program?
What kind of a system are you running on? On a mainframe, Abort Return 2 definitely sets the overall return code and can be queried by downstream steps in the JCL.
If you are talking about the internal return code inside SAS, that's the macro variable SYSCC. In a data step, it can be set:
CALL SYMPUTX('SYSCC', 2, 'G');
In open code, non-Data step code:
%LET SYSCC = 2;
You can then query &SYSCC in downstream code, for example:
%IF &SYSCC < 2 %THEN
%DO;
... Code goes here...
%END;
It is not necessary to create a macro in order have a %IF in open code if you are on SAS 9.4 M5 or higher. The %DO and %END are required.
Jim
I am running SAS program from SAS GRID server. I have a condition if HTTP response is not equal to 200, then abort the program. The program did abort it, but RC code is 1. I like to know how I can overwrite the return code to 2. The version of the program is old. 9.4 M3.
When you say "RC," are you talking at the OS level (outside SAS)? Or are you talking about inside SAS?
There are a lot of return codes inside SAS:
The most critical return codes (in my opinion) in the context of a SAS program are:
Be judicious in the use of SYSRC. I've seen the OS react strangely to a SYSRC set manually in a SAS program run in UNIX. I typically try not to touch SYSRC, but I suppose there could be times where it would be appropriate.
Jim
Hmmm. Interesting. All I can say is that at my last job when working on a UNIX (POSIX) OS computer that when I set SYSRC manually that some very strange things happened. I assumed it was being passed back to the OS, but from what you're saying, that is incorrect. I would definitely agree that SYSRC contains the return code from, say, an unzip executed via an X command.
At least in UNIX, I've seen that SYSCC affects the return code at the OS level, but it wasn't 1:1. For example a SYSCC of 8 would result in an OS return code of (going on memory here) 1. As I think about it, that's probably what @niejung is asking about since a SAS grid is typically UNIX or LINUX. I was thinking that SYSRC was the one to set for that, but apparently not. I've been on Windows lately, so I probably shouldn't rely on my poor memory for Unix/Linux. I deleted my earlier remarks about SYSRC.
Jim
Yes, the only SYSCC code that is handed to the OS as is is zero; I've seen numbers like 1012 that resulted in a return code of 2 (ERROR).
The proper way to force the return code is the ABORT ABEND.
Thank you for that, @Kurt_Bremser. I'm surprised one has to code ABORT ABEND 2, since I used to code ABORT RETURN 2 when I had a job where we ran on a mainframe and checked return codes at the JCL level frequently. Usually SAS tries to be uniform across platforms.
My current job uses Windows. I don't have much occasion to check return codes after SAS executes, but if I get time, I'll have to see how return codes post-SAS work in Windows. You've gotten me curious. 🙂
Jim
I think that ABORT RETURN should also work on all platforms; the use of ABORT ABEND here is probably a remnant of our mainframe past, where ABEND seems to have consequences with regards to the JCL scripts and scheduler that probably do not exist on other systems.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: