Search code examples
sasfcmp

SAS proc fcmp returns missing


I have the following code:

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;

I expected to get N as result in temp. However it is missing. While Debugging I mentioned, that %put &=res; resolves to N, but put res;returns.`. Waht is the problem?


Solution

  • My guess is that the metadata library is not assigned inside the run_macro session.

    I've had some really weird and inconsistent results with run_macro, I'd avoid it where possible - try dosubl instead. The following code works:

    %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;