The WAITFOR statement
suspends execution of the current SAS session until the specified
tasks finish executing or until the TIMEOUT= interval has elapsed.
If the specified task was started with the WAIT option, then the WAITFOR
statement ignores that task.
For a description of
the WAIT option, see SYSTASK Statement: UNIX.
For example, the following
statements start three different X client programs and waits for them
to complete:
systask command "xv" taskname=pgm1;
systask command "xterm" taskname=pgm2;
systask command "xcalc" taskname=pgm3;
waitfor _all_ pgm1 pgm2 pgm3;
The WAITFOR statement
can be used to execute multiple concurrent SAS sessions. The following
statements start three different SAS jobs and suspend the execution
of the current SAS session until those three jobs have finished executing:
systask command "sas myprog1.sas" taskname=sas1;
systask command "sas myprog2.sas" taskname=sas2;
systask command "sas myprog3.sas" taskname=sas3;
waitfor _all_ sas1 sas2 sas3;
Note: In this method, SAS terminates
after each command, which can result in reduced performance.
SAS/CONNECT
can also be used for executing parallel SAS sessions. See the
SAS/CONNECT User's Guide for more information.
If you have long-running
jobs that use the SYSTASK command multiple times, use the WAITFOR
statement or the CLEANUP option in the SYSTASK command to clear the
memory. The WAITFOR statement releases memory by removing the information
for all completed processes that were started by the SYSTASK command.
The CLEANUP option clears memory when a specific job completes, and
releases memory for further use. If you use the WAITFOR statement
after a job has completed, the statement is ineffective because the
job has already been cleaned up by the CLEANUP option.
The SYSRC macro variable
contains the return code for the WAITFOR statement. If a WAITFOR statement
cannot execute successfully, the SYSRC macro variable will contain
a nonzero value. For example, the WAITFOR statement might contain
syntax errors. If the number of seconds specified with the TIMEOUT
option elapses, then the WAITFOR statement finishes executing, and
SYSRC is set to a nonzero value if one of the following occurs:
-
you specify a single task that
does not finish executing
-
you specify more than one task
and the _ANY_ option (which is the default setting), but none of the
tasks finishes executing
-
you specify more than one task
and the _ALL_ option, and any one of the tasks does not finish executing
Any task whose status variable is still NULL after
the WAITFOR statement has executed did not complete execution.
For a description of
status variables for individual tasks, see SYSTASK Statement: UNIX.