I'd like to create a function that uses hash. The table that is being hashed has 3 columns: Age, Sex, a. I'd like to use a macro in the following way:
Define macro before data step:
%macro hashfind(age, sex) ; rc=tab.find(key: &age, key: &sex ); %LET p=a ; %PUT p; %mend;
Open data step, Define hash as following:
if _n_=1 then do; declare hash tab(); rc=tab.definekey('Age'); rc=tab.definekey('Sex'); rc=tab.definedata('a'); rc=tab.definedone(); do until (eof1); set work.tab end=eof1; rc=tab.add(); put rc; end; end;
Use the macro in data step in the following way:
abc=%hashfind(30, 'M') ;
this way the "abc" value is always equal 1. That's not correct with the table. However after I execute the macro and assign this value outside of macro abc=a which is correct value.
To sum it up: what can I do to use whole hash inside macro? (I will extend the macro in the future so it's a necessity.)
Or: Does anyone know how to define a function, that uses hashes in the way I'd like? Using PROC FCMP is not an option, because hashing in PROC FCMP defined functions is not available in SAS 7.1 which I'm using.