SAS:使用热键执行SAS代码 [英] SAS: Execute SAS code using hotkey
问题描述
我要执行的代码是独立我目前的计划的通过在SAS 9.4增强型编辑器中的键盘快捷键的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!;
保存新的密钥按
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;
编译的
Compile the %HelloWorld
macro. If we then bind %HelloWorld();
to F7
, we can demonstrate that a macro may be called with a shortcut.
我们可以采取进一步的事情还没有和我们的
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.
它的出现,然而,只有宏语句用这种方法工作.为了证明这一点,假设我们代替定义
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;
再次保存为
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
由于一个自动调用需要的宏被编译和调用,我想
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绑定
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 Path\HelloWorld.sas";
. Now F7
will print "Hello, world!" to the log.
如果我们代替保存
data _null_;
put 'Hello, world!';
run;
到<7>并尝试使用运行它我们的<12>快捷方式,我收到了同样的错误:
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.
混杂.尝试
我也试过直接输入代码放到一个按键定义,但再次,它似乎只对宏语句的工作.
Misc. Attempts
I've also tried entering code directly into a KEYS definition, but again, it only seems to work for macro statements.
可能可以使用<20>,但我的最终目标是能够使用
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.
推荐答案
可以使用提交命令,即定义一个键为:
You can use the submit command, i.e. define a key as:
submit "data _null_ ; put 'Hello World!'; run;"
也可用于宏调用:
submit "%HelloWorld()"
这篇关于SAS:使用热键执行SAS代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!