/* 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
*/
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.