Learning SAS? Welcome to the exclusive online community for all SAS learners.

SAS macro variable %sysrc return code

Reply
Occasional Contributor
Posts: 9

SAS macro variable %sysrc return code

Hi All,

I am using "X" command to run the code in unix enviroment through SAS Code. I have given %sysrc to capture the return code.

I am facing a strange issue. Even my code is running successfully but %sysrc is not returning 0.

It always some other numerical value.

Can anyone let me know what kind of return value captured by %sysrc.?

and what does each return value stand for?

I know below are the return code when I run the code on unix using shell script.

ConditionSeverityReturn Code  Value                
All steps terminated normallySUCCESS0
SAS issued warning(s)WARNING1
SAS issued error(s)ERROR2
User issued the ABORT statementINFORMATIONAL3
User issued the ABORT RETURN statementFATAL4
User issued the ABORT ABEND statementFATAL5
SAS internal errorINFORMATIONAL6
Super User
Super User
Posts: 6,502

Re: SAS macro variable %sysrc return code

Occasional Contributor
Posts: 9

Re: SAS macro variable %sysrc return code

Tom,

I am talking about %sysrc macro variable.

can you suggest me any other way to capture return code of SAS prog which is running through "X" command. Lts running in Unix environment


Thanks


Trusted Advisor
Posts: 1,300

Re: SAS macro variable %sysrc return code

As Tom said, you are looking for &sysrc, not %sysrc.

Super User
Super User
Posts: 6,502

Re: SAS macro variable %sysrc return code

You reference the value of macro variable using &.

Make sure to reference it right away as a number of other things can modify the value of the SYSRC macro variable.

If you are still not getting the return code you want then you might need modify your unix command so that it stores the code into a file instead and then read that file after the unix command has finished.

Occasional Contributor
Posts: 9

Re: SAS macro variable %sysrc return code

Tom,

I am not sure if I am getting you. Could you please explain it with any example. it would be great if you can give me any example.

Thanks

Super User
Super User
Posts: 6,502

Re: SAS macro variable %sysrc return code

Here is a trivial example showing a successful and failed X call.

1    x 'echo hello'

1  !               ;

2    %let rc1=&sysrc ;

3    %put &=rc1 ;

RC1=0

4    x 'echxxhello'

4  !               ;

5    %let rc2=&sysrc ;

6    %put &=rc2 ;

RC2=127

Occasional Contributor
Posts: 9

Re: SAS macro variable %sysrc return code

Thanks Tom for sharing with an example.


I am also doing the same thing. Though there is no error in sas log but still it's throwing an RC  > 0


Can I get the list of return code to handle it? or If you can suggest me any other way. to handle it.

 

Thanks

Super User
Super User
Posts: 6,502

Re: SAS macro variable %sysrc return code

Normally I like to wrap the system calls in a DATA _NULL_ so that I can trap any messages that it might be trying to send me.

7    data _null_;

8     infile 'echxxhello' pipe ;

9     input ;

10    put _infile_;

11   run;

NOTE: The infile 'echxxhello' is:

      Pipe command="echxxhello"

/bin/ksh: line 1: echxxhello: not found

NOTE: 1 record was read from the infile 'echxxhello'.

      The minimum record length was 39.

      The maximum record length was 39.

Super User
Posts: 6,972

Re: SAS macro variable %sysrc return code

The SAS log does not include error messages from the operating system (or any output done to stdout and stderr) during execution of the system command in the X statement.

You can capture all messages to the log by using this construct:

filename oscmd pipe "command 2>&1";

data _null_;

infile oscmd;

put _infile_;

run;

Note the 2>&1, which redirects stderr output to stdout, which can be read from the infile.

There is no taxative "list of return codes", as these are arbitrarily set by the executed statement. The only convention is that a value of 0 signals successful execution.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Valued Guide
Posts: 2,175

Re: SAS macro variable %sysrc return code

To have a look at %macro sysrc, just look at the saslog after submiting the code:

  %inc sasautos( sysrc ) /source2 ;

Occasional Contributor
Posts: 9

Re: SAS macro variable %sysrc return code

Peter,


could you please let me know with an example.


Thanks


Ask a Question
Discussion stats
  • 11 replies
  • 4630 views
  • 0 likes
  • 5 in conversation