<?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: Summing within nested sql query in pass through in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727632#M226357</link>
    <description>&lt;P&gt;ID represents accounts and the users are the people workings those accounts. Multiple users can manage amounts on one accounts and these amounts are separate transactions. SO i need to sum of all the amounts by user and then i need to count the number of times the account appears. Like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;TD&gt;user&lt;/TD&gt;&lt;TD&gt;sum(amt)&lt;/TD&gt;&lt;TD&gt;count (ID)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;bdf&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, it is to subset the oracle table. the sas table has other information that is not found in that oracle table&lt;/P&gt;</description>
    <pubDate>Fri, 19 Mar 2021 02:54:14 GMT</pubDate>
    <dc:creator>TheNovice</dc:creator>
    <dc:date>2021-03-19T02:54:14Z</dc:date>
    <item>
      <title>Summing within nested sql query in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727583#M226320</link>
      <description>&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 tables like below:&lt;/P&gt;&lt;P&gt;Table A:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;TD&gt;user&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;bdf&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table b:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/T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/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, i know how to get the output until sum(amt)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;CONNECT TO ORACLE AS ORADB (user=&amp;amp;NAME password=&amp;amp;pASS path=ExaODIN preserve_comments);&lt;BR /&gt;create table same as&lt;BR /&gt;select&lt;BR /&gt;d.*,sum(b.amt) as amt&lt;BR /&gt;from A D&lt;BR /&gt;left join connection to ORADB&lt;BR /&gt;(select id, date,user,amt&lt;BR /&gt;from Table B&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;) e&lt;BR /&gt;on A.id = B.id&lt;BR /&gt;and (A.date) = (b.date)&lt;BR /&gt;AND A.user = b.user&lt;BR /&gt;group by a.id,b.user_id&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;Disconnect from ORADB;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I i don't know how to get the count of the ID as well... I can't seem to get the syntax right for the nested sub query that will sum the amt by user first and then let me count the total ids&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this makes sense&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 21:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727583#M226320</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2021-03-18T21:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Summing within nested sql query in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727592#M226323</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Please post your code using the appropriate icon.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is table A a SAS table and table B an Oracle table?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The syntax could be something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname ORADB oracle user=&amp;amp;NAME password=&amp;amp;pASS path=ExaODIN preserve_comments;
proc sql;
  connect using ORADB;
  create table SAME as
  select A.*, B.USER_ID, sum(B.AMT) as AMT
  from A 
         left join B
       ORADB.B
         on  A.ID   = B.ID
         and A.DATE = B.DATE
         and A.USER = B.USER
  group by A.ID, B.USER_ID
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also do not use uppercase randomly in your code. Or parentheses. Use these to make your code more legible, rather than messier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 22:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727592#M226323</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-18T22:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Summing within nested sql query in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727625#M226350</link>
      <description>&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies, I was trying to conceal variable names and table names and did a shoddy job.&lt;/P&gt;&lt;P&gt;Table A is a local sas table = Let's call it Accounts&lt;/P&gt;&lt;P&gt;Table B is in oracle = Let's call it Amounts. This is a huge table. Hence the use of passthrough&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is similar to your code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However,&amp;nbsp; The sum(amt) has to be grouped by user and the count(id) has to be grouped by Id only. This is where i am stuck. I could just write a second query to get the count of ID but i would like to do it in the nested query if possible.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;CONNECT TO ORACLE AS ORADB (user=&amp;amp;NAME password=&amp;amp;pASS path=ExaODIN preserve_comments);&lt;BR /&gt;create table BIF as&lt;BR /&gt;select&lt;BR /&gt;a.*,sum(b.amt) as Amt&lt;/P&gt;&lt;P&gt;from Accounts a&lt;BR /&gt;left join connection to ORADB&lt;BR /&gt;(select BAN, PYM_METHOD,deposit_Date,user_id, original_amt&lt;BR /&gt;from ODS.Amounts&lt;BR /&gt;&lt;BR /&gt;) b&lt;BR /&gt;on A.id = B.id&lt;BR /&gt;and a.date = b.date&lt;BR /&gt;AND a.user = b.user&lt;BR /&gt;group by a.id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 01:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727625#M226350</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2021-03-19T01:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Summing within nested sql query in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727629#M226354</link>
      <description>&lt;P&gt;Are USER and ID linked somehow? As in all USERs in one ID cannot be found in another ID?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the value of the SAS table here since you do an qui join in ID and USER? You could do the summary wholly in Oracle. Is it to subset the Oracle table?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 02:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727629#M226354</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-19T02:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Summing within nested sql query in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727632#M226357</link>
      <description>&lt;P&gt;ID represents accounts and the users are the people workings those accounts. Multiple users can manage amounts on one accounts and these amounts are separate transactions. SO i need to sum of all the amounts by user and then i need to count the number of times the account appears. Like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;TD&gt;user&lt;/TD&gt;&lt;TD&gt;sum(amt)&lt;/TD&gt;&lt;TD&gt;count (ID)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;bdf&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;01-Jan-21&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, it is to subset the oracle table. the sas table has other information that is not found in that oracle table&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 02:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727632#M226357</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2021-03-19T02:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Summing within nested sql query in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727639#M226360</link>
      <description>What sort of percentage do you keep?  How many different values for ID and USER in table A?&lt;BR /&gt;</description>
      <pubDate>Fri, 19 Mar 2021 05:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727639#M226360</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-19T05:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Summing within nested sql query in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727888#M226459</link>
      <description>&lt;P&gt;in the hundred thousands&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 03:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727888#M226459</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2021-03-20T03:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Summing within nested sql query in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727895#M226462</link>
      <description>&lt;P&gt;It seems you should reduce the volume as much as possible in Oracle:&lt;/P&gt;
&lt;P&gt;Sum the amounts and count the records, using group by ID, USER. This is the pass-through query.&lt;/P&gt;
&lt;P&gt;This query is joined to the SAS table. &lt;/P&gt;
&lt;P&gt;The syntax could be something like:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;libname ORADB oracle user=&amp;amp;NAME password=&amp;amp;pASS path=ExaODIN preserve_comments;
proc sql;
  connect using ORADB;
  create table SAME as
  select A.*, SUM, COUNT
  from A 
    left join connection to ORADB 
      (select ID, DATE, USER, sum(AMT) as SUM, count(*) as COUNT 
       from B
       group by A.ID, B.USER_ID)
    on  A.ID   = B.ID
    and A.DATE = B.DATE
    and A.USER = B.USER
;
quit;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 07:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-within-nested-sql-query-in-pass-through/m-p/727895#M226462</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-20T07:50:25Z</dc:date>
    </item>
  </channel>
</rss>

