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
- /
- SAS Procedures
- /
- Proc Tabulate: Summary of two different rows

- 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

02-06-2013 10:03 AM

Hello,

I'm trying to do a table with proc tabulate where I'm calculating different totals.

At the moment it looks like the following:

With the following code:

PROC TABULATE

DATA=my.data;

VAR SUM_A_KOST_J SUM_A_HB SUM_A_TB SUM_AUSGABEN_OEFFENTLICH;

CLASS PERH_J / ORDER=UNFORMATTED MISSING;

CLASS KAT1AG / ORDER=UNFORMATTED MISSING;

TABLE /* Zeilendimension */

PERH_J,

/* Spaltendimension */

(ALL='SUBTOTAL_1')*SUM_AUSGABEN_OEFFENTLICH

KAT1AG*SUM_AUSGABEN_OEFFENTLICH

(ALL='SUBTOTAL_2')*SUM_A_KOST_J

KAT1AG*SUM_A_KOST_J

;

;

RUN;

Now I would like to add a row which calculates me the TOTAL of SUBTOTAL_1 and SUBTOTAL_2.

Is this possible? And how can I do this?

Thanks for your help.

Accepted Solutions

Solution

02-06-2013
10:58 AM

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

02-06-2013 10:58 AM

One of the principles of using PROC TABULATE is that any one cell in the report can be based on just a single analysis variable. So the answer is no, you can't do that using your current structure to the data. However, if you were to preprocess your data and create a new analysis variable then it would be possible:

newvar = sum_ausgaben_offentlich + sum_a_kost_j;

Then add NEWVAR to the VAR statement, and the rest would be fairly easy.

Good luck.

All Replies

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

02-06-2013 10:44 AM

If you change Perh_J, to

Perh_J All='Total'

You will get the sum of 2011 and 2012 for all columns. If want **only** Subtotal21 and Subtotal_2 summed then you're likely outside of proc tabulate.

Solution

02-06-2013
10:58 AM

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

02-06-2013 10:58 AM

One of the principles of using PROC TABULATE is that any one cell in the report can be based on just a single analysis variable. So the answer is no, you can't do that using your current structure to the data. However, if you were to preprocess your data and create a new analysis variable then it would be possible:

newvar = sum_ausgaben_offentlich + sum_a_kost_j;

Then add NEWVAR to the VAR statement, and the rest would be fairly easy.

Good luck.

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

02-08-2013 09:35 AM

Thank you very much for the answers.

Unfortunately the structure of the data isn't so easy as it looks like while creating the proc tabulate.

Well, I have to search for a possible preprocess.

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

02-08-2013 12:34 PM

In that case, here's a similar approach that might work. Instead of printing the report with PROC TABULATE, create an output data set instead. Then modify the output data set and use that as the input to a second PROC TABULATE to actually print the report.