<?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: Using first. and last. to determine sections of data to remove or keep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255933#M48959</link>
    <description>&lt;P&gt;You can assign a counter variable, and limit the output to the first group of dt.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check;
    set test;
    by dt dt2;&lt;BR /&gt;    format dt dt2 mmddyy10.;
	if first.dt then counter+1;
	if counter=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 10 Mar 2016 20:55:11 GMT</pubDate>
    <dc:creator>DanZ</dc:creator>
    <dc:date>2016-03-10T20:55:11Z</dc:date>
    <item>
      <title>Using first. and last. to determine sections of data to remove or keep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255929#M48957</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
     format dt date9;
     format dt2 date9;
     input dt dt2;
     datalines;
     20000 20001
     20000 20002
     20000 20003
     21000 21001
     21000 21002
     21000 21003
     21000 21004
     21000 21005
     ;
run;

proc sort data = test;
     by dt dt2;
run;

data check;
    set test;
    by dt dt2;
    if last.dt = first.dt then
         if abs(last.dt2 - first.dt) &amp;lt; 5 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I would like to happen is the section of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 20000 20001
 20000 20002
 20000 20003&lt;/PRE&gt;&lt;P&gt;dates to all be deleted and the next section&lt;/P&gt;&lt;PRE&gt;  21000 21001
  21000 21002
  21000 21003
  21000 21004
  21000 21005&lt;/PRE&gt;&lt;P&gt;to all be retained. How can I get this to work?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2016 20:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255929#M48957</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-03-10T20:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using first. and last. to determine sections of data to remove or keep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255933#M48959</link>
      <description>&lt;P&gt;You can assign a counter variable, and limit the output to the first group of dt.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check;
    set test;
    by dt dt2;&lt;BR /&gt;    format dt dt2 mmddyy10.;
	if first.dt then counter+1;
	if counter=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Mar 2016 20:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255933#M48959</guid>
      <dc:creator>DanZ</dc:creator>
      <dc:date>2016-03-10T20:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using first. and last. to determine sections of data to remove or keep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255934#M48960</link>
      <description>Where do I add that to my current set up? Or is this a new data step?</description>
      <pubDate>Thu, 10 Mar 2016 20:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255934#M48960</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-03-10T20:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using first. and last. to determine sections of data to remove or keep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255935#M48961</link>
      <description>Oh, sorry. I should have put if counter = 2. Replace your check datastep.&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Mar 2016 20:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/255935#M48961</guid>
      <dc:creator>DanZ</dc:creator>
      <dc:date>2016-03-10T20:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using first. and last. to determine sections of data to remove or keep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/256034#M49012</link>
      <description>&lt;P&gt;This condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.dt = first.dt&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;can only be true when there is only &lt;U&gt;one&lt;/U&gt; observation in the current BY (dt) group. When you process the last observation of a by group containing multiple observations, only last. is true, and in the next observation only first. will be true.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 08:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/256034#M49012</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-11T08:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using first. and last. to determine sections of data to remove or keep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/256094#M49027</link>
      <description>&lt;P&gt;Your suggestion doesn't yield the desired outcome. This is also a toy problem so we won't have the luxury of saying counter occurrence # is desired.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 12:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/256094#M49027</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-03-11T12:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using first. and last. to determine sections of data to remove or keep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/256095#M49028</link>
      <description>&lt;P&gt;How can I do what I am looking to do though?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 12:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/256095#M49028</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-03-11T12:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using first. and last. to determine sections of data to remove or keep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/256105#M49031</link>
      <description>&lt;P&gt;Here is a solution I have that worked now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check;
    set test;
    by dt dt2;
	format dt dt2 date9.;
	diff = abs(dt - dt2);
	if diff &amp;lt; 5 then delete;
	if last.dt then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2016 13:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-to-determine-sections-of-data-to-remove-or/m-p/256105#M49031</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-03-11T13:26:45Z</dc:date>
    </item>
  </channel>
</rss>

