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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: