BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Balli
Obsidian | Level 7

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

    

1 ACCEPTED SOLUTION

Accepted Solutions
Balli
Obsidian | Level 7

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;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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.

Balli
Obsidian | Level 7

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.

Kurt_Bremser
Super User

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).

Balli
Obsidian | Level 7

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;

Balli
Obsidian | Level 7
"The last line in your input will now contain the return code from your command."

Does that mean I need to look for the return code in my input text file ?
Kurt_Bremser
Super User

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: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 2762 views
  • 2 likes
  • 2 in conversation