Calcite | Level 5

## How to sum specific rows in dataset

I have a dataset like below:

Finality        Balance

a                    10

b                    15

c                     8

d                    30

First, I would like to sum the finalities 'a' and 'd', resulting in 40. Then, this result must be divided by the sum of all rows. Is there a way to do so, since I have to do the same thing for b and c, separately (dividing 'b' by the sum of all rows and so on)?

The final table I need is something like:

Finality        Result

e (a+d)         0.6349

b                  0.2381

c                  0.1270

I don't know if I made myself clear. Sorry if don't.

4 REPLIES 4
Super User

## Re: How to sum specific rows in dataset

If you only have four rows then do this by hand.

If you have lots more rows then more complete example data and the RULES, not the rows, but how do we know that A and D rows are the ones to add, as well as the B and C? There is not immediately obvious surface logic that says these specific pairs should be added.

Tourmaline | Level 20

## Re: How to sum specific rows in dataset

"If you only have four rows then do this by hand."---

Sir @ballardw  Not really participating in this thread or much today as I am not feeling well, but that comment made me laugh. I didn't know you had a sense of humor. Nice to notice that. 🙂

Super User

## Re: How to sum specific rows in dataset

Hope feel better soon.

Some have considered my humor odd at times.

In this case I am actually moderately serious with the number of missing elements of the problem description.

Super User

## Re: How to sum specific rows in dataset

Use a custom format, along with PROC FREQ.

``````proc format;
value final_fmt
'a', 'd' = ' e (a+d)'
other = [\$8.];
run;

proc freq data=have;
table finality / out=want outpct;
format finality final_fmt.;
run;``````

@-a_a-rlis wrote:

I have a dataset like below:

Finality        Balance

a                    10

b                    15

c                     8

d                    30

First, I would like to sum the finalities 'a' and 'd', resulting in 40. Then, this result must be divided by the sum of all rows. Is there a way to do so, since I have to do the same thing for b and c, separately (dividing 'b' by the sum of all rows and so on)?

The final table I need is something like:

Finality        Result

e (a+d)         0.6349

b                  0.2381

c                  0.1270

I don't know if I made myself clear. Sorry if don't.

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