03-16-2015 06:50 PM
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.
|Condition||Severity||Return Code Value|
|All steps terminated normally||SUCCESS||0|
|SAS issued warning(s)||WARNING||1|
|SAS issued error(s)||ERROR||2|
|User issued the ABORT statement||INFORMATIONAL||3|
|User issued the ABORT RETURN statement||FATAL||4|
|User issued the ABORT ABEND statement||FATAL||5|
|SAS internal error||INFORMATIONAL||6|
03-16-2015 07:24 PM
Looks like you have the %SYSRC() autocall macro confused with the SYSRC macro variable?
03-17-2015 12:09 AM
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
03-17-2015 09:05 AM
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.
03-17-2015 06:46 PM
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.
03-17-2015 07:44 PM
Here is a trivial example showing a successful and failed X call.
1 x 'echo hello'
1 ! ;
2 %let rc1=&sysrc ;
3 %put &=rc1 ;
4 x 'echxxhello'
4 ! ;
5 %let rc2=&sysrc ;
6 %put &=rc2 ;
03-17-2015 08:20 PM
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.
03-17-2015 08:28 PM
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_;
NOTE: The infile 'echxxhello' is:
/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.
03-18-2015 03:11 AM
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";
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.