<?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 Calculate Percentage with rows and column calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416239#M102185</link>
    <description>&lt;P&gt;Calculating percentages with the N of a row as the denominator.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is create a table using proc tabulate, if possible, where the N of the row is used as the denominator for the cell.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quarter is a class variable, with categories of Q1, Q2, Q3, Q4 (this is to be used as the row). Flag_1 and Flag_2 are binary flag variables; they have values of either 1 or 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I want the sum of my flag variables (flag_1 and flag_2) within a row (quarter class variable) to be the numerator in a cell, divided by the number of observations for that row, where the quarter is Q1 etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired output is below (Made up numbers for the sum of observations in a row (30, 40, etc); wanted to emphasize that the number of observations with a different quarter vary):&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_UAG24T3.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16859i43803AD6D58E7A77/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_UAG24T3.png" alt="_UAG24T3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2017 03:30:58 GMT</pubDate>
    <dc:creator>renalstats</dc:creator>
    <dc:date>2017-11-27T03:30:58Z</dc:date>
    <item>
      <title>Calculate Percentage with rows and column calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416239#M102185</link>
      <description>&lt;P&gt;Calculating percentages with the N of a row as the denominator.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is create a table using proc tabulate, if possible, where the N of the row is used as the denominator for the cell.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quarter is a class variable, with categories of Q1, Q2, Q3, Q4 (this is to be used as the row). Flag_1 and Flag_2 are binary flag variables; they have values of either 1 or 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I want the sum of my flag variables (flag_1 and flag_2) within a row (quarter class variable) to be the numerator in a cell, divided by the number of observations for that row, where the quarter is Q1 etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired output is below (Made up numbers for the sum of observations in a row (30, 40, etc); wanted to emphasize that the number of observations with a different quarter vary):&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_UAG24T3.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16859i43803AD6D58E7A77/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_UAG24T3.png" alt="_UAG24T3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 03:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416239#M102185</guid>
      <dc:creator>renalstats</dc:creator>
      <dc:date>2017-11-27T03:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Percentage with rows and column calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416245#M102189</link>
      <description>&lt;P&gt;sum of var divided by number of obs is called the mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data HAVE;
  do QUARTER=1 to 4;
    do FL1=0 to 1;
      do FL2=0 to 1;
        do I=1 to 10;
          if ranuni(0)&amp;gt;.5 then output;
        end;
      end;
    end;
  end;
run;

proc tabulate data=HAVE;
  class QUARTER ;
  var FL1 FL2;
  table QUARTER, n (FL1 FL2)*(sum mean) ;
run;
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Tabulate: Table 1" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c m header" rowspan="2" scope="col"&gt;&amp;nbsp;&lt;/TH&gt;
&lt;TH class="c header" rowspan="2" scope="col"&gt;N&lt;/TH&gt;
&lt;TH class="c header" colspan="2" scope="colgroup"&gt;FL1&lt;/TH&gt;
&lt;TH class="c header" colspan="2" scope="colgroup"&gt;FL2&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="c header" scope="col"&gt;Sum&lt;/TH&gt;
&lt;TH class="c header" scope="col"&gt;Mean&lt;/TH&gt;
&lt;TH class="c header" scope="col"&gt;Sum&lt;/TH&gt;
&lt;TH class="c header" scope="col"&gt;Mean&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;QUARTER&lt;/TH&gt;
&lt;TD rowspan="2" class="r b data"&gt;18&lt;/TD&gt;
&lt;TD rowspan="2" class="r b data"&gt;11.00&lt;/TD&gt;
&lt;TD rowspan="2" class="r b data"&gt;0.61&lt;/TD&gt;
&lt;TD rowspan="2" class="r b data"&gt;9.00&lt;/TD&gt;
&lt;TD rowspan="2" class="r b data"&gt;0.50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r b data"&gt;23&lt;/TD&gt;
&lt;TD class="r b data"&gt;13.00&lt;/TD&gt;
&lt;TD class="r b data"&gt;0.57&lt;/TD&gt;
&lt;TD class="r b data"&gt;14.00&lt;/TD&gt;
&lt;TD class="r b data"&gt;0.61&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r b data"&gt;18&lt;/TD&gt;
&lt;TD class="r b data"&gt;9.00&lt;/TD&gt;
&lt;TD class="r b data"&gt;0.50&lt;/TD&gt;
&lt;TD class="r b data"&gt;9.00&lt;/TD&gt;
&lt;TD class="r b data"&gt;0.50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r b data"&gt;21&lt;/TD&gt;
&lt;TD class="r b data"&gt;8.00&lt;/TD&gt;
&lt;TD class="r b data"&gt;0.38&lt;/TD&gt;
&lt;TD class="r b data"&gt;10.00&lt;/TD&gt;
&lt;TD class="r b data"&gt;0.48&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 27 Nov 2017 04:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416245#M102189</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-11-27T04:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Percentage with rows and column calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416446#M102248</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/176949"&gt;@renalstats&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Calculating percentages with the N of a row as the denominator.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to do is create a table using proc tabulate, if possible, where the N of the row is used as the denominator for the cell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quarter is a class variable, with categories of Q1, Q2, Q3, Q4 (this is to be used as the row). Flag_1 and Flag_2 are binary flag variables; they have values of either 1 or 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I want the sum of my flag variables (flag_1 and flag_2) within a row (quarter class variable) to be the numerator in a cell, divided by the number of observations for that row, where the quarter is Q1 etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The desired output is below (Made up numbers for the sum of observations in a row (30, 40, etc); wanted to emphasize that the number of observations with a different quarter vary):&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_UAG24T3.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16859i43803AD6D58E7A77/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_UAG24T3.png" alt="_UAG24T3.png" /&gt;&lt;/span&gt;&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;Your data picture shows a sum/sum your description says&amp;nbsp;a sum divided by an n (number of observations). so which is it you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc tabulate has statistics colpctsum and rowpctsum if the denominatior is a sum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You much better off providing an example data set in data step form as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;did and then actual numbers in your result so we can check code behavior.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 15:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416446#M102248</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-27T15:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Percentage with rows and column calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416492#M102253</link>
      <description>Thank you, I was looking/thinking about it incorrectly.</description>
      <pubDate>Mon, 27 Nov 2017 19:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Percentage-with-rows-and-column-calculation/m-p/416492#M102253</guid>
      <dc:creator>renalstats</dc:creator>
      <dc:date>2017-11-27T19:38:47Z</dc:date>
    </item>
  </channel>
</rss>

