%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);
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.