1

我有以下代码:

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温度。然而它不见了。虽然我提到了调试,但它%put &=res;解析为N, 但是put res; returns.`. 什么问题?

4

1 回答 1

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;
于 2017-07-03T11:28:54.483 回答