proc fcmp
functions allow passing hash objects as parameters. The documentation is a little vague and it doesn't mention whether or not this ability is restricted to calls from other fcmp
functions or if it's allowed from a data step call as well.
I'm trying to define a hash in a data step and then pass that hash by reference to an fcmp
function. When I try the below code however, it's giving me: NOTE: Invalid type conversion
and I'm not sure where I'm going wrong (or if this is even possible).
option cmplib=work.funcs;
proc fcmp outlib=work.funcs.funcs;
function test(h hash);
return (0);
endsub;
run;
data _null_;
format pos best.;
if _n_ eq 1 then do;
declare hash h();
rc = h.definekey('pos');
rc = h.definedone();
call missing (pos);
end;
xx = test2(h);
put _all_;
run;
The reason I am trying to do this is because I would like to eventually have several functions that I can pass the same hash table to as a parameter.
I don't believe this is possible from data step (be good to see that documentation link).
However - you CAN create a hash table within an fcmp function (or subroutine), and it will remain there for every subsequent call, until the end of the data step.
If you need to retain the state of that hash table across different fcmp function calls, then create a generic subroutine to contain the hash table, and call that subroutine from your different function calls.
Note that the implementation of hash tables within fcmp is limited (eg no attributes such as 'ordered' and you can't export them to datasets).