BookmarkSubscribeRSS Feed
sasgorilla
Pyrite | Level 9

All,

 

I have made a table that displays multiple levels for several variables. For each variable, there is a % column that displays the relative percentage for each level. This is all good, however, I am wondering if there is a way to make only my Total row to reflect rowpctsum and not colpctsum.

Have: 

sasgorilla_0-1770058377926.png

Want: 

sasgorilla_1-1770058426247.png


Code I am using is below: 

 

proc tabulate data=testtable noseps order=data;
	options nodate nonumber;
	Title Justify=Left
     "Test table";
	class  a b c d e f g /preloadfmt;
	classlev  a b c d e f /s=[JUST=R];
	var pyears;
	table a b c d e f ALL="TOTAL" ,  
			ALL="Total" *(pyears=" "*(sum="py"*f=8.0 colpctsum="%"*f=8.1)) g="exposure"*(pyears=" "*(sum="py"*f=8.0 colpctsum="%"*f=8.1)) ;
	keylabel sum=' ';
run;


Is this possible to do? 

 

 

2 REPLIES 2
Kathryn_SAS
SAS Employee

To get the desired percentages, you would have to restructure the table so that the sum and percent are stacked in the row dimension, rather than as columns in the column dimension. Here is an example.

proc tabulate data=testtable order=data;
class  a b c d e f g /preloadfmt;
classlev  a b c d e f /s=[JUST=R];
var pyears;
*table a b c d e f ALL="TOTAL" ,
        ALL="Total" *(pyears=" "*(sum="py"*f=8.0 colpctsum="%"*f=8.1))
 g="exposure"*(pyears=" "*(sum="py"*f=8.0 colpctsum="%"*f=8.1)) ;
keylabel sum=' ';
table (a b)*pyears=' '*(sum="py"*f=8.0 colpctsum="%"*f=8.1)
 All='Total'*pyears=' '*(sum="py"*f=8.0 rowpctsum="%"*f=8.1),
 All='Total' g='exposure' / row=float;
run;
Ksharp
Super User

You want this ?

 

proc tabulate data=sashelp.heart(obs=1000);
class status bp_status sex;
var ageatstart;
table status bp_status all='Total',
 ALL="Total" *ageatstart=" "*(sum="py"*f=8.0 colpctsum="%"*f=8.1) 
 sex="exposure"*ageatstart=" "*(sum="py"*f=8.0 pctsum<status bp_status sex>="%"*f=8.1) ;
 keylabel sum=' ';
run;

Ksharp_0-1770104406879.png

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 202 views
  • 0 likes
  • 3 in conversation