<?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: Subtotals with different Group By in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657471#M22612</link>
    <description>&lt;PRE&gt;data T;
input P $ L CD $ EXP MV;
Datalines;
A 1 A1 10 100
A 1 A1 15 115
B 1 B1 20 120
B 2 B2 25 125
C 1 C1 30 130
C 2 C1 35 135
C 3 C2 40 140
;
proc sql;
create table want as
select * ,
(select sum(exp) from t where p=a.p) as sum_P,
(select sum(exp) from t where p=a.p and l=a.l) as sum_P_L,
(select sum(mv) from t where p=a.p and cd=a.cd) as sum_P_cd

 from t as a;
quit;&lt;/PRE&gt;</description>
    <pubDate>Thu, 11 Jun 2020 12:25:42 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-06-11T12:25:42Z</dc:date>
    <item>
      <title>Subtotals with different Group By</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657453#M22603</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have this dataset and I want to create a new table with all the table columns plus three new columns with subtotals based on different Group by.&lt;/P&gt;
&lt;P&gt;Sum (Exp) Group by P&lt;/P&gt;
&lt;P&gt;Sum (Exp) Group by P,L&lt;/P&gt;
&lt;P&gt;Sum (MV) Group by P, CD&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that feasible within a single proc sql?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
input P $ L CD $ EXP MV;
Datalines;
A 1 A1 10 100
A 1 A1 15 115
B 1 B1 20 120
B 2 B2 25 125
C 1 C1 30 130
C 2 C1 35 135
C 3 C2 40 140
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 11:44:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657453#M22603</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T11:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Subtotals with different Group By</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657457#M22604</link>
      <description>&lt;P&gt;I don't think a single call to SQL can do this, but PROC SUMMARY can. in fact, PROC SUMMARY gives you additional sums taht you didn't ask for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=t;
	class p l cd;
	types p p*l p*cd;
	var exp mv;
	output out=sums sum=sum_exp sum_mv;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 11:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657457#M22604</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-06-11T11:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Subtotals with different Group By</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657460#M22606</link>
      <description>The output has double the lines of data</description>
      <pubDate>Thu, 11 Jun 2020 12:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657460#M22606</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T12:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Subtotals with different Group By</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657463#M22608</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254213"&gt;@cmemtsa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The output has double the lines of data&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't know what you mean by this. When I run the code, I don't see double of anything. Please show me.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 12:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657463#M22608</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-06-11T12:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subtotals with different Group By</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657468#M22611</link>
      <description>&lt;DIV id="tinyMceEditorcmemtsa_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditorcmemtsa_4" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorcmemtsa_3" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorcmemtsa_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorcmemtsa_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 12:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657468#M22611</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T12:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Subtotals with different Group By</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657471#M22612</link>
      <description>&lt;PRE&gt;data T;
input P $ L CD $ EXP MV;
Datalines;
A 1 A1 10 100
A 1 A1 15 115
B 1 B1 20 120
B 2 B2 25 125
C 1 C1 30 130
C 2 C1 35 135
C 3 C2 40 140
;
proc sql;
create table want as
select * ,
(select sum(exp) from t where p=a.p) as sum_P,
(select sum(exp) from t where p=a.p and l=a.l) as sum_P_L,
(select sum(mv) from t where p=a.p and cd=a.cd) as sum_P_cd

 from t as a;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jun 2020 12:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657471#M22612</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-06-11T12:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Subtotals with different Group By</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657474#M22613</link>
      <description>That worked! Thank you!</description>
      <pubDate>Thu, 11 Jun 2020 12:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657474#M22613</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T12:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: Subtotals with different Group By</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657530#M22617</link>
      <description>I still don't see any duplicates.</description>
      <pubDate>Thu, 11 Jun 2020 13:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Subtotals-with-different-Group-By/m-p/657530#M22617</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-06-11T13:56:03Z</dc:date>
    </item>
  </channel>
</rss>

