I have a table looks like this:
And I want to use Proc tabulate to create a tabular report like this:
What should be the correct way to do this?
Hi:
I think your issue is defining too many of your variables as being a CLASS (category or grouping) usage, when it seems to me that GROUPX, RESPONDENT, CLASS_A, CLASS_B, and CLASS_C should all be ANALYSIS variables in a VAR statement, not a CLASS statement. Then your next issue is using the * (asterisk) operator, which nests or crosses items and instead, you want them to merely be "stacked" or concatenated -- for each variable (GROUPX, RESPONDENT, etc) to be a separate row in the report table.
Something more like the code below, that produced this output:
Cynthia
data my_data;
infile datalines dlm=',' dsd;
input resp_id $ groupx respondent class_A class_B class_C;
** adjust these 3 so that can use simple PERCENT format (which multiplies by 100);
class_A = class_A / 100;
class_B = class_B / 100;
class_C = class_C / 100;
return;
datalines;
P001,5,10,100,.,.
P002,4,13,61.53846,23.07692,15.38462
P003,5,13,38.46154,53.84615,7.692308
P004,7,20,60,25,15
;
run;
ods html file='c:\temp\diff_tabulate.html' style=pearl;
proc tabulate data=my_data f=comma6.0;
class resp_id/ missing style=Header{background=white};
var class_a class_b class_c respondent groupx / style=Header{background=white};
table groupx respondent class_a*f=percent9.2 class_b*f=percent9.2 class_c*f=percent9.2,
resp_id / row=float misstext='-';
title 'try me';
keylabel sum=' ';
label groupx = '# Group X'
respondent = '# Respondent'
class_a = '% Resp Class A'
class_b = '% Resp Class B'
class_c = '% Resp Class C';
run;
ods html close;
Hi:
I think your issue is defining too many of your variables as being a CLASS (category or grouping) usage, when it seems to me that GROUPX, RESPONDENT, CLASS_A, CLASS_B, and CLASS_C should all be ANALYSIS variables in a VAR statement, not a CLASS statement. Then your next issue is using the * (asterisk) operator, which nests or crosses items and instead, you want them to merely be "stacked" or concatenated -- for each variable (GROUPX, RESPONDENT, etc) to be a separate row in the report table.
Something more like the code below, that produced this output:
Cynthia
data my_data;
infile datalines dlm=',' dsd;
input resp_id $ groupx respondent class_A class_B class_C;
** adjust these 3 so that can use simple PERCENT format (which multiplies by 100);
class_A = class_A / 100;
class_B = class_B / 100;
class_C = class_C / 100;
return;
datalines;
P001,5,10,100,.,.
P002,4,13,61.53846,23.07692,15.38462
P003,5,13,38.46154,53.84615,7.692308
P004,7,20,60,25,15
;
run;
ods html file='c:\temp\diff_tabulate.html' style=pearl;
proc tabulate data=my_data f=comma6.0;
class resp_id/ missing style=Header{background=white};
var class_a class_b class_c respondent groupx / style=Header{background=white};
table groupx respondent class_a*f=percent9.2 class_b*f=percent9.2 class_c*f=percent9.2,
resp_id / row=float misstext='-';
title 'try me';
keylabel sum=' ';
label groupx = '# Group X'
respondent = '# Respondent'
class_a = '% Resp Class A'
class_b = '% Resp Class B'
class_c = '% Resp Class C';
run;
ods html close;
Thank you very much for you help!
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.