BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amanjot_42
Fluorite | Level 6

Hi guys,

 

Can you please help me in adding up two numbers which are separated by a comma:

 

Year dividend

2010 10

2011 11,15

2012 16

2013 20

 

In the example, I want to take the total of 11 and 15 as my final amount for the year 2011.

 

Regards,

Amanjot

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

So you have a string containing numbers, right? See this:

data have;
input year dividend $;
datalines;
2010 10
2011 11,15
2012 16
2013 20
;

data want;
set have;
do i = 1 to countw(dividend,',');
  div_num = sum(div_num,input(scan(dividend,i,','),best32.));
end;
drop i;
run;

proc print data=want noobs;
run;

Result:

year    dividend    div_num

2010     10            10  
2011     11,15         26  
2012     16            16  
2013     20            20  

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

So you have a string containing numbers, right? See this:

data have;
input year dividend $;
datalines;
2010 10
2011 11,15
2012 16
2013 20
;

data want;
set have;
do i = 1 to countw(dividend,',');
  div_num = sum(div_num,input(scan(dividend,i,','),best32.));
end;
drop i;
run;

proc print data=want noobs;
run;

Result:

year    dividend    div_num

2010     10            10  
2011     11,15         26  
2012     16            16  
2013     20            20  
amanjot_42
Fluorite | Level 6

Thanks, that was so quick!

 

It worked well

 

cheers

amanjot_42
Fluorite | Level 6
Thanks, that was so quick!