%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);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.