Hi,
Is there a SAS function to calculate the number of digits in a numeric field ?
For example: I have a roll number numeric field. I want the count to show as below
ROLL NUMBER COUNT
1234567 7
12345 5
1212 4
Thank you
If you're working with integers only, then try the approach in the blog post Compute the number of digits in an integer by @Rick_SAS.
data have;
input ROLLNUMBER;
count = ceil(log10(ROLLNUMBER + 1));
datalines;
1234567
12345
1212
;
Result:
ROLLNUMBER count 1234567 7 12345 5 1212 4
If you're working with integers only, then try the approach in the blog post Compute the number of digits in an integer by @Rick_SAS.
data have;
input ROLLNUMBER;
count = ceil(log10(ROLLNUMBER + 1));
datalines;
1234567
12345
1212
;
Result:
ROLLNUMBER count 1234567 7 12345 5 1212 4
thank you @PeterClemmensen . That is exactly what I needed.
If you know the value is an integer (a whole number) then you could just convert it to a string and count the number of digits.
digits=length(cats(whole_number));
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: