<?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: how to get  last two lastest transaction dates for each customer id in sas in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621079#M77201</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you want to manage duplicate dates:&lt;/P&gt;
&lt;P&gt;Eg. for id = 1, do you want the 2 records with date = 4dec2010? or 4feb2010 and 4dec2010 ?&lt;/P&gt;
&lt;P&gt;Do you want to retrieve only the date and the id ? Or also x, ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2020 08:24:31 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-01-30T08:24:31Z</dc:date>
    <item>
      <title>how to get  last two lastest transaction dates for each customer id in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621071#M77199</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id date : date9. x;
format date date9.;
cards;
1 1jan2010 1
1 2jan2010 2
1 2jan2010 32
1 4feb2010 45
1 4feb2010 34
1 4dec2010 45
1 4dec2010 34
2 1jan2010 1
2 2jan2010 2
2 3jan2010 32
2 14feb2010 45
2 24feb2010 34
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;All&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how to get last two lastest transaction dates for each customer id in sas&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 08:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621071#M77199</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-01-30T08:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to get  last two lastest transaction dates for each customer id in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621072#M77200</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;can you post some sample data?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 07:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621072#M77200</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-30T07:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to get  last two lastest transaction dates for each customer id in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621079#M77201</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you want to manage duplicate dates:&lt;/P&gt;
&lt;P&gt;Eg. for id = 1, do you want the 2 records with date = 4dec2010? or 4feb2010 and 4dec2010 ?&lt;/P&gt;
&lt;P&gt;Do you want to retrieve only the date and the id ? Or also x, ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 08:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621079#M77201</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-30T08:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to get  last two lastest transaction dates for each customer id in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621080#M77202</link>
      <description>&lt;P&gt;ID AND DATE IS ENOUGH&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 08:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621080#M77202</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-01-30T08:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to get  last two lastest transaction dates for each customer id in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621082#M77203</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Optional -&amp;gt; depends on how you want to manage duplicate records */
proc sort data=test out=test1 (keep= id date) nodupkey;
	by id date;
run;

proc transpose data=test1 out=test_tr (drop=_name_) prefix=date;
	var date;
	by id;
run;

data want;
	set test_tr;
	format max_date_1 max_date_2 date9.;
	max_date_1 = largest(1, of date:);
	max_date_2 = largest(2, of date:);
	drop date:;
run;

/* Optional -&amp;gt; depends on how you want to get the results */
proc transpose data=want out=want2 (drop=_name_ rename=(col1=date));
	var max_date_1 max_date_2;
	by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 08:50:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621082#M77203</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-30T08:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to get  last two lastest transaction dates for each customer id in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621092#M77204</link>
      <description>&lt;P&gt;A hash object approach&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id date : date9. x;
format date date9.;
cards;
1 1jan2010 1
1 2jan2010 2
1 2jan2010 32
1 4feb2010 45
1 4feb2010 34
1 4dec2010 45
1 4dec2010 34
2 1jan2010 1
2 2jan2010 2
2 3jan2010 32
2 14feb2010 45
2 24feb2010 34
;
run;

data want(keep=id date);

    if _N_=1 then do;
        declare hash h (multidata : 'Y', ordered : 'd');
        h.definekey('id', 'date');
        h.definedone();
        declare hiter hi ('h');
    end;

    do until (last.id);
        set test;
        by id;
        h.add();
    end;

    do _n_=1 to 2;
        rc = hi.first(); 
        rc = hi.prev();
        output;
        rc = h.remove();
    end;

    rc=h.clear();

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 09:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621092#M77204</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-30T09:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to get  last two lastest transaction dates for each customer id in sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621123#M77206</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id date : date9. x;
format date date9.;
cards;
1 1jan2010 1
1 2jan2010 2
1 2jan2010 32
1 4feb2010 45
1 4feb2010 34
1 4dec2010 45
1 4dec2010 34
2 1jan2010 1
2 2jan2010 2
2 3jan2010 32
2 14feb2010 45
2 24feb2010 34
;
run;
proc sort data=test out=temp ;
by id descending date;
run;
data want;
 set temp;
 by id descending date;
 if first.id then n=0;
 n+first.date;
if n &amp;lt;= 2;
drop n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 13:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-get-last-two-lastest-transaction-dates-for-each-customer/m-p/621123#M77206</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-30T13:03:47Z</dc:date>
    </item>
  </channel>
</rss>

