Sum digits of a string

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Sum digits of a string

Hello Smiley Happy

 

My question is if I have a string such as '6423BS24F', how do I write a step that sums only the numbers of the string?

 

THANK YOU!!!!!


Accepted Solutions
Solution
‎04-11-2016 08:53 PM
Contributor
Posts: 21

Re: Sum digits of a string

Hello Astounding,

 

The code actually works!! You are the best Smiley Happy 

 

Thank you!!!

View solution in original post


All Replies
Super User
Posts: 5,082

Re: Sum digits of a string

data want;

string = '6423BS24F';

total = 0;

do i=1 to length(string);

   total + input(substr(string, i, 1), ?? 1.);

end;

run;

Solution
‎04-11-2016 08:53 PM
Contributor
Posts: 21

Re: Sum digits of a string

Hello Astounding,

 

The code actually works!! You are the best Smiley Happy 

 

Thank you!!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 417 views
  • 4 likes
  • 2 in conversation