<?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: remove the observation when the date is within 5 days and retain the earliest date record among in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493216#M129717</link>
    <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;only between different type SMALL and BIG but not between themselves.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;What does this mean? Can you add an example in your data showing this case?&lt;/P&gt;</description>
    <pubDate>Thu, 06 Sep 2018 21:38:51 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-09-06T21:38:51Z</dc:date>
    <item>
      <title>remove the observation when the date is within 5 days and retain the earliest date record among them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493198#M129710</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA table1;
infile datalines DELIMITER=','; 
INFORMAT id 2. type $10. date date2 MMDDYY10. ; 

 INPUT id  date type date2;

format date date9.
       date2 date9.;
DATALINES;
1,02/09/2012,BIG,02/09/2012
2,05/16/2012,BIG,05/18/2012
2,06/18/2012,BIG,06/18/2012
2,06/18/2012,SMALL,	
3,08/08/2011,BIG,08/08/2012
3,09/13/2011,BIG,09/13/2012
4,06/08/2016,BIG,06/12/2016	
5,08/16/2012,BIG,08/16/2012
5,08/15/2012,SMALL,	
6,09/05/2012,BIG,09/06/2012
7,09/05/2012,BIG,09/05/2012
7,02/13/2013,BIG,02/13/2013
7,08/03/2011,BIG,08/03/2011
7,05/09/2012,BIG,05/09/2012
7,04/24/2013,SMALL,	
8,03/31/2017,BIG,04/01/2017
8,03/06/2017,SMALL,	
9,02/17/2016,SMALL,	

;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to remove the observation if in our example of id 5 date is&amp;nbsp; 8/16/2012 for BIG type while for the same id type SMALL is 8/15/2012 the difference in date is 1 thus I would like to remove that observation which is greater and less than 5 days apart. So my dataset has to give only one record for id 5&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;5,08/15/2012,SMALL, but not&amp;nbsp;5,08/16/2012,BIG,08/16/2012&lt;/P&gt;&lt;P&gt;only between different type SMALL and BIG but not between themselves.&lt;/P&gt;&lt;P&gt;Sas EG-7.12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 20:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493198#M129710</guid>
      <dc:creator>Vk_2</dc:creator>
      <dc:date>2018-09-06T20:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: remove the observation when the date is within 5 days and retain the earliest date record among</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493216#M129717</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;only between different type SMALL and BIG but not between themselves.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;What does this mean? Can you add an example in your data showing this case?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 21:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493216#M129717</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-06T21:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: remove the observation when the date is within 5 days and retain the earliest date record among</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493217#M129718</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=table1; by id date; run;

data want;
do until(last.id);
    set table1; by id;
    if missing(lastDate) or intck("day", lastDate, date) &amp;gt; 5 then do;
        output;
        lastdate = date;
        end;
    end;
drop lastDate;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Sep 2018 21:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493217#M129718</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-06T21:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: remove the observation when the date is within 5 days and retain the earliest date record among</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493233#M129724</link>
      <description>If for an id there are 2 SMALL type or 2 BIG within 5 days I dont want to remove but if they are different type within 5 days then I would just want the earliest one</description>
      <pubDate>Fri, 07 Sep 2018 00:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493233#M129724</guid>
      <dc:creator>Vk_2</dc:creator>
      <dc:date>2018-09-07T00:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: remove the observation when the date is within 5 days and retain the earliest date record among</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493236#M129726</link>
      <description>I dont want to remove both of these like eg&lt;BR /&gt;7,09/05/2012,BIG,09/05/2012&lt;BR /&gt;7,09/07/2013,BIG,09/08/2013&lt;BR /&gt;though they are 2 days apart but not different type</description>
      <pubDate>Fri, 07 Sep 2018 01:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493236#M129726</guid>
      <dc:creator>Vk_2</dc:creator>
      <dc:date>2018-09-07T01:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: remove the observation when the date is within 5 days and retain the earliest date record among</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493241#M129728</link>
      <description>This is not considering the type condition. If for an id there are 2 SMALL type or 2 BIG within 5 days I dont want to remove but if they are different type within 5 days then I would just want the earliest one. eg&lt;BR /&gt;7,09/05/2012,BIG,09/05/2012&lt;BR /&gt;7,09/07/2013,BIG,09/08/2013&lt;BR /&gt;though they are 2 days apart but not different type. Hence I dont want to remove these records</description>
      <pubDate>Fri, 07 Sep 2018 01:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493241#M129728</guid>
      <dc:creator>Vk_2</dc:creator>
      <dc:date>2018-09-07T01:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: remove the observation when the date is within 5 days and retain the earliest date record among</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493247#M129729</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=HAVE out=SORTED; 
  by ID DATE TYPE;
run;
data WANT; 
  set SORTED; 
  if ID=lag(ID) and TYPE ne lag(TYPE) and . &amp;lt; dif(DATE) &amp;lt; 5 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 02:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493247#M129729</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-07T02:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: remove the observation when the date is within 5 days and retain the earliest date record among</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493254#M129733</link>
      <description>&lt;P&gt;Is this it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA table1;
infile datalines dsd; 
INPUT id  date :mmddyy10. type :$10. date2 :MMDDYY10.;
format date date2 date9.;
DATALINES;
1,02/09/2012,BIG,02/09/2012
2,05/16/2012,BIG,05/18/2012
2,06/18/2012,BIG,06/18/2012
2,06/18/2012,SMALL,.          &amp;lt; drop : same date, different type
3,08/08/2011,BIG,08/08/2012
3,09/13/2011,BIG,09/13/2012
4,06/08/2016,BIG,06/12/2016	
5,08/16/2012,BIG,08/16/2012   &amp;lt; drop : one day apart, different type
5,08/15/2012,SMALL,.	
6,09/05/2012,BIG,09/06/2012
7,09/05/2012,BIG,09/05/2012
7,09/07/2012,BIG,09/07/2012   &amp;lt; Keep : two days apart but same type
7,02/13/2013,BIG,02/13/2013
7,08/03/2011,BIG,08/03/2011
7,05/09/2012,BIG,05/09/2012
7,04/24/2013,SMALL,.	
8,03/31/2017,BIG,04/01/2017
8,03/06/2017,SMALL,.	
9,02/17/2016,SMALL,.	
;

proc sort data=table1; by id date; run;

data want;
do until(last.id);
    set table1; by id;
    if  missing(lastDate) or 
        intck("day", lastDate, date) &amp;gt; 5  or 
        lastType = type then do;
            output;
            lastdate = date;
            lasttype = type;
            end;
    end;
drop last: ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 03:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-the-observation-when-the-date-is-within-5-days-and-retain/m-p/493254#M129733</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-07T03:21:23Z</dc:date>
    </item>
  </channel>
</rss>

