<?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: Creating Sum variables with different sorting in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657236#M22593</link>
    <description>&lt;P&gt;Please use the "little running man" to post your code, and do some formatting on the code. This spaghetti is nigh unreadable.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jun 2020 07:43:13 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-06-11T07:43:13Z</dc:date>
    <item>
      <title>Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657153#M22589</link>
      <description>Hi to all! I'm running this proc sql as I want to create two new variables as sum of the same variable but with different grouping each time but I get error msg. Is if feasible under a single proc sql? proc sql; SELECT P, L, Exp, ((select sum(exp) FROM t group by P ) as TotalExp ), ((Select sum(exp) FROM t group by P,L ) as TotalExpL), FROM t; run;</description>
      <pubDate>Thu, 11 Jun 2020 06:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657153#M22589</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T06:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657208#M22590</link>
      <description>&lt;P&gt;You can do it by joining the same table in the "from" statement, but each table is grouped differently&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 
t1.P, 
t1.L, 
t1.Exp,
t2.TotalExp,
t1.TotalExpL 
from 
(select P, L, Exp, sum(Exp) as TotalExpL from t group by P, L) t1 
inner join 
(select P, sum(Exp) as TotalExp from t group by P) t2 
on t1.P=t2.P
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jun 2020 07:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657208#M22590</guid>
      <dc:creator>sustagens</dc:creator>
      <dc:date>2020-06-11T07:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657234#M22591</link>
      <description>Thanks. It worked for this case. If becomes more complicated with one more variable for sorting (see below), how can we proceed? proc sql; select t1.P, t1.L, t1.Exp, t1.cd, t2.TotalExp, t1.TotalExpCd t1.TotalExpL from ((select P, L, Exp, sum(Exp) as TotalExpL from t group by P, L) t1 (select P, L, Exp, sum(Exp) as TotalExpCd from t group by P, CD)) t1 inner join (select P, sum(Exp) as TotalExp from t group by P) t2 on t1.P=t2.P ; quit;</description>
      <pubDate>Thu, 11 Jun 2020 07:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657234#M22591</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T07:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657235#M22592</link>
      <description>&lt;P&gt;Your ERROR is caused by an unneeded and invalid comma, and probably a missing QUIT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
SELECT
 P, L, Exp,
 ((select sum(exp) FROM t group by P ) as TotalExp ),
 ((Select sum(exp) FROM t group by P,L ) as TotalExpL), /* this comma is not needed */
 FROM t; 
run; /* SQL statements are executed immediately, so no RUN is needed */
/* use a QUIT statement to end the SQL procedure */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jun 2020 07:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657235#M22592</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-11T07:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657236#M22593</link>
      <description>&lt;P&gt;Please use the "little running man" to post your code, and do some formatting on the code. This spaghetti is nigh unreadable.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 07:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657236#M22593</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-11T07:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657241#M22594</link>
      <description>It does not work.

proc sql;

SELECT

 P, L, Exp,

 ((select sum(exp) FROM t group by P ) as TotalExp),

 ((Select sum(exp) FROM t group by P,L ) as TotalExpL) 

 FROM t; 

quit;</description>
      <pubDate>Thu, 11 Jun 2020 07:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657241#M22594</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T07:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657243#M22595</link>
      <description>I don't know why it appears like that. In the preview the format is correct.</description>
      <pubDate>Thu, 11 Jun 2020 07:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657243#M22595</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T07:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657252#M22596</link>
      <description>&lt;P&gt;It does not work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
SELECT
 P, L, Exp,
 ((select sum(exp) FROM t group by P ) as TotalExp),
 ((Select sum(exp) FROM t group by P,L ) as TotalExpL) 
 FROM t; 
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jun 2020 08:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657252#M22596</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T08:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Sum variables with different sorting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657254#M22597</link>
      <description>&lt;P&gt;Thanks. It worked for this case. If becomes more co&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
select t1.P, 
t1.L, 
t1.Exp,
 t1.cd, 
t2.TotalExp,
 t1.TotalExpCd 
t1.TotalExpL 
from
 (((select P, L, Exp, sum(Exp) as TotalExpL from t group by P, L) t1 
(select P, L, Exp, sum(Exp) as TotalExpCd from t group by P, CD)) t1)
 inner join (select P, sum(Exp) as TotalExp from t group by P) t2 
on t1.P=t2.P ; 
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;mplicated with one more variable for sorting (see below), how can we proceed?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 08:05:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Sum-variables-with-different-sorting/m-p/657254#M22597</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2020-06-11T08:05:34Z</dc:date>
    </item>
  </channel>
</rss>

