One of our stored processes is using unnamed PIPE to run an exe file to parse addresses. Whenever it fails it logs a stderr output similar to the one below in the log and the process continues. We can not find out it failed until we look at the output or the log.
How can we get our process to abort as soon as it finds stderr output from PIPE command ?
filename adv pipe "&cmd &inputFile. &location";
Stderr output:
Unhandled Exception: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Error 96: ERR_STAN_DLL_CALL_EXCEPTION. iPaf32.dll:FixLastLine
Thanks Kurt, this works using redirection of stderr to stdout and conditional processing.
filename adv pipe "&cmd &inputFile. &location 2>&1";
data _null_;
infile adv truncover;
input;
if index(lowcase(_infile_),'exception:') then do;
error ' Process Failed with an Exception';
abort;
end;
run;
Add a short command:
filename adv pipe "&cmd &inputFile. &location; echo $?";
The last line in your input will now contain the return code from your command.
Here my input is a text file and the pipe command creates an output file with same name as input but with different extension.
I did not get the return code anywhere after adding echo.
Mind that my shell code is for UNIX. If you are running SAS on Windows (yucc), you will have to use Windows syntax, but the principle should be the same. What I think will also work in Windows is 2>&1 (redirection of stderr to stdout).
Thanks Kurt, this works using redirection of stderr to stdout and conditional processing.
filename adv pipe "&cmd &inputFile. &location 2>&1";
data _null_;
infile adv truncover;
input;
if index(lowcase(_infile_),'exception:') then do;
error ' Process Failed with an Exception';
abort;
end;
run;
When used in an infile statement, the file reference created from filename pipe sends all output from the external command(s) to the input statement(s) in the data step. Since the final command displays the return code from the immediately preceding command, this will be the last "line" of your input.
Still keep in mind that
echo $?
is UNIX syntax. Windows should work with
echo %errorlevel%
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.