<?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 proc tabulate by two column factors / grouped within in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-tabulate-by-two-column-factors-grouped-within/m-p/485608#M71870</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two questions.&lt;/P&gt;
&lt;P&gt;1. Image shows Wanted Output vs Current Output. What am I doing wrong in the code below?I'd like to show Medicaid 1 vs 0 given the age group.&lt;/P&gt;
&lt;P&gt;2. How to switch the order of&amp;nbsp;Medicaid 0 vs 1 to Medicaid 1 vs 0 in the output table? &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions appreciated. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=mydata order=internal; 
var id;
class medicaid A10 raceth sex vital_status stage1 grade site surgery radiation area area1 birthplace
      type_of_reporting_source year sequence_number  tobacco marital_status_at_dx;
tables 
	(All raceth sex vital_status stage1 grade site surgery radiation area area1 birthplace 
     tobacco marital_status_at_dx type_of_reporting_source year sequence_number), 
	id*(medicaid)*(N colpctn="%"*f=5.1) id*(medicaid*A10)*(colpctn="%"*f=5.1)/nocellmerge;
format...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc tabulate.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22374i96AC406A5156D31F/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc tabulate.png" alt="proc tabulate.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Aug 2018 21:55:43 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2018-08-09T21:55:43Z</dc:date>
    <item>
      <title>proc tabulate by two column factors / grouped within</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-tabulate-by-two-column-factors-grouped-within/m-p/485608#M71870</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two questions.&lt;/P&gt;
&lt;P&gt;1. Image shows Wanted Output vs Current Output. What am I doing wrong in the code below?I'd like to show Medicaid 1 vs 0 given the age group.&lt;/P&gt;
&lt;P&gt;2. How to switch the order of&amp;nbsp;Medicaid 0 vs 1 to Medicaid 1 vs 0 in the output table? &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions appreciated. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=mydata order=internal; 
var id;
class medicaid A10 raceth sex vital_status stage1 grade site surgery radiation area area1 birthplace
      type_of_reporting_source year sequence_number  tobacco marital_status_at_dx;
tables 
	(All raceth sex vital_status stage1 grade site surgery radiation area area1 birthplace 
     tobacco marital_status_at_dx type_of_reporting_source year sequence_number), 
	id*(medicaid)*(N colpctn="%"*f=5.1) id*(medicaid*A10)*(colpctn="%"*f=5.1)/nocellmerge;
format...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc tabulate.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22374i96AC406A5156D31F/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc tabulate.png" alt="proc tabulate.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 21:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-tabulate-by-two-column-factors-grouped-within/m-p/485608#M71870</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-08-09T21:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate by two column factors / grouped within</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-tabulate-by-two-column-factors-grouped-within/m-p/485627#M71876</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two questions.&lt;/P&gt;
&lt;P&gt;1. Image shows Wanted Output vs Current Output. What am I doing wrong in the code below?I'd like to show Medicaid 1 vs 0 given the age group.&lt;/P&gt;
&lt;P&gt;2. How to switch the order of&amp;nbsp;Medicaid 0 vs 1 to Medicaid 1 vs 0 in the output table?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions appreciated. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=mydata order=internal; 
var id;
class medicaid A10 raceth sex vital_status stage1 grade site surgery radiation area area1 birthplace
      type_of_reporting_source year sequence_number  tobacco marital_status_at_dx;
tables 
	(All raceth sex vital_status stage1 grade site surgery radiation area area1 birthplace 
     tobacco marital_status_at_dx type_of_reporting_source year sequence_number), 
	id*(medicaid)*(N colpctn="%"*f=5.1) id*(medicaid*A10)*(colpctn="%"*f=5.1)/nocellmerge;
format...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc tabulate.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22374i96AC406A5156D31F/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc tabulate.png" alt="proc tabulate.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you use the * between variables you are "nesting" the results. When the combination appears in a ROW expression the values are added left to right in the order of the expression. In a column expression they are added top to bottom in order and that is the way the grouping will display.&lt;/P&gt;
&lt;P&gt;So your&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="SAS Monospace" size="2"&gt;id&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;*(medicaid*A10)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;has id on top, then Medicaid, then A10. Then to&amp;nbsp;change the group&amp;nbsp;order of the values&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="SAS Monospace" size="2"&gt;id&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;*(A10* Medicaid)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt; I am afraid that to get exactly what you want is not going to be a simple one step change with your data or Proc Tabulate syntax. You would have to have 7 variables, one for each level of your current A10 and use something like&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Medicaid(A10_1 - A10_7) assuming you created the variables with those names. And getting the correct values and statistic might be interesting. I suspect you might have to summarize all the data and then just use tabulate to display the results.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;You can change the order of appearance of your Medicaid class variable by specifying the option DESCENDING on the CLASS statement. You would likely want to do that only for Medicaid in a separate CLASS statement. You may have multiple class statements to provide different class options for different variables. I would likely use a format so that the meaning of 0 and 1 appears in the table so I don't have to explain it to folks.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;data example;
   do i= 1 to 20;
      x= mod(i,2);
      y= rand('uniform')*100;
      output;
   end;
run;

proc tabulate data=example;
   class x / descending;
   var y;
   table y*mean, 
          x
          /printmiss
   ;
run;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Your () on the row expression label of your table statement does nothing in this case. () are used to indicate a grouping of some sort to nest with one or more other variables and your row is not doing that&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 23:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-tabulate-by-two-column-factors-grouped-within/m-p/485627#M71876</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-09T23:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate by two column factors / grouped within</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-tabulate-by-two-column-factors-grouped-within/m-p/485719#M71885</link>
      <description>&lt;P&gt;This is excellent! This is close to perfect. I'm so happy and everything you said here make sense once you go through them. Totally doable but I couldn't figure. So below is the code reflected on your suggestions which solved the problem as in the new image.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc tab solved.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22377iF101AAE1E46CEE18/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc tab solved.png" alt="proc tab solved.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BRAOVO. Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc tabulate data=mydata order=internal; 
var id;
class A10 raceth sex vital_status stage1 grade site surgery radiation area area1 birthplace
      type_of_reporting_source year sequence_number  tobacco marital_status_at_dx;
class medicaid/descending;
tables 
	(All raceth sex vital_status stage1 grade site surgery radiation area area1 birthplace 
     tobacco marital_status_at_dx type_of_reporting_source year sequence_number), 
	id*(medicaid)*(N colpctn="%"*f=5.1) id*(A10*medicaid)*(colpctn="%"*f=5.1)/nocellmerge printmiss;
format...
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Aug 2018 11:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-tabulate-by-two-column-factors-grouped-within/m-p/485719#M71885</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-08-10T11:21:24Z</dc:date>
    </item>
  </channel>
</rss>

