Previous Page | Next Page

Syntax for the RSUBMIT Statement and Command

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
Syntax Description
Example 1: WAITFOR
Example 2: WAITFOR

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 timeout, 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 non-zero status.

If the specified tasks are completed before timeout, 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.  [cautionend]

Default: 0
See Also: CONNECTREMOTE= option

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.


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;

This statement causes the client session to wait for the REMHOST and the PRINTJB tasks to finish. Both tasks must complete within the allotted time or the time must expire before the WAITFOR statement returns control to the client session. If time expires before the completion of both tasks, control is returned to the current session and the asynchronous tasks continue to execute. The SYSRC global macro variable can be queried to detect this condition. Alternatively, if you specified macro variables for the REMHOST and PRINTJB tasks using the CMACVAR option in the RSUBMIT statement, you could query those macro variables for status information.


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; 

Because the execution of these tasks is not restricted to a time limit, the client session will be suspended until one of the specified tasks completes. Upon completion of either task, the WAITFOR statement returns control to the client session.

Previous Page | Next Page | Top of Page