/***************************************************************************************************************** SAS file name: proc_fcmp_format.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate how to use function logic in PROC FORMAT with PROC FCMP. Author: Peter Clemmensen Creation Date: 01Jul2019 This program supports the blog post "Pass Function Logic to PROC FORMAT in SAS" on SASnrd.com *****************************************************************************************************************/ proc fcmp outlib=work.functions.fun; function Teen(Age) $; length r $12; if 13 le Age le 19 then r='Teenager'; else r='Not Teenager'; return (r); endsub; run; options cmplib=work.functions; proc format; value TeenAger (default=12) other=[Teen()]; run; data class; set sashelp.class; format Age TeenAger.; run; /* A real life example */ proc fcmp outlib=work.functions.fun; function fnc(num) $; if num=int(num) then r=scan(strip(put(num, commax32.10)), 1, ','); else r=tranwrd(strip(tranwrd(strip(put(num, commax32.10)), "0", " "))," ","0"); return (r); endsub; run; options cmplib=work.functions; proc format; value fmt (default=32) other=[fnc()]; run; data test; x=1234.567;output; x=-1234.00;output; x=1234567 ;output; x=1.23 ;output; format x fmt.; run;