<?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: Update column with subtotals in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660019#M22699</link>
    <description>&lt;P&gt;I also thought of that solution but I wanted to ask whether there was a shorter version through creation of mirror table and inner join within the subquery.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will go with that solution since it's not feasible otherwise. Thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jun 2020 12:17:42 GMT</pubDate>
    <dc:creator>cmemtsa</dc:creator>
    <dc:date>2020-06-16T12:17:42Z</dc:date>
    <item>
      <title>Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/659997#M22692</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to update a column with subtotals on another column based on grouping. Do I have to do an inner join in a subquery&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
input ID $ L M;
Datalines;
B 1 10 
B 1 20 
C 1 30 
C 2 40 
D 1 50 
D 1 60 
D 2 70 
;

proc sql;
alter table T add M1 numeric;
update T 
set M1 = 
(select sum(M) from T  group by ID, L )
;
quit;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 11:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/659997#M22692</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-16T11:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660000#M22693</link>
      <description>&lt;P&gt;This might do the trick&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select id, l, m, sum(m) as m1
	from t
	group by id, l
	order by id, l
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jun 2020 11:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660000#M22693</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2020-06-16T11:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660002#M22694</link>
      <description>&lt;P&gt;please try below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
input ID $ L M;
Datalines;
B 1 10 
B 1 20 
C 1 30 
C 2 40 
D 1 50 
D 1 60 
D 2 70 
;

proc sql;
create table want as select ID, L, M, sum(M) as sumM from T  group by ID, L ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jun 2020 11:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660002#M22694</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-16T11:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660003#M22695</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254213"&gt;@cmemtsa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot update the T table by using an inner query that uses this table as it is already in use.&lt;/P&gt;
&lt;P&gt;I would suggest that you create another table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table T2 as
	select *, sum(M) as M1
	from T
	group by 
	ID, L;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 11:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660003#M22695</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-06-16T11:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660007#M22696</link>
      <description>&lt;P&gt;That works but as this is a part&amp;nbsp; of the code, is there a solution with Update?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 11:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660007#M22696</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-16T11:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660008#M22697</link>
      <description>&lt;P&gt;Thank you but is there a way to use Update with subquery and though a mirror table?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 11:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660008#M22697</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-16T11:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660015#M22698</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    /* Create Temporary aggregates table */
	create table sums as
	select id, l, sum(m) as m1
	from t
	group by id, l
	order by id, l;
&lt;BR /&gt;    /* Alter the table */
	alter table T add M1 num;
&lt;BR /&gt;    /* Update the t table */
	update t
	set m1 = (select s.m1 from sums s where t.id=s.id and t.l=s.l);
&lt;BR /&gt;	/* Drop the temporary aggregates table */
	drop table sums;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 11:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660015#M22698</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2020-06-16T11:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660019#M22699</link>
      <description>&lt;P&gt;I also thought of that solution but I wanted to ask whether there was a shorter version through creation of mirror table and inner join within the subquery.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will go with that solution since it's not feasible otherwise. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 12:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660019#M22699</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-16T12:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660024#M22700</link>
      <description>&lt;P&gt;If you really want UPDATE .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data T;
input ID $ L M;
Datalines;
B 1 10 
B 1 20 
C 1 30 
C 2 40 
D 1 50 
D 1 60 
D 2 70 
;

proc sql;
create table _t as select * from t;
alter table T add M1 numeric;
update T 
set M1 = 
(select sum(M) from _T  where id=t.id and l=t.l )
;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jun 2020 13:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660024#M22700</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-06-16T13:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Update column with subtotals</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660814#M22723</link>
      <description>Thanks! This is exactly what I wanted.</description>
      <pubDate>Wed, 17 Jun 2020 05:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-column-with-subtotals/m-p/660814#M22723</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-17T05:31:19Z</dc:date>
    </item>
  </channel>
</rss>

