SYSTASK enables you
to execute operating system-specific commands from within your SAS
session or application. Unlike the X statement, SYSTASK runs these
commands as asynchronous tasks, which means that these tasks execute
independently of all other tasks that are currently running. Asynchronous
tasks run in the background, so you can perform additional tasks while
the asynchronous task is still running.
For example, to copy
a SAS program, you might use this statement:
systask command "copy myprog.sas myprog1.sas"
taskname="copyfile" status=copystat;
The return
code from the
copy
command is saved in the
macro variable COPYSTAT.
Note: Windows command output is
not written to the SAS log.
Program steps that follow
the SYSTASK statements in SAS applications usually depend on the successful
execution of the SYSTASK statements. Therefore, syntax errors in some
SYSTASK statements will cause your SAS application to end.
There are two types
of tasks that can be run with SYSTASK:
All tasks started with
SYSTASK COMMAND are of type Task. For these tasks, if you do not specify
STATVAR or STATE, then SYSTASK LIST displays the task name, type,
and state, and the name of the status macro variable. To terminate
tasks of type Task, use SYSTASK KILL.
Tasks started from
SAS/CONNECT with the SIGNON statement or command, and RSUBMIT statement
are of type SAS/CONNECT Process. To display SAS/CONNECT processes,
use the LISTTASK statement to display the task name, type, and state.
To terminate a SAS/CONNECT process, use the KILLTASK statement. For
information about SAS/CONNECT processes, see SAS/CONNECT User's Guide.
Note: The preferred method for
displaying any task (not just
SAS/CONNECT processes) is to use the
LISTTASK statement instead of SYSTASK LIST. The preferred method for
ending a task is using the KILLTASK statement in place of SYSTASK
KILL.
The SYSRC macro variable
contains the return code for the SYSTASK statement. The status variable
that you specify with the STATUS option contains the return code of
the process started with SYSTASK COMMAND. To ensure that a task executes
successfully, you should monitor both the status of the SYSTASK statement
and the status of the process that is started by the SYSTASK statement.
If a SYSTASK statement
cannot execute successfully, the SYSRC macro variable will contain
a nonzero value. For example, there might be insufficient resources
to complete a task, or the SYSTASK statement can contain syntax errors.
With the SYSTASK KILL statement, if one or more of the processes cannot
be terminated, SYSRC is set to a nonzero value.
When a task is started,
its status variable is set to NULL. You can use the status variables
for each task to determine which tasks failed to complete. Any task
whose status variable is NULL did not complete execution. See WAITFOR
for more information about the status variables.
Unlike the X statement,
you cannot use the SYSTASK statement to start a new interactive session.