BookmarkSubscribeRSS Feed
niejung
Obsidian | Level 7

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?

9 REPLIES 9
jimbarbour
Meteorite | Level 14

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

niejung
Obsidian | Level 7

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.

jimbarbour
Meteorite | Level 14

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:

  • SYSERR
  • SYSCC
  • SYSRC
  • SYSFILRC
  • SYSLIBRC
  • SYSLCKRC
  • SQLEXITCODE
  • SQLRC
  • SQLXRC

 

The most critical return codes (in my opinion) in the context of a SAS program are:

  • SYSCC -- master return code used inside of SAS programs.
  • SYSRC -- the return code from operations submitted via the X command (or similar commands) to the O/S.

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

Kurt_Bremser
Super User

SYSRC holds the return code of the most recently executed (via X or %SYSEXEC) external command. It's got nothing to do with the return code of the SAS session itself.

SYSCC is the one that holds (or corresponds to) the exit code of the SAS session.

jimbarbour
Meteorite | Level 14

@Kurt_Bremser,

 

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

Kurt_Bremser
Super User

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.

jimbarbour
Meteorite | Level 14

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

Kurt_Bremser
Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9 replies
  • 3129 views
  • 1 like
  • 3 in conversation