turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- BI
- /
- Enterprise Guide
- /
- How to sum along row?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-17-2006 07:50 PM

Hi,

Is there a way to add a column that would provide sum of values of columns (say there are 200 columns) along the row? For example, to add a new column of 'Sum' below?

Example

A B C D E Sum

2 2 5 1 0 10

..

..

Is there a way to add a column that would provide sum of values of columns (say there are 200 columns) along the row? For example, to add a new column of 'Sum' below?

Example

A B C D E Sum

2 2 5 1 0 10

..

..

Accepted Solutions

Solution

04-26-2017
08:20 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-18-2006 09:16 AM - last edited on 04-26-2017 08:20 AM by ChrisHemedinger

First suggestion, using DATA step and the SUM function:

```
data test;
infile cards;
input A1 A2 A3 A4 A5;
cards;
2 2 5 1 0
;
run;
data sums;
set test;
/* method 1: array of all numerics */
array n {*} _numeric_;
sum_allnum=sum(of n[*]);
/*method 2: variable range in data set */
sum_range=sum(of a1-a5);
run;
```

If using EG and you want this in the Query Builder (SQL), you need to add a new computed column.

Its formula is SUM(var1, var2, var3, ...)

(you name each and every variable to sum, and separate them with commas).

Unfortunately the previous shortcut SUM(OF var1-var10) only works in datasteps and EG does not code them for you.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-17-2006 09:54 PM

data test;

infile cards;

input A1 A2 A3 A4 A5;

cards;

2 2 5 1 0

;

run;

data test2;

set test;

sum = sum (of a1-a5);

run;

infile cards;

input A1 A2 A3 A4 A5;

cards;

2 2 5 1 0

;

run;

data test2;

set test;

sum = sum (of a1-a5);

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-17-2006 11:02 PM

Hi Dan,

Could pl. suggest it in using Enterprise Guide? (Not in the programming code,I don't understand the codes at this moment). Thanks

Regards,

Could pl. suggest it in using Enterprise Guide? (Not in the programming code,I don't understand the codes at this moment). Thanks

Regards,

Solution

04-26-2017
08:20 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-18-2006 09:16 AM - last edited on 04-26-2017 08:20 AM by ChrisHemedinger

First suggestion, using DATA step and the SUM function:

```
data test;
infile cards;
input A1 A2 A3 A4 A5;
cards;
2 2 5 1 0
;
run;
data sums;
set test;
/* method 1: array of all numerics */
array n {*} _numeric_;
sum_allnum=sum(of n[*]);
/*method 2: variable range in data set */
sum_range=sum(of a1-a5);
run;
```

If using EG and you want this in the Query Builder (SQL), you need to add a new computed column.

Its formula is SUM(var1, var2, var3, ...)

(you name each and every variable to sum, and separate them with commas).

Unfortunately the previous shortcut SUM(OF var1-var10) only works in datasteps and EG does not code them for you.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-29-2015 12:43 AM

hey can you please tell me how to sum all the columns with different names....i.e. not a1,a2,a3,a4....but a,b,c,d,....

Thanks

Krishan Avtar Singh

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-03-2016 02:03 PM

Use above formula but replace var1,var2,etc. with column name