%macro maxOf;
%global var data r;
%let var = %sysfunc(dequote(&var));
%let data = %sysfunc(dequote(&data));
proc sql noprint;
select left(putn(max(&var),"best32.")) into :r
from &data;
quit;
%mend maxOf;
proc fcmp outlib=work.func.test;
function maxOf(var $, data $);
rc = run_macro('maxOf', var, data, r);
if rc = 0 then return(r);
else return(.);
endsub;
quit;
%let cmplib = %sysfunc(getoption(cmplib));
options cmplib = (&cmplib work.func);
data var;
do name = "weight", "height", "age";
output;
end;
run;
data max;
set var;
maxVal = maxOf(name, "sashelp.class");
run;
/* check */
proc print data=max;
run;
/* on lst
max
Obs name Val
1 weight 150
2 height 72
3 age 16
*/
options cmplib = (&cmplib);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.