我有一个我在本地机器上用.sas文件创建的宏.我还有一个用于测试宏的本地数据集.此数据集具有与远程数据集相同的描述符,但只有较少的观察值.现在,我正在尝试针对远程数据集运行本地宏.这基本上就是我所拥有的:
这按预期工作:
%include "C:\my_sas_macro.sas";
%my_sas_macro(my_data=work.localdata)
Run Code Online (Sandbox Code Playgroud)
但是这会产生错误(错误如下):
%include "C:\my_sas_macro.sas";
rsubmit;
%my_sas_macro(my_data=remotelib.remotedata)
endrsubmit;
Run Code Online (Sandbox Code Playgroud)
有错误的日志:
125 %include "C:\my_sas_macro.sas";
136
137 rsubmit;
NOTE: Remote submit to REMOTEID.__7551 commencing.
WARNING: Apparent invocation of macro MY_SAS_MACRO not resolved.
83 %my_sas_macro(my_data=remotelib.remotedata)
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
84 endrsubmit;
NOTE: Remote submit to REMOTEID.__7551 complete.
Run Code Online (Sandbox Code Playgroud)
我很确定我需要以某种方式将%macro /%mend块转移到服务器上,但我无法弄清楚如何.我已经看到了,%SYSLPUT但这是宏变量,而不是完整的宏.
无论如何,我可以在服务器上运行我的宏,而不必只是通过SSH代码和%include那里?
谢谢!
所以根据@ CarolinaJay65的回答,我提出了以下宏,这对我来说效果很好.
%macro include_on_server(file=);
%let server_file = ~/temp.sas;
%SYSLPUT macro_file=&file;
%SYSLPUT server_file = &server_file;
rsubmit;
proc upload
infile= "¯o_file."
outfile= "&server_file."
; run;
%include "&server_file.";
endrsubmit;
%mend include_on_server;
Run Code Online (Sandbox Code Playgroud)
这允许我只是调用%include_on_server(file="C:\my_file.sas"),然后它现在包含在我的远程会话中.
如何使用Proc Upload
rsubmit;
Proc Upload
infile='C:\my_sas_macro.sas'
outfile='//server/my_sas_macro.sas' ;
run;
%include '//server/my_sas_macro.sas';
%my_sas_macro(my_data=remotelib.remotedata)
Run Code Online (Sandbox Code Playgroud)
或者您可以将整个宏分配给宏变量,然后使用%syslput