Chapter Contents

Previous

Next
WAITFOR Statement

WAITFOR Statement



Makes the current SAS session wait for the completion of one or more asynchronously executing tasks that are already in progress.

Local


Syntax
Syntax Description
Example 1
Example 2

Syntax

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

Syntax Description

_ANY_
suspends the SAS session for the completion of any of the specified tasks (a logical OR of the completion task states).

_ALL_
suspends the SAS session for the completion of all of the specified tasks (a logical AND of the completion task states).

task
identifies one or more tasks to be completed asynchronously in an optionally allotted time period. A remote-session-id that is associated with a REMOTE= or PROCESS= option to the RSUBMIT statement corresponds to the name of the task that is specified in the WAITFOR statement. It can also be the name of an asynchronous X command or some other asynchronously executing SAS task.

TIMEOUT=seconds
allots the interval in seconds for asynchronous task processing. If the specified tasks have not finished processing by timeout, task processing is terminated, giving the SYSRC system macro variable a non-zero status. If the specified tasks finish processing before timeout, the WAITFOR statement returns control to the SAS session.

Details

The WAITFOR statement is used to make the current SAS session wait for the completion of one or more tasks that are already in progress as specified by the options _ANY_ or _ALL_. You can use WAITFOR only for asynchronously executing tasks (for example, RSUBMITS that are executed with the WAIT option set to NO). If you try to use WAITFOR and there are no asynchronous tasks executing, then the WAITFOR statement will not enforce the wait condition, but, instead, will continue task execution in the current SAS session.

The name of the task corresponds with the remote-session-id that is assigned to the REMOTE= or PROCESS= option in the RSUBMIT statement. Omission of the REMOTE= or PROCESS= option implies the current session.

The WAITFOR statement can wait for the completion of one or more tasks. If more than one task is specified, then the WAITFOR statement must include either the _ANY_ or the _ALL_ options. The _ANY_ option suspends the SAS session for the completion of any of the specified tasks (a logical OR of the completion task states). The _ALL_ option suspends the SAS session for the completion of all of 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

This example shows the suspension of the current SAS 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 current SAS session to suspend execution in the current session until the REMHOST and the PRINTJB tasks finish. REMHOST and PRINTJB are remote session ids that are assigned to either the REMOTE= or the PROCESS= option in the RSUBMIT statement. Both tasks must complete within the allotted time or the time must expire before the WAITFOR statement returns control to the local SAS session. Should time expire before the completion of both tasks, control is returned to the current SAS session and the asynchronous tasks continue to execute. The SYSRC macro in the autocall library can be queried for task status. Alternatively, if you specified macro variables for the REMHOST and PRINTJB tasks with the MACVAR option, you could query those macro variables for status information.


Example 2

This statement causes the suspension of the current SAS session until either task REMHOST or FORMATJB has completed.

waitfor _any_ remhost formatjb; 

Because no time limit has been placed on the processing of these tasks, as much time as needed can be used for task completion. Upon completion of either task, the WAITFOR statement returns control to the current SAS session.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.