<?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: MAX and SUM on different columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706630#M216888</link>
    <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    userid,
    transaaction_date,
    amount_sum
  from (
    select
      userid,
      transaction_date,
      sum(amount) as amount_sum
    from have
    group by userid, transaction_date
  )
  group by userid
  having transaction_date = max(transaction_date)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, please supply source data in a data step with datalines.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Dec 2020 13:16:10 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-12-17T13:16:10Z</dc:date>
    <item>
      <title>MAX and SUM on different columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706624#M216886</link>
      <description>&lt;P&gt;I am trying to group by USERID to know MAX of TRANSACTION_DATE and on top of that want to sum AMOUNT only for those MAX of TRANSACTION_DATE. Any optimal solution?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 12:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706624#M216886</guid>
      <dc:creator>udupa_13</dc:creator>
      <dc:date>2020-12-17T12:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: MAX and SUM on different columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706630#M216888</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    userid,
    transaaction_date,
    amount_sum
  from (
    select
      userid,
      transaction_date,
      sum(amount) as amount_sum
    from have
    group by userid, transaction_date
  )
  group by userid
  having transaction_date = max(transaction_date)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, please supply source data in a data step with datalines.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 13:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706630#M216888</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-17T13:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: MAX and SUM on different columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706680#M216909</link>
      <description>So SUM of a variable at the latest date?</description>
      <pubDate>Thu, 17 Dec 2020 15:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706680#M216909</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-12-17T15:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: MAX and SUM on different columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706693#M216914</link>
      <description>Yes</description>
      <pubDate>Thu, 17 Dec 2020 16:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706693#M216914</guid>
      <dc:creator>udupa_13</dc:creator>
      <dc:date>2020-12-17T16:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: MAX and SUM on different columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706710#M216925</link>
      <description>&lt;LI-CODE lang="sas"&gt;proc sql;
create table want as
select
  userid,
 transaaction_date,
 sum(amount) as amount_sum
  from have
  group by userid
  having transaction_date = max(transaction_date)
;
quit;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can simplify&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;query to the above in SAS at least.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2020 16:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706710#M216925</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-12-17T16:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: MAX and SUM on different columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706881#M217045</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/317181"&gt;@udupa_13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to group by USERID to know MAX of TRANSACTION_DATE and on top of that want to sum AMOUNT only for those MAX of TRANSACTION_DATE. &lt;STRONG&gt;&lt;FONT color="#008000"&gt;Any optimal solution?&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Optimal&lt;/EM&gt; depends on the perspective: an administrator will consider a solution &lt;EM&gt;optimal&lt;/EM&gt; if it does not use to much of the precious resources a server has, someone else will want as few lines of code as possible and another one does not care about the number of lines, but wants code that can be read easily.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 05:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-and-SUM-on-different-columns/m-p/706881#M217045</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-18T05:41:43Z</dc:date>
    </item>
  </channel>
</rss>

