<?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: PROC SQL: Sum column totals over multiple tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292099#M60573</link>
    <description>&lt;P&gt;The 5 tables are delivered to my supervisor&amp;nbsp;that wants to validate my work.&lt;/P&gt;&lt;P&gt;I'm validating it beforehand to make sure he doesn't get any strange results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the input. I think I'll use macro variables to check the sums.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2016 08:43:00 GMT</pubDate>
    <dc:creator>Elle</dc:creator>
    <dc:date>2016-08-17T08:43:00Z</dc:date>
    <item>
      <title>PROC SQL: Sum column totals over multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/291712#M60428</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an input dataset with 4 important variables: ID, A1, A2, A3.&lt;/P&gt;&lt;P&gt;After processing it, I've split it into 5 datasets: ERR1, ERR2, ERR3, MODEL, NEWINPUT, with the same inputs.&lt;/P&gt;&lt;P&gt;I need to validate the results so I'm trying to do a query to see if:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SUM(input.A1)&lt;/STRONG&gt; is equal to &amp;nbsp;&lt;STRONG&gt;SUM( SUM(ERR1.A1), SUM(ERR2.A1) ....., SUM(NEWINPUT.A1) )&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also I need to group it by ID.&lt;/P&gt;&lt;P&gt;My output should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ID        INPUT_A1             OUTPUT_A1                                  INPUT_A2  OUTPUT_A2  INPUT_A3  OUTPUT_A3          
1        SUM(input.A1)         SUM( SUM(ERR1.A1), SUM(ERR2.A1) .....)       ...        ...        ...       ...
 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;My current code, which is not working, looks like this:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select coalesce(a.Id, b.Id, c.Id, d.Id, e.Id, f.Id)  as ID,
		   sum(a.A1) as IN_A1, 
		   sum( sum(b.A1), sum(c.A1), sum(d.A1), sum(e.A1), sum(f.A1) ) as OUT_A1,
		   sum(a.A2) as IN_A2, 
		   sum( sum(b.A2), sum(c.A2), sum(d.A2), sum(e.A2), sum(f.A2) ) as OUT_A2,
		   sum(a.A3) as IN_A3,
		   sum( sum(b.A3), sum(c.A3), sum(d.A3), sum(e.A3), sum(f.A3) ) as OUT_A3
	from Input as a, 
		 err.err1 as b,
		 err.err2 as c,
		 err.err3 as d,
		 err.model as e,
		 err.newinput as f
	where a.Id=b.Id=c.Id=d.Id=e.Id=f.Id
	group by calculated ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;Any help?&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 08:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/291712#M60428</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2016-08-17T08:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Sum column totals over multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/291726#M60432</link>
      <description>&lt;P&gt;What is not working...?&lt;/P&gt;
&lt;P&gt;First, since you are using inner join, no need to do the coalesce() and the&amp;nbsp;calculated thing.&lt;/P&gt;
&lt;P&gt;Second, what does uniquely identify an&amp;nbsp;observation in the tables?&lt;/P&gt;
&lt;P&gt;If it isn't ID, you will end up with M-M in your result set.&lt;/P&gt;
&lt;P&gt;If it,s ID, no need for group by.&lt;/P&gt;
&lt;P&gt;Sample data always help input and output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 16:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/291726#M60432</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-08-15T16:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Sum column totals over multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/291836#M60483</link>
      <description>&lt;P&gt;Why split the dataset into 5 separate datasets in the first place? &amp;nbsp;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&amp;nbsp;has mentioned, provide example test data (form of a datastep) and what the output should look like. &amp;nbsp;I would imagine there are better techniques, using by group for instance.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 09:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/291836#M60483</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-16T09:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Sum column totals over multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292062#M60560</link>
      <description>Hi&lt;BR /&gt;I think it's better if you add information in a separate post (not thread!), it's easier to follow the dialogue. &lt;BR /&gt;&lt;BR /&gt;You could create empty  template data sets which you append your results to, ensuring you consistent layout. &lt;BR /&gt;Another option is to make this logic into a macro, will let you set parameters and macro logic can do checks on the input data.&lt;BR /&gt;&lt;BR /&gt;But, why do you need this at all, doesn't sound like a one time thing. Don't you trust the logic in the preceeding steps?</description>
      <pubDate>Wed, 17 Aug 2016 05:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292062#M60560</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-08-17T05:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Sum column totals over multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292097#M60571</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;UPDATE1:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The INPUT dataset contains information about customer purchases.&lt;/P&gt;&lt;P&gt;ERR1 - is supposed to contain certain rows from the INPUT that fall under ERROR1 (EMPTY at the moment)&lt;/P&gt;&lt;P&gt;ERR2 - rows from INPUT that fall under ERROR2 (EMPTY at the moment)&lt;/P&gt;&lt;P&gt;ERR3 - rows from INPUT that fall under ERROR3 (Has about 10 rows)&lt;/P&gt;&lt;P&gt;MODEL - rows from INPUT that are VALID (Has the bulk of the data)&lt;/P&gt;&lt;P&gt;NEWINPUT - rows from INPUT that will be taken to the next time period where extra data is added and at one point it will become the new input file for the exact same analysis (contains about 5 rows at this point)&lt;/P&gt;&lt;P&gt;All of these tables are mutually exclusive and have the same structure so it would make sense to validate if the split is done correctly by simply verifying the sums of the columns for each variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VAR A: SUM(A) for INPUT = SUM (SUM(A) for ERR1, SUM(A) for ERR2, SUM(A) for ERR3, SUM(A) for MODEL, SUM(A) for NEWINPUT)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But all I get with my query is a table with the right header and missing values for each column&lt;/P&gt;&lt;P&gt;Hope it's more clear. Cannot share data as it's sensitive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: ID is unique key&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 08:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292097#M60571</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2016-08-17T08:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Sum column totals over multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292098#M60572</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;UPDATE2:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I've identified the problem: SUM function doesn't operate on empty datasets. Something with its argument needing to be numeric.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Does anyone know a way around this? The 5 datasets are quite interactive and, depending on the INPUT data, each one of them can be empty at any time.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 08:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292098#M60572</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2016-08-17T08:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Sum column totals over multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292099#M60573</link>
      <description>&lt;P&gt;The 5 tables are delivered to my supervisor&amp;nbsp;that wants to validate my work.&lt;/P&gt;&lt;P&gt;I'm validating it beforehand to make sure he doesn't get any strange results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the input. I think I'll use macro variables to check the sums.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 08:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Sum-column-totals-over-multiple-tables/m-p/292099#M60573</guid>
      <dc:creator>Elle</dc:creator>
      <dc:date>2016-08-17T08:43:00Z</dc:date>
    </item>
  </channel>
</rss>

