<?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: Find MAX date by customer in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293406#M61060</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12161"&gt;@paul&lt;/a&gt;_skirving wrote:&lt;BR /&gt;
&lt;P&gt;Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... and i think i understand how it works too!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which is the most important thing for me, also.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Aug 2016 12:43:22 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-08-23T12:43:22Z</dc:date>
    <item>
      <title>Find MAX date by customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293398#M61053</link>
      <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i'm stuck again, maybe someone could help me out please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following, which gives me all the data i need, customer number, address etc. &amp;nbsp;it has 389 customers and 83,000 transaction dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;create table work.transaction_dates as&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; select distinct&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; t1.*,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; t2.Datestart as Last_Transaction_Date,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; t2.customer_number&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from work.have4 as t1 left join have5 as t2 on (t1.accountid=t2.a_number);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this works OK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i try to find the latest transaction date per customer with this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.transactions_MAX;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; set &lt;SPAN&gt;work.&lt;SPAN&gt;transaction_dates&lt;/SPAN&gt;&lt;/SPAN&gt;;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where Last_Transaction_Date=max(Last_Transaction_Date);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; by Last_Transaction_Date;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get -&amp;nbsp;ERROR: Function MAX requires at least 2 argument(s). &amp;nbsp;(the number of transactions per customer could be between 0 and X.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i get the last transaction date per customer?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 12:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293398#M61053</guid>
      <dc:creator>pandhandj</dc:creator>
      <dc:date>2016-08-23T12:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find MAX date by customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293401#M61055</link>
      <description>&lt;P&gt;In a data step, the max(function) behaves differently from SQL. In SQL, max() works vertically and only needs one argument; in a data step, max() can only be applied to values of the current observation, and needs more than one argument.&lt;/P&gt;
&lt;P&gt;Instead consider this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from transaction_dates
group by customer_number
having last_transaction_date = max(last_transaction_date);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=transaction_dates;
by customer_number descending last_transaction_date;
run;

data want;
set transaction_dates;
by customer_number;
retain ref_date;
if first.customer_number then ref_date = last_transaction_date;
if last_transaction_date = ref_date;
drop ref_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Am not so sure about my SQL, but quite sure about the data step solution.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 12:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293401#M61055</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-23T12:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Find MAX date by customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293405#M61059</link>
      <description>&lt;P&gt;Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that works a treat and i think i understand how it works too!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you very much for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best regards.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 12:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293405#M61059</guid>
      <dc:creator>pandhandj</dc:creator>
      <dc:date>2016-08-23T12:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find MAX date by customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293406#M61060</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12161"&gt;@paul&lt;/a&gt;_skirving wrote:&lt;BR /&gt;
&lt;P&gt;Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... and i think i understand how it works too!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which is the most important thing for me, also.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 12:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293406#M61060</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-23T12:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find MAX date by customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293474#M61083</link>
      <description>&lt;P&gt;Depending on how many other variables you need to carry along;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=&lt;SPAN&gt;work.transaction_dates nway;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; class customer_number;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; var ref_date;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; output out=work.lasttransaction max(ref_date)=Last_Transaction_date;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 15:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-MAX-date-by-customer/m-p/293474#M61083</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-23T15:47:37Z</dc:date>
    </item>
  </channel>
</rss>

