<?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 Sum column values for a variable by another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575864#M162951</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two variables that I want to focus on - set and balance. Is there code that would sum up balance by set i.e. in the &lt;U&gt;'Results' tab&lt;/U&gt;, there would be a summary table that would show that set=1 has a total balance of 107, set=2 has a total balance of 46 and&amp;nbsp;set=3 has a total balance of 95. The below example is a small extract but there are over 100,000 records in my dataset, so would like a quick overview to see what the total balance would be by set (1, 2 or 3). Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set&amp;nbsp; &amp;nbsp;Balance&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 82&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 36&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Current code:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc summary data=test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;var balance;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;by set;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jul 2019 15:40:24 GMT</pubDate>
    <dc:creator>jeremy4</dc:creator>
    <dc:date>2019-07-23T15:40:24Z</dc:date>
    <item>
      <title>Sum column values for a variable by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575864#M162951</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two variables that I want to focus on - set and balance. Is there code that would sum up balance by set i.e. in the &lt;U&gt;'Results' tab&lt;/U&gt;, there would be a summary table that would show that set=1 has a total balance of 107, set=2 has a total balance of 46 and&amp;nbsp;set=3 has a total balance of 95. The below example is a small extract but there are over 100,000 records in my dataset, so would like a quick overview to see what the total balance would be by set (1, 2 or 3). Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set&amp;nbsp; &amp;nbsp;Balance&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 82&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 36&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Current code:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc summary data=test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;var balance;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;by set;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 15:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575864#M162951</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-07-23T15:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sum column values for a variable by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575867#M162952</link>
      <description>&lt;P&gt;Pay attention, in your code you used&amp;nbsp;&lt;STRONG&gt;BY SET,&amp;nbsp;&lt;/STRONG&gt;which assumes that the data set is already sorted by &lt;STRONG&gt;SET&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have no huge amount of sets you can use &lt;STRONG&gt;CLASS&lt;/STRONG&gt; instead of &lt;STRONG&gt;BY&lt;/STRONG&gt; and be free of sorting the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyhow you missed the OUTPUT statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=test;

   var balance;

   by set;   /* or class set; */

  output out=want sum=;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jul 2019 15:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575867#M162952</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-07-23T15:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sum column values for a variable by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575868#M162953</link>
      <description>Did your code not work?&lt;BR /&gt;Or do you need something else?&lt;BR /&gt;&lt;BR /&gt;proc sort data=test; by set;run;&lt;BR /&gt;proc means data=test sum;&lt;BR /&gt;by set;&lt;BR /&gt;var balance;&lt;BR /&gt;run;</description>
      <pubDate>Tue, 23 Jul 2019 15:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575868#M162953</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-23T15:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sum column values for a variable by another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575869#M162954</link>
      <description>&lt;P&gt;Your code looks o.k. to me (if the source data is sorted by variable SET). Here just for fun alternative code using SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
/*  create table want as*/
  select 
    set, sum(balance) as sum_balance
  from test
  group by set
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jul 2019 15:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-column-values-for-a-variable-by-another-variable/m-p/575869#M162954</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-07-23T15:50:54Z</dc:date>
    </item>
  </channel>
</rss>

