%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);
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.