Help using Base SAS procedures

How to use proc tabulate to create table with multiple different rows?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

How to use proc tabulate to create table with multiple different rows?

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?


Accepted Solutions
Solution
‎06-27-2015 09:52 PM
SAS Super FREQ
Posts: 8,743

Re: How to use proc tabulate to create table with multiple different rows?

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


All Replies
Solution
‎06-27-2015 09:52 PM
SAS Super FREQ
Posts: 8,743

Re: How to use proc tabulate to create table with multiple different rows?

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;

Occasional Contributor
Posts: 8

Re: How to use proc tabulate to create table with multiple different rows?

Thank you very much for you help!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 232 views
  • 0 likes
  • 2 in conversation