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
- /
- Programming
- /
- Summing values of a variable in proc tabulate

Topic Options

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

02-06-2018 03:50 PM - edited 02-06-2018 03:51 PM

Hello,

I have a variable x which is a binary variable (may have missing values). A sum function in proc means would give me value of 60. (yes=60, no or missing=40).

When I use the sum function in proc tabulate with a class statement, I get the number of obs (n=100) instead of the sum (60).

Here is the code I am using:

proc tabulate data = have;

var x;

class y;

table x*sum, y;

run;

Any help would be appreciated.

Thanks

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

Posted in reply to div44

02-06-2018 04:19 PM

Show your output or provide the data used in the form of a data step, preferably both.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

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

Posted in reply to div44

02-06-2018 05:32 PM

Your code works fine for me. You have some other issue.

If you run the following the results should be the following. I added in the Count/N so you can see the difference and the PROC MEANS to show that the results are correct.

y | |||
---|---|---|---|

0 | 1 | ||

x | Sum | 20.00 | 12.00 |

x | N | 56 | 44 |

```
data have;
call streaminit(12345);
do i=1 to 100;
x=rand('bernoulli', 0.4);
y=rand('bernoulli', 0.5);
output;
end;
run;
proc tabulate data=have;
var x;
class y;
table x*sum x*n, y;
run;
proc means data=have n sum nway;
var x;
class y;
run;
```

div44 wrote:

Hello,

I have a variable x which is a binary variable (may have missing values). A sum function in proc means would give me value of 60. (yes=60, no or missing=40).

When I use the sum function in proc tabulate with a class statement, I get the number of obs (n=100) instead of the sum (60).

Here is the code I am using:

proc tabulate data = have;

var x;

class y;

table x*sum, y;

run;

Any help would be appreciated.

Thanks