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!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 897 views
  • 0 likes
  • 2 in conversation