<?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: Using SQL aggregate functions with a LEFT JOIN in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246565#M56243</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"texthere" AS label_everyone,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is not an aggregate. This is what most probably causes every record to be in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an aside, I would clearly avoid putting it all in one complex step. Build it step by step, it is easier to understand and easier to debug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Write every program as if the next one to maintain it is a violent psychopath who knows where you live"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my solution with a data step that will make only one pass through the large dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sums;
label_everyone = 'texthere';
merge
  data_with_many_rows
  data_with_one_row
  end=done
;
retain
  total1 0
  total2 0
  total1_subset 0
  total2_subset 0
;
total1 + numvar1;
total2 + numvar2;
if classvar = 1 then do;
  total1_subset + numvar1;
  total2_subset + numvar2;
end;
if done then output;
keep label_everyone total1 total2 total1_subset total2_subset vars_from one_row;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(not tested because of missing test data)&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jan 2016 09:04:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-01-28T09:04:03Z</dc:date>
    <item>
      <title>Using SQL aggregate functions with a LEFT JOIN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246563#M56242</link>
      <description>&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p2"&gt;I've got two datasets. &amp;nbsp;The first dataset&amp;nbsp;(DATA_WITH_MANY_ROWS) is a dataset with many rows of data and includes two numeric variables numvar1 and numvar2. &amp;nbsp;Using only one PROC SQL step, I would like to 1) aggregate&amp;nbsp;the data across this entire table, then 2) aggregate the data within a subset of the table, then 3)&amp;nbsp;join with an existing dataset that has only one observation (DATA_WITH_ONE_ROW). &amp;nbsp;You'll also notice I'm including adding a text label to the data. &amp;nbsp;Essentially&amp;nbsp;I am trying to export a final dataset which contains only one observation and side by side includes the above described measures. &amp;nbsp;&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p2"&gt;I have included code below showing my current approach. &amp;nbsp;However, the output table (OUTPUT_TABLE) ends up having as many rows as the dataset&amp;nbsp;DATA_WITH_MANY_ROWS. &amp;nbsp;I can't seem to figure out where my code is going wrong since I'm fairly certain each item in the left-join should only have one observation and should join smoothly using the ON 1=1 condition. Since I am summarizing in every case down to a single row of data, I assume I do not need to use group by functions. &amp;nbsp;&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p2"&gt;Am I misunderstanding something about how the order that SQL is processing my code?&amp;nbsp;Thanks to the community for any help/insight.&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SQL&lt;/STRONG&gt;&lt;SPAN class="s1"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s2"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;TABLE&lt;/SPAN&gt; work.OUTPUT_TABLE &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p4"&gt;SELECT&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s3"&gt;"texthere"&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; label_everyone,&lt;/P&gt;
&lt;P class="p3"&gt;SUM(a.numvar1) &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; TOTAL1 SUM(a.numvar2) &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; TOTAL2,&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s4"&gt;b.&lt;/SPAN&gt;*, &lt;SPAN class="s4"&gt;c.&lt;/SPAN&gt;*&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s2"&gt;FROM&lt;/SPAN&gt; work.DATA_WITH_MANY_ROWS &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; a&lt;/P&gt;
&lt;P class="p4"&gt;LEFT JOIN&lt;/P&gt;
&lt;P class="p3"&gt;(&lt;SPAN class="s2"&gt;SELECT&lt;/SPAN&gt; SUM(numvar1) &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; TOTAL1_SUBSET, SUM(numvar2) &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; TOTAL2_SUBSET &lt;SPAN class="s2"&gt;FROM&lt;/SPAN&gt; DATA_WITH_MANY_ROWS &lt;SPAN class="s2"&gt;WHERE&lt;/SPAN&gt; classvar=&lt;SPAN class="s4"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;) &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; b &lt;SPAN class="s2"&gt;ON&lt;/SPAN&gt; &lt;SPAN class="s4"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;=&lt;SPAN class="s4"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s2"&gt;LEFT&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;JOIN&lt;/SPAN&gt; DATA_WITH_ONE_ROW &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; c &lt;SPAN class="s2"&gt;ON&lt;/SPAN&gt; &lt;SPAN class="s4"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;=&lt;SPAN class="s4"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P class="p2"&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;&lt;SPAN class="s1"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 08:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246563#M56242</guid>
      <dc:creator>mconover</dc:creator>
      <dc:date>2016-01-28T08:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL aggregate functions with a LEFT JOIN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246565#M56243</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"texthere" AS label_everyone,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is not an aggregate. This is what most probably causes every record to be in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an aside, I would clearly avoid putting it all in one complex step. Build it step by step, it is easier to understand and easier to debug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Write every program as if the next one to maintain it is a violent psychopath who knows where you live"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my solution with a data step that will make only one pass through the large dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sums;
label_everyone = 'texthere';
merge
  data_with_many_rows
  data_with_one_row
  end=done
;
retain
  total1 0
  total2 0
  total1_subset 0
  total2_subset 0
;
total1 + numvar1;
total2 + numvar2;
if classvar = 1 then do;
  total1_subset + numvar1;
  total2_subset + numvar2;
end;
if done then output;
keep label_everyone total1 total2 total1_subset total2_subset vars_from one_row;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(not tested because of missing test data)&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 09:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246565#M56243</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-28T09:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL aggregate functions with a LEFT JOIN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246571#M56244</link>
      <description>&lt;P&gt;Sorry, its not clear what you are trying to do, there are several errors in the code. &amp;nbsp;Also, code formatting makes reading a lot easier:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WORK.OUTPUT_TABLE as
  select  "texthere" as LABEL_EVERYONE,
          sum(A.NUMVAR1) as TOTAL1    /* &amp;lt;- missing semicolon */
          sum(A.NUMVAR2) as TOTAL2,
          B.*,    /* This is meaningless? */
          C.*     /* This is meaningless? */
  from    WORK.DATA_WITH_MANY_ROWS as A
  left join (select sum(NUMVAR1) as TOTAL1_SUBSET, 
                    sum(NUMVAR2) as TOTAL2_SUBSET 
             from   DATA_WITH_MANY_ROWS where CLASSVAR=1) as B 
  on      1=1  /* This is equicalent to merge every row in A with every row in B, not what you intend */
  left join DATA_WITH_ONE_ROW as C 
  on 1=1;  /* as above, merge eveery row of first result with every row of this one */
quit;&lt;/PRE&gt;
&lt;P&gt;Post some sample data, in the form of a datastep, and what you want the output to look like.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 09:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246571#M56244</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-28T09:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL aggregate functions with a LEFT JOIN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246593#M56246</link>
      <description>&lt;P&gt;Let n denote the number of rows in DATA_WITH_MANY_ROWS (n&amp;gt;1). The left join of DATA_WITH_MANY_ROWS with the table with alias b (which has only one row) on 1=1 is a table with all rows from DATA_WITH_MANY_ROWS, enriched with the two variables from "b" (i.e. identical values of TOTAL1_SUBSET and TOTAL2_SUBSET, respectively, on each row). Hence the note in the log: "NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized." The resulting table has n rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same situation with the second left join: You simply get additional columns (one per variable in DATA_WITH_ONE_ROW) having constant values in all rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's &lt;EM&gt;this&lt;/EM&gt; temporary table with n rows on which the first SELECT statement operates. It selects summary statistics (TOTAL1, TOTAL2), but at the same time "original data" contributed by tables "b" and "c". The important point is that "original data", i.e. b.* and c.*, does &lt;EM&gt;not&lt;/EM&gt; refer to the single observations of tables "b" and "c", but to the &lt;EM&gt;columns&lt;/EM&gt; &lt;EM&gt;contributed&lt;/EM&gt; &lt;EM&gt;by&lt;/EM&gt; "b" and "c" &lt;EM&gt;in the temporary table&lt;/EM&gt;&amp;nbsp;described above! Hence the note in the log: "NOTE: The query requires remerging summary statistics back with the original data." That is, the values of TOTAL1 and TOTAL2 are copied n times to appear in all rows together with the values b.* and c.* (regardless of the fact that these values happen to be likewise only copies of a single value per variable) and with the constant label_everyone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, a &lt;STRONG&gt;quick fix&lt;/STRONG&gt; of your PROC SQL step would be to&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;insert the keyword "DISTINCT" after the first "SELECT": SELECT DISTINCT "texthere" ...&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;add the missing comma after "TOTAL1" (as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&amp;nbsp;pointed at).&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;That said, I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;&amp;nbsp;that the task could be accomplished more efficiently, be it with an improved PROC SQL step or with a data step. (I think, "&lt;FONT face="courier new,courier"&gt;merge&lt;/FONT&gt;" should read "&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;set&lt;/FONT&gt;&lt;/STRONG&gt;" in Kurt's solution and the RETAIN statement is redundant due to the "SUM" statements.)&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 12:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246593#M56246</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-28T12:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL aggregate functions with a LEFT JOIN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246598#M56247</link>
      <description>&lt;P&gt;Both "set" and "merge" work because of the way the vars are retained and only one output happens at the very end. But to me the "merge" better shows the side-by-side nature of the operation.&lt;/P&gt;
&lt;P&gt;And I used the retain statement because it allows to set the initial value.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 12:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246598#M56247</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-28T12:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL aggregate functions with a LEFT JOIN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246617#M56248</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;: Are you sure? Maybe it depends on the input datasets, but with those I had made up for testing (see below) it seemed that the variable(s) from DATA_WITH_ONE_ROW would have missing values with the 1-to-1 merge. With the SET statement, however, they would have their single value, because&amp;nbsp;&lt;SPAN&gt;DATA_WITH_ONE_ROW is the second dataset in the SET statement, so that the value is present in the last observation selected with "&lt;FONT face="courier new,courier"&gt;if done&lt;/FONT&gt; ...".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data_with_many_rows;
do numvar1=1 to 10;
  classvar=mod(numvar1,3);
  numvar2=int(11*ranuni(314159));
  output;
end;
run;

data data_with_one_row;
a=314;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;If I'm not mistaken, the initial value 0 (used in the RETAIN statement) is implied by the use of the Sum statement (as is the "retaining" itself). So, for example, without the RETAIN statement the subset totals would still have value 0 (and not missing) if the condition "&lt;FONT face="courier new,courier"&gt;classvar=1&lt;/FONT&gt;" was never met and hence the Sum statements were never executed (but compiled!).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 13:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246617#M56248</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-28T13:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL aggregate functions with a LEFT JOIN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246623#M56249</link>
      <description>&lt;P&gt;You are right. I'm so used to do MERGE always with a BY that I presumed that the value(s) of data_with_one_row would automatically be kept for the whole operation. Which they obviously aren't, so &lt;FONT face="courier new,courier"&gt;set&lt;/FONT&gt; is the way to go.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 14:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246623#M56249</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-01-28T14:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL aggregate functions with a LEFT JOIN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246640#M56250</link>
      <description>&lt;P class="p2"&gt;&lt;STRONG&gt;Excuse the poor layout etc, just edited your code quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;&lt;STRONG&gt;BM&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SQL&lt;/STRONG&gt;&lt;SPAN class="s1"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s2"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;TABLE&lt;/SPAN&gt; work.OUTPUT_TABLE &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p4"&gt;SELECT&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"texthere"&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; label_everyone,&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A.total1,&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A.total2,&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b.&lt;/SPAN&gt;*,&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c.&lt;/SPAN&gt;*&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s2"&gt;FROM&lt;/SPAN&gt;&amp;nbsp;(&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select &amp;nbsp;&lt;SPAN&gt;SUM(a.numvar1) &lt;/SPAN&gt;&lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt;&lt;SPAN&gt; TOTAL1,&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;&amp;nbsp;SUM(a.numvar2) &lt;/SPAN&gt;&lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt;&lt;SPAN&gt; TOTAL2&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from &amp;nbsp; &amp;nbsp;work.DATA_WITH_MANY_ROWS&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; a&lt;/P&gt;&lt;P class="p4"&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;SPAN class="s2"&gt;SELECT&lt;/SPAN&gt; SUM(numvar1) &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; TOTAL1_SUBSET,&lt;/P&gt;&lt;P class="p4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SUM(numvar2) &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; TOTAL2_SUBSET&lt;/P&gt;&lt;P class="p4"&gt;&lt;SPAN class="s2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;DATA_WITH_MANY_ROWS&lt;/P&gt;&lt;P class="p4"&gt;&lt;SPAN class="s2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WHERE&lt;/SPAN&gt; classvar=&lt;SPAN class="s4"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p4"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ) &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; b&lt;/P&gt;&lt;P class="p4"&gt;&lt;SPAN class="s2"&gt;, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;DATA_WITH_ONE_ROW &lt;SPAN class="s2"&gt;AS&lt;/SPAN&gt; c ;&lt;/P&gt;&lt;P class="p2"&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;&lt;SPAN class="s1"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 15:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-SQL-aggregate-functions-with-a-LEFT-JOIN/m-p/246640#M56250</guid>
      <dc:creator>BMiller</dc:creator>
      <dc:date>2016-01-28T15:05:27Z</dc:date>
    </item>
  </channel>
</rss>

