<?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: Add a subtotal column in the database in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429368#M281487</link>
    <description>Yes, they're just 2 columns in the same database. Awesome. Thanks again draycut.</description>
    <pubDate>Sat, 20 Jan 2018 11:15:56 GMT</pubDate>
    <dc:creator>Tony5</dc:creator>
    <dc:date>2018-01-20T11:15:56Z</dc:date>
    <item>
      <title>Add a subtotal column in the database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429356#M281483</link>
      <description>&lt;P&gt;Hi, I'm still a newbie with SAS an I need help with maybe a simple question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you add a subtotal column in a database?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say this is my sample dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
	input zip $ branch $ count;

	datalines;
	501 52--- 1
	501 81--- 2
	501 99--- 1
	101 22--- 2
	101 23--- 48
	101 31--- 40
	101 42--- 56
	;
run;

proc print;
run;&lt;/PRE&gt;&lt;P&gt;Which gives me this in the results window:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Input dbase" style="width: 152px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17996iF336D5C0D7E6F02B/image-dimensions/152x209?v=v2" width="152" height="209" role="button" title="sas subtotals 1.png" alt="Input dbase" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Input dbase&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Table below shows what I want to happen with the database:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output dbase" style="width: 427px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17997i97A36D7FB2D96776/image-dimensions/427x194?v=v2" width="427" height="194" role="button" title="sas subtotals.png" alt="Output dbase" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Output dbase&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tried to Google and I'm confused whether I should use tabulate or sql or what. (I also don't know SQL by the way.)&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Tony&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 08:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429356#M281483</guid>
      <dc:creator>Tony5</dc:creator>
      <dc:date>2018-01-20T08:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add a subtotal column in the database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429362#M281484</link>
      <description>&lt;P&gt;Do like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input zip $ branch $ count;

	datalines;
	501 52--- 1
	501 81--- 2
	501 99--- 1
	101 22--- 2
	101 23--- 48
	101 31--- 40
	101 42--- 56
	;
run;

proc sql;
   create table want as
   select *
         ,sum(count) as Count_Subtotals
         ,count/ calculated Count_Subtotals as Percent_Count format=percent.
   from have
   group by zip;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Jan 2018 09:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429362#M281484</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-20T09:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Add a subtotal column in the database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429366#M281485</link>
      <description>&lt;P&gt;Thanks for the quick response draycut!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code worked flawlessly. I'm super happy to see that the code is simpler than I expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Curious question though. Just in case I have multiple 'count' columns in another database, can I just do this? (see code)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
   select *
         ,sum(count) as Count_Subtotals
         ,count/ calculated Count_Subtotals as Percent_Count format=percent.
         ,sum(count_2) as Count_Subtotals_2
         ,count/ calculated Count_Subtotals_2 as Percent_Count_2 format=percent.
   from have
   group by zip;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or do I need to repeat the proc sql blocks per column?&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 11:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429366#M281485</guid>
      <dc:creator>Tony5</dc:creator>
      <dc:date>2018-01-20T11:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Add a subtotal column in the database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429367#M281486</link>
      <description>&lt;P&gt;No problem, glad to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the count colums are in different data sets, you can not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are, you can use the same code&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 11:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429367#M281486</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-20T11:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Add a subtotal column in the database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429368#M281487</link>
      <description>Yes, they're just 2 columns in the same database. Awesome. Thanks again draycut.</description>
      <pubDate>Sat, 20 Jan 2018 11:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-a-subtotal-column-in-the-database/m-p/429368#M281487</guid>
      <dc:creator>Tony5</dc:creator>
      <dc:date>2018-01-20T11:15:56Z</dc:date>
    </item>
  </channel>
</rss>

