<?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 with percentage calculations in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517765#M3403</link>
    <description>&lt;P&gt;Thank you. I will try your approach to see if it will work for my case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 01 Dec 2018 21:48:45 GMT</pubDate>
    <dc:creator>kenwill</dc:creator>
    <dc:date>2018-12-01T21:48:45Z</dc:date>
    <item>
      <title>PROC TABULATE with percentage calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517618#M3360</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a follow up to&amp;nbsp;a question I posted earlier. This time, I tried to do percentage calculations but not quite successful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see attachments:&lt;/P&gt;&lt;P&gt;Data set: table.sas7bdat&lt;/P&gt;&lt;P&gt;2 tables I tried to create: Table2.xlsx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below are my SAS codes.&amp;nbsp;I can calculate the&amp;nbsp;column percentages correctly, but not the row percentages.&lt;/P&gt;&lt;P&gt;Besides, I want to show the N and % side by side instead of two separate tables (one for N, another for %) like what I did here. How can I do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/* Column percentages */&lt;/SPAN&gt;&lt;BR /&gt;proc tabulate data=test.table;&lt;BR /&gt;where temperature ~= 'warm' and month ~= 'december';&lt;BR /&gt;class month time;&lt;BR /&gt;class temperature / mlf;&lt;BR /&gt;table time=' ' all='Total',&lt;BR /&gt;month=' '*(temperature=' ' all)*n=' '&lt;BR /&gt;month=' '*(temperature=' ' all)*colpctn=' '&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Row percentages */&lt;/P&gt;&lt;P&gt;proc tabulate data=test.table;&lt;BR /&gt;where temperature ~= 'warm' and month ~= 'december';&lt;BR /&gt;class month time;&lt;BR /&gt;class temperature / mlf;&lt;BR /&gt;table time=' ' all='Total',&lt;BR /&gt;month=' '*(temperature=' ' all)*n=' '&lt;BR /&gt;month=' '*(temperature=' ' all)*rowpctn=' '&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any advice!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ken&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 19:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517618#M3360</guid>
      <dc:creator>kenwill</dc:creator>
      <dc:date>2018-11-30T19:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE with percentage calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517621#M3361</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248732"&gt;@kenwill&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a follow up to&amp;nbsp;a question I posted earlier. This time, I tried to do percentage calculations but not quite successful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please see attachments:&lt;/P&gt;
&lt;P&gt;Data set: table.sas7bdat&lt;/P&gt;
&lt;P&gt;2 tables I tried to create: Table2.xlsx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are my SAS codes.&amp;nbsp;I can calculate the&amp;nbsp;column percentages correctly, but not the row percentages.&lt;/P&gt;
&lt;P&gt;Besides, I want to show the N and % side by side instead of two separate tables (one for N, another for %) like what I did here. How can I do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You will have to describe what a "correct" row percentage may be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The general approach in getting two or more statistics to appear together are parentheses.&lt;/P&gt;
&lt;P&gt;Instead of&lt;/P&gt;
&lt;PRE&gt;month=' '*(temperature=' ' all)*n=' '
month=' '*(temperature=' ' all)*colpctn=' '&lt;/PRE&gt;
&lt;P&gt;try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;month=' '*(temperature=' ' all)* (n=' ' colpctn=' ')
&lt;/PRE&gt;
&lt;P&gt;Though specific orders may depend on the nesting of different variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is best to provide data in the form of&amp;nbsp; data step code. Then people using different operating systems and SAS versions&amp;nbsp;can create data to test code with. You may not know that there are lots of people using different versions of SAS and some of them, even with the same operating system, may not be able to use your SAS data set because they have an older version.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 19:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517621#M3361</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-30T19:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE with percentage calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517665#M3377</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the advice!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the dataset in Excel format (Book1.xlsx). Would that help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding the row percentage calculations. How can I calculate them with respect to the subtotal (ie., per each month) instead of the whole row (pls see Table2.xlsx)? I am not familiar with nesting, any&amp;nbsp;tips are&amp;nbsp;most welcome.&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;P&gt;Ken&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 21:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517665#M3377</guid>
      <dc:creator>kenwill</dc:creator>
      <dc:date>2018-11-30T21:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE with percentage calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517689#M3388</link>
      <description>&lt;P&gt;See if this example using the SASHELP.CARS data helps.&lt;/P&gt;
&lt;P&gt;Note that the second table uses pctn&amp;lt;cylinders&amp;gt; to get the percentage within&amp;nbsp;the values of cylinder for a single type of car.&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=sashelp.cars;
   where cylinders in (4 6 8);
   class make type cylinders;
   table make ,
         type*cylinders*(n rowpctn)
   ;
   table make ,
         type*cylinders*(n pctn&amp;lt;cylinders&amp;gt;)
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;Do not use colpctn&amp;lt;&amp;gt; rowpctn&amp;lt;&amp;gt; colpctsum&amp;lt;&amp;gt; or rowpctsum&amp;lt;&amp;gt;&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;. Those options are (or at least in previous versions of SAS) are&amp;nbsp;so far from the expected submitted code that they will crash SAS. PCTN&amp;lt;&amp;gt; or Pctsum&amp;lt;&amp;gt; with a &lt;STRONG&gt;single&lt;/STRONG&gt; variable. The &amp;lt;&amp;gt; says which variable to use for denominator. The variable must appear in the table request and things can get picky about order and dimension&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quite often it is more reliable to use Proc summary to summarize the data and then a data step to add percentages. And then use a report procedure like the Proc Print, Report or Tabulate (carefully)&amp;nbsp;to show the summarized data&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 22:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517689#M3388</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-30T22:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE with percentage calculations</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517765#M3403</link>
      <description>&lt;P&gt;Thank you. I will try your approach to see if it will work for my case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 21:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-TABULATE-with-percentage-calculations/m-p/517765#M3403</guid>
      <dc:creator>kenwill</dc:creator>
      <dc:date>2018-12-01T21:48:45Z</dc:date>
    </item>
  </channel>
</rss>

