/* test data */
data one;
infile cards truncover;
input from :$20.;
cards;
0
0.006789123
1
53
100
12345
a234
234x
dunkin
-0.1
;
run;
/* special formatting */
proc fcmp outlib=work.star.bucks;
function tall(n) $;
return (if 0<=n & n<1
then left(putn(round(n, .0001), "8.4"))
else " ");
endsub;
function grande(n) $;
return (if 1<=n & n<100
then left(putn(n, "8."))
else " ");
endsub;
function venti(n) $;
return (if 100<=n & n<=constant('big')
then left(putn(round(n,100), "best8."))
else " ");
endsub;
function coffee(s $) $;
length n 8 t $20 g $20 v $20;
if verify(s, "0123456789. ") then return(left(s));
n = inputn(s, "best20.");
t = tall(n);
g = grande(n);
v = venti(n);
return (coalescec(t,g,v));
endsub;
quit;
%let cmplib = %sysfunc(getoption(cmplib));
options cmplib = (work.star &cmplib);
data two;
set one;
length to $20;
to = coffee(from);
run;
options cmplib = (&cmplib);
/* check */
proc print data=two;
run;
/* on lst
Obs from to
1 0 0.0000
2 0.006789123 0.0068
3 1 1
4 53 53
5 100 100
6 12345 12300
7 a234 a234
8 234x 234x
9 dunkin dunkin
10 -0.1 -0.1
*/
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.