首先,你在做什么可能会更好地在一个宏中完成。这就是你在SAS大部分时间都是这样做的。
%macro calc_func(in_table=, out_table=, var=);
proc sql noprint;
create table &out_table. as
select &var.
from &in_table.
;
quit;
%mend calc_func;
所有第二,你可以在一个用户定义的函数做这个(或用户定义的调用程序,更有可能,因为没有什么这里返回);但如果我的理解是正确的,你必须通过到这个宏。
查看this paper了解更多信息,或者查看下面的示例。
%macro calc_func();
%let table1=%sysfunc(dequote(&table1.));
%let var1=%sysfunc(dequote(&var1.));
%let motherTable=%sysfunc(dequote(&motherTable.));
%put _all_;
proc sql;
create table &table1. as (
select &var1.
from sashelp.&motherTable.)
;
quit;
%mend calc_func;
proc fcmp outlib=work.funcs.test;
function calculate(table1 $, var1 $, motherTable $);
rc = run_macro('calc_func', motherTable, table1, var1);
return(rc);
endsub;
quit;
options cmplib=work.funcs;
data _null_;
x = calculate('newclass', 'age', 'class');
put x=;
run;
基本上,RUN_MACRO
取宏名称作为参数,然后允许FCMP创建具有FCMP变量(或传递的参数)的名称宏变量。但是,你必须删除他们的报价,这是...恼人的。不要这样做的好理由,除非它真的有必要,我想。
来源
2015-10-12 21:00:58
Joe
由于您所做的只是运行SAS代码,我只需将该“功能”作为宏写入即可。 – Tom