Dear,
I need find maximal decimal digits in value for each var. Please suggest. Thank you
In my data below the output needed;
var maxdecimal
a 3
b 1
c 6
d 0
data have;
input var $ value;
datalines;
a 100.01
a 110.003
a 100
b 1.1
b 2
c 5.000002
c 6.01
c 4
d 2
d 5
;
data have;
input var $ value;
datalines;
a 100.01
a 110.003
a 100
b 1.1
b 2
c 5.000002
c 6.01
c 4
d 2
d 5
;
data want;
do until(last.var);
set have;
by var;
max_dec=max_dec <> lengthn(scan(cats(value),2,'.'));
end;
drop value;
run;
You must trust SAS number to string conversion algorithms (which are pretty good) for this to work:
proc sql;
select
var,
max(lengthn(scan(put(value, best32.), 2, "."))) as maxDecimal
from have
group by var;
quit;
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.