SAS多任务并行处理,利用systask

SYSTASK



Executes, lists, or terminates asynchronous tasks

Valid in:anywhere in a SAS program
Windows specifics:all

Syntax

SYSTASK COMMAND "host-command"
<WAIT | NOWAIT>
<TASKNAME=taskname>
<MNAME=name-var>
<STATUS=stat-var>
<SHELL<="shell-command">>;

SYSTASK LIST <_ALL_ | taskname> <STATE> <STATVAR>;

SYSTASK KILL taskname <taskname...>;

COMMAND
executes the 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:   The host-command that you specify cannot require input from the keyboard.   [cautionend]

WAIT | NOWAIT
determines whether SYSTASK 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, SYSTASK 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 SYSTASK to store the task name that it automatically generated for the task. If you specify both the TASKNAME option and the MNAME option, SYSTASK 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 SYSTASK to store the status of the task. Status variable names must be unique among all active tasks.

SHELL<="shell-command">
specifies that the host-command should be executed with the host shell command. If you specify a shell-command, SYSTASK uses the shell command that you specify to invoke the shell; otherwise, SYSTASK 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 SYSTASK COMMAND statement.


Details

SYSTASK allows you to execute host-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 COPYFILE.

Note:   Windows command output is not written to the SAS log.   [cautionend]

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 abort.

There are two types of tasks that can be run with SYSTASK:

Task
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. You can use SYSTASK KILL to terminate only tasks of type Task.

SAS/Connect Process
Tasks started from SAS/Connect with the SYSTASK BEGIN statement are of type SAS/Connect Process. For SAS/Connect processes, SYSTASK LIST displays the task name, type, and state. You cannot use SYSTASK KILL to terminate a SAS/Connect process. For information on starting SAS/Connect processes with SYSTASK, see SAS/CONNECT User's Guide.

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 non-zero value. For example, there may be insufficient resources to complete a task, or the SYSTASK statement may contain systax errors. With the SYSTASK 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 SYSTASK statement to start a new interactive session.


See Also

  • Statement: WAITFOR

  • Statement: X

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值