This is similar and a basic change from the previous example:
DATA example;
do respondent=1 to 10;
q1_1 = rand('integer',2)-1;
q1_2 = rand('integer',2)-1;
q1_3 = rand('integer',2)-1;
q1_4 = rand('integer',2)-1;
q1_5 = rand('integer',2)-1;
q1sum = sum(of q1_:);
sex = rand('integer',2)-1;
output;
end;
run;
proc tabulate data=example;
var q1_: q1sum;
class sex;
table q1_:,
sex* (n='Respondents' sum="Number of selected"*f=best5.
mean="Percent selected"*f=percent8.1 )
/ style=[pretext='Percentages of respondents']
;
table (q1_:) q1sum ,
sex* ( pctsum<q1sum>='Percent of all selected'
sum='Number'*f=best5. )
/
;
label q1sum='All Q1 responses';
run;
So if you have a sex / gender / whatever variable to make subgroups that is a CLASS variable.
You could suppress the variable name/ default label by using: sex=' '* (<statistics).
If you MUST have the N in the column heading that is a bit more work and may involve macro coding.
If the class variables do not have the text you want to see in the table then create a format to create the desired text. Formats can also create report groups just by applying a different format.
There is a paper at https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-TABLEN/ta-p/634030
that has some other approaches to making tables that may help.
... View more