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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.