<?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: Selecting the 2nd occurance in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584431#M166491</link>
    <description>&lt;P&gt;Ok. Have you tried the code I posted above?&lt;/P&gt;</description>
    <pubDate>Wed, 28 Aug 2019 05:37:49 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-08-28T05:37:49Z</dc:date>
    <item>
      <title>Selecting the 2nd occurance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584426#M166487</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me on how to select only the 2nd occurrence from a dataset? Below is an example. Kind regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Account&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;InterestRate&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;InterestRate_ChangeDate&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20001562&lt;/TD&gt;&lt;TD&gt;4.89%&lt;/TD&gt;&lt;TD&gt;19-Nov-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20001562&lt;/TD&gt;&lt;TD&gt;4.55%&lt;/TD&gt;&lt;TD&gt;22-Nov-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20006956&lt;/TD&gt;&lt;TD&gt;5.27%&lt;/TD&gt;&lt;TD&gt;11-Sep-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20006956&lt;/TD&gt;&lt;TD&gt;5.25%&lt;/TD&gt;&lt;TD&gt;1-Nov-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20006956&lt;/TD&gt;&lt;TD&gt;5.27%&lt;/TD&gt;&lt;TD&gt;8-Nov-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20009898&lt;/TD&gt;&lt;TD&gt;5.43%&lt;/TD&gt;&lt;TD&gt;18-Sep-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20009898&lt;/TD&gt;&lt;TD&gt;5.44%&lt;/TD&gt;&lt;TD&gt;18-Oct-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20009898&lt;/TD&gt;&lt;TD&gt;5.55%&lt;/TD&gt;&lt;TD&gt;18-Nov-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20009898&lt;/TD&gt;&lt;TD&gt;5.61%&lt;/TD&gt;&lt;TD&gt;18-Dec-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20009898&lt;/TD&gt;&lt;TD&gt;5.00%&lt;/TD&gt;&lt;TD&gt;18-Jan-19&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 05:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584426#M166487</guid>
      <dc:creator>Timbim</dc:creator>
      <dc:date>2019-08-28T05:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the 2nd occurance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584427#M166488</link>
      <description>&lt;P&gt;Do you mean simply the second observation? Or the second occurrence inside each account?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 05:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584427#M166488</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-28T05:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the 2nd occurance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584428#M166489</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Account InterestRate :percent. InterestRate_ChangeDate :date11.;
format InterestRate percent8.2 InterestRate_ChangeDate date11.;
datalines;
20001562 4.89% 19-Nov-18
20001562 4.55% 22-Nov-18
20006956 5.27% 11-Sep-18
20006956 5.25% 1-Nov-18
20006956 5.27% 8-Nov-18
20009898 5.43% 18-Sep-18
20009898 5.44% 18-Oct-18
20009898 5.55% 18-Nov-18
20009898 5.61% 18-Dec-18
20009898 5.00% 18-Jan-19
;

data want;
	if _N_=1 then do;
		declare hash h();
		h.definekey('Account');
		h.definedata('c');
		h.definedone();
	end;

	set have;
	
	rc=h.check();
 
    if rc ne 0 then do;
       c=1;
       h.add();
    end;
    if rc=0 then do;
       rc=h.find();	c=c+1;
       if c=2 then output;;
       rc=h.replace();
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 06:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584428#M166489</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-28T06:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the 2nd occurance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584429#M166490</link>
      <description>The 2nd occurrence for the account.&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Aug 2019 05:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584429#M166490</guid>
      <dc:creator>Timbim</dc:creator>
      <dc:date>2019-08-28T05:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the 2nd occurance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584431#M166491</link>
      <description>&lt;P&gt;Ok. Have you tried the code I posted above?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 05:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584431#M166491</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-28T05:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the 2nd occurance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584433#M166492</link>
      <description>&lt;P&gt;Since you data is sorted by Account, you can also do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	do _N_=1 by 1 until (last.Account);
		set have;
		by Account;
		if _N_=2 then output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With the hash object code though, the data does not have to be sorted by Account.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 05:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584433#M166492</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-28T05:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the 2nd occurance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584476#M166493</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by account;
if first.account
then counter = 1;
else counter + 1;
if counter = 2;
drop counter;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;have needs to be sorted properly, of course.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 09:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-2nd-occurance/m-p/584476#M166493</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-28T09:06:57Z</dc:date>
    </item>
  </channel>
</rss>

