I am trying to build a function in SAS that will concatenate and number and a percent value and return a character string result like X (Y%). Here is my code:
proc fcmp outlib = func.funcs.mwfunc;
/* Create function to return a string in the style X (Y%) */
function npct(n, pct) $ 25;
length concatp $25 n pct 8;
n_f = n;
pct_f = pct;
concatp = cat(n_f, " (", round(pct_f*100,0.01),"%",")");
return(concatp);
endsub;
quit;
/* Test function */
data _null_;
x = npct(5,0.10);
put x;
run;When I test this function, it produces the following result:
5 (10=)
Instead of 5 (10%).
How do I correct this? Is there some kind of masking function I need?
Thanks for the help. I am working in SAS 9.4.
Just use single quotes.
'%'
in your function definition.
Thank you, that was way easier than I anticipated!
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.