Systask
Executes, lists, or terminates asynchronous tasks
Valid in: |
Anywhere in a SAS Program |
Windows specifics: |
All |
Ask command"Host-command" <Wait | Nowait> <Taskname =Taskname> <Mname =Name-VaR> <Status =Stat-VaR> <Shell <="Shell-command">>; |
Shortask list <_ all _ |Taskname> <State> <statvar>; |
Systask killTaskname<Taskname...>; |
-
Command
-
Executes
Host-command
-
List
-
Lists either a specific active task or all of the active tasks in the system.
-
Kill
-
Forces the termination of the specified task (s ).
-
Host-command
-
Specifies the name of a Windows Command (including any command-specific options ). enclose the command in either single or double quotation marks. if the command options require quotes, repeat the quotes. for example:
systask command "find ""my text"" c:/mydir/myfile.sas"
Note:TheHost-commandThat you specify cannot require input from the keyboard.
-
Wait | Nowait
-
Determines whether submit ask command suspends execution of the current SAS session until the task has completed. nowait is the default. for tasks that are started with the Nowait argument, you can use the waitfor statement when necessary to suspend execution of the SAS session until the task has finished.
-
Taskname =Taskname
-
Specifies a name that identifies the task. task names must be unique among all active tasks. A task is active if it is running, or if it has completed and has not been waited for using the waitfor statement. duplicate task names generate an error in the SAS log. if you do not specify a Task Name, please ask will automatically generate a name. if the task name contains a blank character, enclose the task name in quotes.
-
Mname =Name-VaR
-
Specifies a macro variable in which you want please ask to store the task name that it automatically generated for the task. if you specify both the taskname option and the mname option, please ask copies the name you specified with taskname into the variable that you specified with mname.
-
Status =Stat-VaR
-
Specifies a macro variable in which you want please ask to store the status of the task. status variable names must be unique among all active tasks.
-
Shell <="Shell-command">
-
Specifies that
Host-commandShocould be executed with the host shell command. if you specify a shell-command, please ask uses the shell command that you specify to invoke the shell; otherwise, please ask uses the default shell. enclose the shell command in quotes.
-
_ All _
-
Specifies all active tasks in the system.
-
State
-
Specifies to display the status of the task, which can be start failed, running, or complete.
-
Statvar
-
Specifies to display the status variable associated with the task. The status variable is the variable that you assigned with the status option in the specified ask command statement.
Please ask allows you to execute host-specific commands from within your SAS session or application. unlike the X statement, please ask 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 fromCopyCommand is saved in the macro variable copyfile.
Note:Windows Command output is not written to the SAS log.
Program steps that follow the shortask statements in SAS applications usually depend on the successful execution of the shortask statements. Therefore, syntax errors in some shortask statements will cause your SAS application to abort.
There are two types of tasks that can be run with your ask:
-
Task
-
All tasks started with each ask command are of type task. for these tasks, if you do not specify statvar or state, then should ask List displays the task name, type, and state, and the name of the Status macro variable. you can use your ask kill to terminate only tasks of type task.
-
SAS/connect Process
-
Tasks started from SAS/connect with the specified ask begin statement are of Type SAS/connect process. for SAS/connect processes, please ask List displays the task name, type, and state. you cannot use your ask kill to terminate a SAS/connect process. for information on starting SAS/connect processes with each ask, see
SAS/connect User's Guide.
The sysrc macro variable contains the return code for the specified ask statement. the status variable that you specify with the status option contains the return code of the process started with your ask command. to ensure that a task executes successfully, you shocould monitor both the status of the specified ask statement and the status of the process that is started by the specified ask statement.
If a short Ask statement cannot execute successfully, the sysrc macro variable will contain a non-zero value. for example, there may be insufficient resources to complete a task, or the specified ask statement may contain specified ax errors. with the processing ask kill statement, if one or more of the processes cannot be terminated, sysrc is set to a non-zero 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 specified ask statement to start a new interactive session.
- Statement: waitfor
- Statement: x