<?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: How do I find the sum of subgroup in proc SQL in my grouped data? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615413#M76971</link>
    <description>When you select distinct *, you're saying take the unique values for each line, which INCLUDES the rate. You don't want the rate for each value though, you want that summarized so you cannot use the * notation in your query. &lt;BR /&gt;&lt;BR /&gt;Most other SQL types (Oracle, DB2) would cause this to result in an error but in SAS this is allowed and can be quite useful. You should be seeing a note about re-merging in the log though, which should raise a flag for you.</description>
    <pubDate>Mon, 06 Jan 2020 18:08:23 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-01-06T18:08:23Z</dc:date>
    <item>
      <title>How do I find the sum of subgroup in proc SQL in my grouped data?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615387#M76965</link>
      <description>&lt;P&gt;Hello guys, I am new to SAS and having a problem on producing the sub-grouping value in my proc sql after I grouped them once before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My sample is:&lt;/P&gt;&lt;P&gt;data try;&lt;BR /&gt;input ID type $ name $ rate;&lt;BR /&gt;datalines;&lt;BR /&gt;10 1 orange 0.7&lt;BR /&gt;25 1 apple 0.1&lt;BR /&gt;25 2 apple 0.1&lt;BR /&gt;25 3 apple 0.3&lt;BR /&gt;11 2 pear 0.5&lt;BR /&gt;11 1 pear 0.3&lt;BR /&gt;11 2 pear 0.1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is like:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Type Name&amp;nbsp; Rate&lt;/P&gt;&lt;P&gt;10&amp;nbsp; 1 orange&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.7&lt;/P&gt;&lt;P&gt;25&amp;nbsp; 1 apple&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.5&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2 apple&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3 apple&lt;BR /&gt;11&amp;nbsp; 1&amp;nbsp; pear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.9&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; pear&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table try2 as select distinct *, sum(rate) as rate2 from try&lt;BR /&gt;group by ID, name&lt;BR /&gt;order by ID, name;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My output can not display only all the data. How can I just get the subgroup total and only displaying the ID as once. The summed rate is not necessarily matched with the type. The idea is showing the ID's subgroup total rate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for all help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 17:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615387#M76965</guid>
      <dc:creator>Woodyfc</dc:creator>
      <dc:date>2020-01-06T17:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the sum of subgroup in proc SQL in my grouped data?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615398#M76968</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/305735"&gt;@Woodyfc&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach to do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table try2 as
select distinct ID, type, name, sum(rate) as rate2 from try
group by ID, name
order by ID, name;
quit;

proc report data=try2;
 columns ID type name rate2;
 define ID / group;
  define rate2 / group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture d’écran 2020-01-06 à 18.49.23.png" style="width: 200px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35171i5A97C63C8054D1CE/image-size/small?v=v2&amp;amp;px=200" role="button" title="Capture d’écran 2020-01-06 à 18.49.23.png" alt="Capture d’écran 2020-01-06 à 18.49.23.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 17:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615398#M76968</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-06T17:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the sum of subgroup in proc SQL in my grouped data?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615413#M76971</link>
      <description>When you select distinct *, you're saying take the unique values for each line, which INCLUDES the rate. You don't want the rate for each value though, you want that summarized so you cannot use the * notation in your query. &lt;BR /&gt;&lt;BR /&gt;Most other SQL types (Oracle, DB2) would cause this to result in an error but in SAS this is allowed and can be quite useful. You should be seeing a note about re-merging in the log though, which should raise a flag for you.</description>
      <pubDate>Mon, 06 Jan 2020 18:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615413#M76971</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-06T18:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the sum of subgroup in proc SQL in my grouped data?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615513#M76980</link>
      <description>Thanks!! I was too focused on proc sql, forgetting the alternative procedure haha.</description>
      <pubDate>Tue, 07 Jan 2020 00:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615513#M76980</guid>
      <dc:creator>Woodyfc</dc:creator>
      <dc:date>2020-01-07T00:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the sum of subgroup in proc SQL in my grouped data?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615514#M76981</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; Thanks for your reminders!!:D</description>
      <pubDate>Tue, 07 Jan 2020 00:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-find-the-sum-of-subgroup-in-proc-SQL-in-my-grouped-data/m-p/615514#M76981</guid>
      <dc:creator>Woodyfc</dc:creator>
      <dc:date>2020-01-07T00:22:48Z</dc:date>
    </item>
  </channel>
</rss>

