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:
Want:
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?
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;
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;
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.
Ready to level-up your skills? Choose your own adventure.