SAS proc fcmp返回丢失

时间:2017-07-03 11:15:19

标签: sas fcmp

我有以下代码:

options mprint mlogic symbolgen;
%macro get_vtype();
  %let table = %sysfunc(dequote(&table.));
  %let var = %sysfunc(dequote(&var.));

  data metadata.temp;
    set &table.;
    var = vtype(&var.);
    call symput('res',vtype(&var.));
  run;
%put &=res;
%mend;
proc fcmp outlib=work.functions.wrapper;
  function myvtype(table $,var $) $ 1;
    rc = run_macro('get_vtype',table,var,res);
    put rc;
    put res;
    return (res);
  endsub;
quit;
options cmplib=work.functions;
data temp;
  vtype = myvtype("sashelp.class","age");
run;

我希望得到N作为temp的结果。然而它缺失了。在我提到的调试时,%put &=res;解析为N,但put res; returns。`。 哇是问题?

1 个答案:

答案 0 :(得分:3)

我的猜测是metadata会话中没有分配run_macro库。

我在run_macro时遇到了一些非常奇怪且不一致的结果,我尽量避免使用它 - 请尝试使用dosubl。以下代码有效:

%macro get_vtype(table,var);
  data _null_;
    set &table.;
    var = vtype(&var.);
    call symputx('res',vtype(&var.),'g');
    stop;
  run;
%put &=res;
%mend;
proc fcmp outlib=work.functions.wrapper;
  function myvtype(table $,var $) $ 1;
    rc = dosubl(cats('%get_vtype(',table,',',var,');'));
    put rc;
    length res $1;
    res=symget("res");
    put res;
    return (res);
  endsub;
quit;
options cmplib=work.functions;
data test;
  vtype = myvtype("sashelp.class","age");
run;