WAITFOR Statement

Causes the client session to wait for the completion of one or more tasks (asynchronous RSUBMIT statements) that are in progress.
Valid in: client session

Syntax

WAITFOR <_ANY_|_ALL_> task ... taskn <TIMEOUT=seconds> ;

Syntax Description

_ANY_
causes the client session to wait for the completion of any of the specified tasks (a logical OR of the completion task states).
_ALL_
causes the client session to wait for the completion of all of the specified tasks (a logical AND of the completion task states).
task...taskn
identifies one or more asynchronous tasks to be completed. The task corresponds with the server–ID that is associated with the CONNECTREMOTE= option when the RSUBMIT is submitted.
TIMEOUT=seconds
allots the interval, in seconds, to wait for one or more asynchronous tasks to complete. If the specified tasks have not completed by time-out, the WAITFOR statement is terminated, control is returned to the client session, and the asynchronous tasks continue to execute until they are completed. The SYSRC system macro variable will have a nonzero status.
If the specified tasks are completed before time-out, the WAITFOR statement returns control to the client session as soon as the specified tasks are completed.
Note: Specifying TIMEOUT=0 is equivalent to providing no TIMEOUT value. Specifying a value of 0 causes the client session to wait indefinitely for the asynchronous tasks to complete before control is returned to the client session.

Details

The WAITFOR statement causes the client session to wait for the completion of one or more tasks that are in progress in the server session as specified by the options _ANY_ or _ALL_. WAITFOR synchronizes dependent tasks. You can use WAITFOR only for asynchronously executing tasks. If you use WAITFOR and there are no asynchronous tasks executing, the WAITFOR statement does not enforce a wait condition. Instead, execution continues in the client session.
The name of the task corresponds with the server-ID.
The WAITFOR statement can wait for the completion of one or more tasks. If more than one task is specified and neither _ANY_ nor _ALL_ is specified, _ANY_ is implied. The client session will wait for any of the listed tasks to complete before resuming control. This is not an error condition.
If more than one task is specified, and the _ANY_ option is specified, the client session waits for the completion of any of the specified tasks (a logical OR of the completion task states). If the _ALL_ option is specified, the client session waits for the completion of all the specified tasks (a logical AND of the completion task states). The WAITFOR statement does not support complex logical statements, such as A OR (B AND C).
Invalid tasks that are specified in the WAITFOR statement are ignored but are identified in notes in the SAS log.

Examples

Example 1: Example 1: WAITFOR

The following example shows the suspension of the client session until both tasks have completed or 300 seconds (5 minutes) pass, whichever occurs first.
waitfor _all_  remhost printjb  timeout=300;

Example 2: Example 2: WAITFOR

The following WAITFOR statement causes the client session to wait for either the REMHOST or FORMATJB task to complete.
waitfor _any_ remhost formatjb;