<?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: Eliminate record without know when to stop the process in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247370#M309424</link>
    <description>&lt;P&gt;Oh this code works, but I feel that it is quite weird the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sort data=have ; by decending time;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have nobs=nobs;&lt;BR /&gt;i+1;&lt;BR /&gt;del=0;&lt;BR /&gt;do j=i+1 to i+20 until (found=1);&lt;BR /&gt;set have (keep=enter exit time rename=(enter=ent exit=ext time=t)) point=j;&lt;BR /&gt; if enter&amp;lt;ext then do;&lt;BR /&gt; del=1;&lt;BR /&gt; found=1;&lt;BR /&gt; end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want; set want;&lt;BR /&gt;if time=1 then del=0;&lt;BR /&gt;if del=1 then delete;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort; by time;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Feb 2016 03:33:53 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2016-02-02T03:33:53Z</dc:date>
    <item>
      <title>Eliminate record without know when to stop the process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247364#M309423</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My problem is that I have a list of customer with the time/id_order when they come to me. Each of them has the time they plan&amp;nbsp;to see a doctor&amp;nbsp;and when they plan to leave.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The thing is that this doctor can only meet one at a time. So basically, the enter value of a certain record must be larger than the value of exit for previous record.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If I have to do it manually, I will keep running the process of:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;lag_exit=lag(exit);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if enter&amp;lt;lag_exit then delete;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;untill the size of the data remain the same, no more delete.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you help me to make it automatically run by SAS?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you so much.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have; input id_order&amp;nbsp;enter exit; &lt;BR /&gt;cards;&lt;BR /&gt; 1 1 5&lt;BR /&gt; 2 7 20&lt;BR /&gt; 3 11 15&lt;BR /&gt; 4 18 22&lt;BR /&gt; 5 22 43&lt;BR /&gt; 6 25 100&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort; by &lt;SPAN&gt;id_order&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have; set have;&lt;BR /&gt;lag_exit=lag(exit);&lt;BR /&gt;if enter&amp;lt;lag_exit then delete;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want; set have;&lt;BR /&gt;lag_exit=lag(exit);&lt;BR /&gt;if enter&amp;lt;lag_exit then delete;run;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 03:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247364#M309423</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-02T03:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Eliminate record without know when to stop the process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247370#M309424</link>
      <description>&lt;P&gt;Oh this code works, but I feel that it is quite weird the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sort data=have ; by decending time;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have nobs=nobs;&lt;BR /&gt;i+1;&lt;BR /&gt;del=0;&lt;BR /&gt;do j=i+1 to i+20 until (found=1);&lt;BR /&gt;set have (keep=enter exit time rename=(enter=ent exit=ext time=t)) point=j;&lt;BR /&gt; if enter&amp;lt;ext then do;&lt;BR /&gt; del=1;&lt;BR /&gt; found=1;&lt;BR /&gt; end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want; set want;&lt;BR /&gt;if time=1 then del=0;&lt;BR /&gt;if del=1 then delete;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort; by time;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 03:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247370#M309424</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-02T03:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Eliminate record without know when to stop the process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247374#M309425</link>
      <description>&lt;P&gt;I love this question. But you didn't post the output you want yet .&lt;/P&gt;
&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 id_order enter exit; 
cards;
1 1 5
2 7 20
3 11 15
4 18 22
5 22 43
6 25 100
;
run;
data _null_;
if 0 then set have;
declare hash h(dataset:'have',ordered:'a');
declare hiter hi('h');
h.definekey('id_order');
h.definedata(all:'y');
h.definedone();

do while(hi.next()=0);
 n+1;
 rc=h.remove(key:id);
 if enter lt lag_exit and n ne 1 then id=id_order;
  else lag_exit=exit;
end;
 rc=h.remove(key:id);
h.output(dataset:'want');
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2016 06:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247374#M309425</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-02-02T06:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Eliminate record without know when to stop the process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247386#M309426</link>
      <description>&lt;P&gt;What about:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by enter;
run;

data want;
set have;
retain lag_exit .;
if lag_exit &amp;gt; enter then delete;
else lag_exit = exit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2016 09:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247386#M309426</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-02-02T09:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Eliminate record without know when to stop the process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247392#M309427</link>
      <description>&lt;P&gt;Just a couple of tips as I couldnt read that code. &amp;nbsp;Use the code window - {i} in the post icons - this will preserve the indetation. &amp;nbsp;Also format the code for readability and avoid typo's:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have; 
  by descending time;  /* Note the typo correction */
run;
 
data want;
  set have nobs=nobs;
  i+1;
  del=0;
  do j=i+1 to i+20 until (found=1);
    set have (keep=enter exit time rename=(enter=ent exit=ext time=t)) point=j;
    if enter&amp;lt;ext then do;
      del=1;
      found=1;
    end;
  end;
run;
 
data want; 
  set want;
  if time=1 then del=0;
  if del=1 then delete;
run;
 
proc sort; 
  by time;
run;&lt;/PRE&gt;
&lt;P&gt;As for your actualy code, you may be simpler off doing:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  delete from HAVE
  where exit &amp;lt; (select lag_exit from HAVE);
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2016 10:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247392#M309427</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-02T10:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Eliminate record without know when to stop the process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247527#M309428</link>
      <description>&lt;P&gt;that is amazing code!&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 16:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eliminate-record-without-know-when-to-stop-the-process/m-p/247527#M309428</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-02T16:29:49Z</dc:date>
    </item>
  </channel>
</rss>

