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
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Error in Summary Function

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
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-12-2017 02:30 PM

Hello,

Thanks for checking!

My goal is to get the sum of count of 2 variables (num_id1 and num_id2) in separate column as 'IDCounts'.

I am getting error prior computing that new column.

My output should be like this:

num_id1 num_id 2 IDcounts(Newcolumn)

2 4 6

4 4 8

proc sql;

create table test.number

as select name, count(num_id1) as count1,

count(num_id2) as count2,

sum(count(cin_id1)) as grand_sum, (Tried this way, still getting error)

sum(count1) as grand_sum1

from test.data

run;

ERROR: The SUM summary function requires a numeric argument.

ERROR: Summary functions nested in this way are not supported.

ERROR: The following columns were not found in the contributing tables: count1.

Accepted Solutions

Solution

07-12-2017
02:45 PM

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

Posted in reply to Kalai2008

07-12-2017 02:42 PM - edited 07-12-2017 02:43 PM

Looks like you might be confusing the SQL aggregate function SUM() with the SAS function SUM(,).

The first one takes one argument and calculates the sum across observations. The second takes two or more arguments and sums the values in the same observation.

```
proc sql;
create table test.number as
select name
, count(num_id1) as count1
, count(num_id2) as count2
, sum(calculated count1, calculated count2) as grand_sum
from test.data
group by name
order by name
;
quit;
```

All Replies

Solution

07-12-2017
02:45 PM

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

Posted in reply to Kalai2008

07-12-2017 02:42 PM - edited 07-12-2017 02:43 PM

Looks like you might be confusing the SQL aggregate function SUM() with the SAS function SUM(,).

The first one takes one argument and calculates the sum across observations. The second takes two or more arguments and sums the values in the same observation.

```
proc sql;
create table test.number as
select name
, count(num_id1) as count1
, count(num_id2) as count2
, sum(calculated count1, calculated count2) as grand_sum
from test.data
group by name
order by name
;
quit;
```

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

07-12-2017 02:45 PM

Thank you! It worked..