<?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 Finding first occurrence within a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurrence-within-a-dataset/m-p/434657#M281968</link>
    <description>&lt;P&gt;I have the following dataset where I need to only have the first year (occurrence) where the count is &amp;gt;=2 (I also want to keep any subsequent years thereafter). For instance for ID1, I need data starting in FY12 and I also want to keep FY 13 - 15 because I know the index year for this ID is FY12. I would keep ID2 and keep ID3 starting at FY12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't figure out quite how to keep everything I need. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Count FY&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; 14&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Feb 2018 19:01:14 GMT</pubDate>
    <dc:creator>jsandsk</dc:creator>
    <dc:date>2018-02-06T19:01:14Z</dc:date>
    <item>
      <title>Finding first occurrence within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurrence-within-a-dataset/m-p/434657#M281968</link>
      <description>&lt;P&gt;I have the following dataset where I need to only have the first year (occurrence) where the count is &amp;gt;=2 (I also want to keep any subsequent years thereafter). For instance for ID1, I need data starting in FY12 and I also want to keep FY 13 - 15 because I know the index year for this ID is FY12. I would keep ID2 and keep ID3 starting at FY12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't figure out quite how to keep everything I need. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Count FY&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; 14&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 19:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurrence-within-a-dataset/m-p/434657#M281968</guid>
      <dc:creator>jsandsk</dc:creator>
      <dc:date>2018-02-06T19:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurrence within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurrence-within-a-dataset/m-p/434669#M281970</link>
      <description>&lt;P&gt;Assuming your data is in sorted order as shown:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if first.id then output_flag=0;&lt;/P&gt;
&lt;P&gt;if count &amp;gt;= 2 then output_flag + 1;&lt;/P&gt;
&lt;P&gt;if output_flag;&lt;/P&gt;
&lt;P&gt;drop output_flag;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 19:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurrence-within-a-dataset/m-p/434669#M281970</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-06T19:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurrence within a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurrence-within-a-dataset/m-p/434685#M281971</link>
      <description>&lt;P&gt;one way to do this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

input @1 ID @5 Count @15 FY;
datalines;
1 1 10
1 1 11
1 3 12
1 1 13
1 12 14
1 2 15
2 2 11
3 1 11
3 7 12
3 2 13
3 1 14
;

proc sql;
create table want as
select a.* from 
(select * from have)a
inner join
(select id, min(FY) as min_fy from have
where count &amp;gt;= 2
group by id)b
on a.id = b.id
and a.fy &amp;gt;= b.min_fy;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 20:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurrence-within-a-dataset/m-p/434685#M281971</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-02-06T20:38:10Z</dc:date>
    </item>
  </channel>
</rss>

