BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,
Using Proc Tabulate step, I am able to display the three variables listings:

Say Row 1 that had some values in year1, year 2 etc

Proc tabulate which I am using now displays Totals to the end for year 1, year 2 etc. I need the total for the rows across totalling in all the years. For Ex:

Year1 Year2 Year3 Total
Row1 20 30 50 100


How to get this Total shown to the end in Row1?

thanks,
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
The universal CLASS variable ALL is what you want to use. The placement of ALL on the TABLE statement (in the row dimension or the column dimension or in both dimensions) will determine where the summary line (the ALL line) appears.

Consider this example code (submit the code and review the results from each separate PROC TABULATE step):
[pre]
ods html file='c:\temp\tab_all.html' style=sasweb;

proc tabulate data=sashelp.prdsale f=comma12.;
title 'Using All Both Dimensions';
class year prodtype;
var actual;
table prodtype all,
year*actual*sum all*actual*sum;
keylabel sum=' '
all='Total';
run;

proc tabulate data=sashelp.prdsale f=comma12.;
title 'Using All Row Dimension Only';
class year prodtype;
var actual;
table prodtype all,
year*actual*sum;
keylabel sum=' '
all='Total';
run;

proc tabulate data=sashelp.prdsale f=comma12.;
title 'Using All Column Dimension Only';
class year prodtype;
var actual;
table prodtype,
year*actual*sum all*actual*sum;
keylabel sum=' '
all='Total';
run;

ods html close;

[/pre]

This first TABLE statement has the ALL in both dimensions, row and column:
[pre]
table prodtype all,
year*actual*sum all*actual*sum;
[/pre]
PRODTYPE will go down the rows and the TOTAL of ALL PRODTYPES will be the last row. Then the SUM of the ACTUAL variable values will be under each YEAR in the column dimension. Finally, the SUM of all the YEAR values for ACTUAL (all*actual*sum) will be the last column to the right of the table.

Then for a TOTAL in just the ROW dimension (at the bottom of all the rows), I would have only:
[pre]
table prodtype all,
year*actual*sum;
[/pre]

And for a TOTAL in just the COLUMN dimension (to the right of all the years), I would have only:
[pre]
table prodtype,
year*actual*sum all*actual*sum;
[/pre]

For more help using ALL with PROC TABULATE, you might consider contacting Tech Support.

cynthia
deleted_user
Not applicable
Thanks Cynthia,
That worked exactly what I needed.

But I have two variables in VAR list. I was trying two different ways. But it throws error: " There are multiple analysis variables associated with a single table cell in the following nesting "

proc tabulate data=all;
class NB YEAR ;
VAR AM FEE
;
table NB all,
Year*am*sum all*am*sum,
Year*fee*sum all*fee*sum
;
;

KEYLABEL ALL = 'TOTAL'
SUM = ' '
;



run;

In the above Tabulate Procedure, highlighted one in bold for the fee is not working. I tried giving the 'Fee' variable in the same " Year*am*sum all*am*sum "

But not working? How to get this working.

thanks,
Cynthia_sas
SAS Super FREQ
Hi:
I'm in a class today, so really can't take a close look. Just a couple of idea. The comma (,) is not just punctuation. Right now, you are creating a 3 dimensional table -- one with page, row and column dimensions:
[pre]
table NB all, <---page
Year*am*sum all*am*sum, <--- row
Year*fee*sum all*fee*sum <---col
;
[/pre]

I suspect that you are getting PROC TABULATE error messages that say something like that there are multiple analysis variables associated with a table cell and then you probably see a bunch of variables and asterisks listed.

Every place that you have a comma is an instruction to PROC TABULATE to go to a new dimension. If this is what you intend (a 3-dimensional report) -- then you'll need to move all your statistics to just 1 dimension or the other (move all the SUM into either the ROW or COL dimension).

Otherwise, if this is NOT what you intend, you might consider reading the documentation about table operators or contacting Tech Support for more help.

cynthia
deleted_user
Not applicable
Cyndy,
That helped me.

I replaces the earlier second variable in "Table" with below and report looks good.

(year all)*(am fee)


thanks,

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3639 views
  • 0 likes
  • 2 in conversation