<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PROC TABULATE is smarter than I am: Categories and subtotals in column (class?) variable in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678259#M32578</link>
    <description>&lt;P&gt;If you want a variable to be a grouping variable it goes on a CLASS statement, not VAR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So maybe&lt;/P&gt;
&lt;PRE&gt;proc tabulate data = gender_by_source_and_entity;
	class entity gender;
	class source;
	table entity * source, gender * (N rowpctn)&lt;BR /&gt;        / misstext='0';
run;&lt;/PRE&gt;
&lt;P&gt;To get 0 for things not appearing in the data you can use the table misstext option as shown&lt;/P&gt;</description>
    <pubDate>Thu, 20 Aug 2020 20:14:23 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-08-20T20:14:23Z</dc:date>
    <item>
      <title>PROC TABULATE is smarter than I am: Categories and subtotals in column (class?) variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678237#M32576</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have data that looks like this (actually 7000 records, multiple entities, 3 sources):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gender_by_source_and_entity;
   input entity source gender;
datalines;
1 1 1
1 1 1
1 1 2
1 2 1
1 2 1
1 2 2
2 1 1
2 1 1
2 1 1
2 1 2
2 2 2
2 2 2
3 1 1
3 1 1
3 2 1
3 2 2
3 2 2
3 2 2
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to create a table that shows counts of gender by source by entity, with subtotals, like so:&lt;/P&gt;
&lt;PRE&gt;		gender count	
		1	2
Entity	source		
			
1	1	2	1
	2	2	1
	Sub	4	2
2	1	3	1
	2	0	2
	Sub	3	3
3	1	2	0
	2	1	3
	Sub	3	3
&lt;/PRE&gt;
&lt;P&gt;I really actually want percents in there in addition to raw counts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I THINK Proc TABULATE is the way to do this, but it is smarter than I am.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data = gender_by_source_and_entity;
	class entity gender;
	var source;
	table entity * source, gender * (N rowpctn);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;gets me close but not there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;		gender			
		1		2	
		N	RowPctN	N	RowPctN
entity		4	66.67	2	33.33
1	source				
2	source	3	50	3	50
3	source	3	50	3	50
&lt;/PRE&gt;
&lt;P&gt;specifically it doesn't break the entities down into their multiple sources.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I get a suggestion, some guidance, or a bone?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HB&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 19:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678237#M32576</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2020-08-20T19:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE is smarter than I am: Categories and subtotals in column (class?) variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678258#M32577</link>
      <description>&lt;P&gt;PROC TABULATE is smarter that all of us.&amp;nbsp; But here's code that does what I think you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gender_by_source_and_entity;
   input entity source gender;
datalines;
1 1 1
1 1 1
1 1 2
1 2 1
1 2 1
1 2 2
2 1 1
2 1 1
2 1 1
2 1 2
2 2 2
2 2 2
3 1 1
3 1 1
3 2 1
3 2 2
3 2 2
3 2 2
;
run;
proc tabulate data=_last_ noseps;
  class entity source gender;

  tables entity=' '*(source=' ' all='Sub'), gender*(N='count'*f=comma6. rowpctn='Pct'*f=6.2)
   /box='Entity   Source ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After the comma in the tables statement is the description of the columns, which are counts and percentages nested within gender: &lt;EM&gt;&lt;STRONG&gt;gender*(N rowpctn)&lt;/STRONG&gt;&lt;/EM&gt;.&amp;nbsp;&amp;nbsp; The rest of the after-comma clause is just controlling labels and formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before the comma is the row descriptino, in which you can&amp;nbsp;&amp;nbsp;&amp;nbsp; (source and total-over-sources) nested within entity:&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt; entity*(source all)&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 20:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678258#M32577</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-20T20:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE is smarter than I am: Categories and subtotals in column (class?) variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678259#M32578</link>
      <description>&lt;P&gt;If you want a variable to be a grouping variable it goes on a CLASS statement, not VAR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So maybe&lt;/P&gt;
&lt;PRE&gt;proc tabulate data = gender_by_source_and_entity;
	class entity gender;
	class source;
	table entity * source, gender * (N rowpctn)&lt;BR /&gt;        / misstext='0';
run;&lt;/PRE&gt;
&lt;P&gt;To get 0 for things not appearing in the data you can use the table misstext option as shown&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 20:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678259#M32578</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-20T20:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE is smarter than I am: Categories and subtotals in column (class?) variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678272#M32579</link>
      <description>&lt;P&gt;Thank you, thank you, thank you.&amp;nbsp; I wasn't getting the "all three variables in the class statement" part.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Props to BallardW for the /misstext = '0' thing.&amp;nbsp; Useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 21:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-TABULATE-is-smarter-than-I-am-Categories-and-subtotals-in/m-p/678272#M32579</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2020-08-20T21:21:02Z</dc:date>
    </item>
  </channel>
</rss>

