Example 5: Using MP CONNECT and the WAITFOR Statement


This example enables you to perform two encapsulated tasks in parallel, but both tasks must be completed before the client session can continue.
The following program sorts two data sets asynchronously. After both sort operations are complete, the results are merged.


/* SAS system option SASCMD starts an MP CONNECT server session. */
option autosignon=yes;
option sascmd="!sascmd";

/* Remote submit first task. */
/* Sort the first data set as one task. */
/* SIGNON performed automatically by RSUBMIT. */
rsubmit process=task1 wait=no; 
libname mydata '/project/test1';

      proc sort data=mydata.part1;
     by x;

/* Remote submit second task. */
/* SIGNON performed automatically by RSUBMIT. */ 
rsubmit process=task2 wait=no;
libname mydata '/project/test2';

   /* Sort the second data set as one task. */
   proc sort data=mydata.part2;
     by x;

/* Wait for both tasks to complete. */
waitfor _all_ task1 task2;

/* Merge the results and continue processing. */
libname mydata ('/project/test1' '/project/test2');
data work.sorted;
  merge mydata.part1 mydata.part2;