%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);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.