Example 7: Preventing Pipes from Closing Prematurely

Purpose

The TIMEOUT= option in the LIBNAME statement can be useful if a considerable delay is anticipated between the time that one task tries to read from a pipe and the time when another task starts to write to that pipe.
In this program, task P1 performs several DATA steps, a PROC SORT, and a PROC RANK, which is the step that writes to the pipe OUTLIB. However, task P2 is idle before the execution of the DATA step, which reads from the pipe INLIB. Therefore, a longer time-out is specified in the INLIB LIBNAME statement in order to allow sufficient time for task P1 to complete its processing before writing its output to the pipe.

Program

rsubmit p1 wait=no;
      libname outLib sasesock "pipe" timeout=10000;
      data a b;
         do i=1 to 10;
            output;
         end;
      run;
      data c;
         set a b;
      run;
      proc sort data=c out=sorted;
         by i;
      run;
      proc rank data=sorted out=outLib.ranked;
         var i;
         ranks Check;
      run;
   endrsubmit;
   rsubmit p2 wait=no;
      libname inLib  sasesock "pipe" timeout=60000;
      data fromPipe;
         set inLib.ranked;
      run;
      proc print; run;
   endrsubmit;