SAS:使用热键执行 SAS 代码 [英] SAS: Execute SAS code using hotkey

查看:30
本文介绍了SAS:使用热键执行 SAS 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 SAS 9.4 for Windows 的增强编辑器中的键盘快捷键执行独立于我当前程序的代码.我已经以有限的成功实现了这一点,只能执行宏语句.但是,我也希望能够执行非宏语句.我该怎么做?

I want to execute code which is independent of my current program via keyboard shortcuts within the Enhanced Editor in SAS 9.4 for Windows. I've achieved this with limited success being able to execute only macro statements. However, I want to be able to execute non-macro statements, too. How do I do this?

这是我目前为止的想法.

Here's what I've figured out so far.

通过在命令提示符中输入KEYS"或提交进入 KEYS 菜单

Get to the KEYS menu by either entering "KEYS" into the command prompt or submitting

dm 'keys';

对于其中一个键,输入定义

For one of the keys, enter the definition

%put Hello, world!;

Ctrl+s 保存新的键绑定.出于解释的目的,我将它绑定到 F7.保存后,按 F7 和Hello, world!"将打印到日志中.

Save the new key binding by pressing Ctrl+s. For the purposes of this explanation, I will bind it to F7. Once saved, press F7 and "Hello, world!" will be printed to the log.

我们可以通过将上述代码放在宏中来进一步扩展这个概念.

We can extend this concept further by placing the above code in a macro.

%macro HelloWorld();
  %put Hello, world!;
%mend;

编译 %HelloWorld 宏.如果我们然后将 %HelloWorld(); 绑定到 F7,我们可以证明可以使用快捷方式调用宏.

Compile the %HelloWorld macro. If we then bind %HelloWorld(); to F7, we can demonstrate that a macro may be called with a shortcut.

我们可以更进一步,将我们的 %HelloWorld 宏保存为程序 HelloWorld.sas.如果我们然后将其放入 AUTOCALL 库中(运行 %put %sysfunc(pathname(sasautos)); 以查找它们在您计算机上的位置),我们可以执行它在任何新的 SAS 会话中.

We can take things further yet and save our %HelloWorld macro as a program HelloWorld.sas. If we then put this in an AUTOCALL library (run %put %sysfunc(pathname(sasautos)); to find where those are located on your computer), we can execute it within any new SAS session.

但是,似乎只有宏语句才能使用此方法.为了证明这一点,假设我们将 %HelloWorld 定义为

It appears, however, that only macro statements work with this method. To demonstrate this, suppose that we instead defined %HelloWorld as

%macro HelloWorld();
  data _null_;
    put 'Hello, world!';
  run;
%mend;

同样,将其保存为 HelloWorld.sas 并将其放置在 AUTOCALL 目录中.对我来说,当我尝试执行此操作时,出现以下错误:

Again, save this as HelloWorld.sas and place it in an AUTOCALL directory. For me, when I try to execute this, I get the following error:

ERROR: The SAS/EIS product with which the procedure is associated is either not licensed for
       your system or the product license has expired. Please contact your SAS installation
       representative.

通过 %INCLUDE

由于 AUTOCALL 需要编译和调用宏,我认为 %INCLUDE 可能会直接执行代码.

Via %INCLUDE

Since an AUTOCALL requires a macro to be compiled and called, I thought %INCLUDE might execute the code directly.

创建一个名为 HelloWorld.sas 的文件,其中包含 %put Hello, world!.将其保存到短文件路径.然后,在 KEYS 菜单中将 F7 绑定到 %include "C:Short PathHelloWorld.sas";.现在 F7 将打印Hello, world!"到日志.

Create a file called HelloWorld.sas containing %put Hello, world!. Save it to a short file path. Then, in the KEYS menu bind F7 to %include "C:Short PathHelloWorld.sas";. Now F7 will print "Hello, world!" to the log.

如果我们改为保存

data _null_;
  put 'Hello, world!';
run;

HelloWorld.sas 并尝试使用我们的 %INCLUDE 快捷方式运行它,我收到同样的错误:

to HelloWorld.sas and try to run it using our %INCLUDE shortcut, I receive the same error:

ERROR: The SAS/EIS product with which the procedure is associated is either not licensed for
       your system or the product license has expired. Please contact your SAS installation
       representative.

杂项.尝试

我也尝试将代码直接输入到 KEYS 定义中,但同样,它似乎只适用于宏语句.

Misc. Attempts

I've also tried entering code directly into a KEYS definition, but again, it only seems to work for macro statements.

也许可以使用 %SYSFUNC,但我的最终目标是能够使用 PROC SQL 或数据步骤,我不认为 %SYSFUNC 可以做到这一点.

It might be possible to use %SYSFUNC, but my ultimate goal is to be able to use PROC SQL or data steps and I don't think %SYSFUNC can do this.

推荐答案

可以使用submit命令,即将key定义为:

You can use the submit command, i.e. define a key as:

submit "data _null_ ; put 'Hello World!'; run;"

也适用于宏调用:

submit "%HelloWorld()"

这篇关于SAS:使用热键执行 SAS 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆