BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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
;
2 REPLIES 2
novinosrin
Tourmaline | Level 20

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;
PGStats
Opal | Level 21

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;
PG

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1519 views
  • 2 likes
  • 3 in conversation