BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TasteMyBiceps
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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:

tabulate_table.png

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;

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

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:

tabulate_table.png

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;

TasteMyBiceps
Calcite | Level 5

Thank you very much for you help!

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!

What is Bayesian Analysis?

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.

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
  • 2 replies
  • 804 views
  • 0 likes
  • 2 in conversation