<?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: Delete pair of observations based on positive and negative supply values in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700749#M2319</link>
    <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;BR /&gt;</description>
    <pubDate>Sun, 22 Nov 2020 14:48:37 GMT</pubDate>
    <dc:creator>dac_js</dc:creator>
    <dc:date>2020-11-22T14:48:37Z</dc:date>
    <item>
      <title>Delete pair of observations based on positive and negative supply values</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700733#M2315</link>
      <description>&lt;P&gt;data a1;&lt;/P&gt;&lt;P&gt;input ID date :date9. Supply;&lt;/P&gt;&lt;P&gt;format date date9.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 03JAN19&amp;nbsp;&amp;nbsp; 90&lt;/P&gt;&lt;P&gt;2 02JAN19&amp;nbsp;&amp;nbsp; 30&lt;/P&gt;&lt;P&gt;2 15FEB2019 30&lt;/P&gt;&lt;P&gt;3 02JAN19&amp;nbsp;&amp;nbsp; 30&lt;/P&gt;&lt;P&gt;3 05JAN19&amp;nbsp;&amp;nbsp; -30&lt;/P&gt;&lt;P&gt;3 30MAR19&amp;nbsp;&amp;nbsp; 30&lt;/P&gt;&lt;P&gt;4 03APR19&amp;nbsp;&amp;nbsp; 60&lt;/P&gt;&lt;P&gt;5 01FEB19&amp;nbsp;&amp;nbsp; 60&lt;/P&gt;&lt;P&gt;5 02FEB19&amp;nbsp;&amp;nbsp; 60&lt;/P&gt;&lt;P&gt;5 06FEB19&amp;nbsp;&amp;nbsp; -60&lt;/P&gt;&lt;P&gt;6 01MAR19&amp;nbsp;&amp;nbsp; 30&lt;/P&gt;&lt;P&gt;6 01APR19&amp;nbsp;&amp;nbsp; 30&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to delete pairs of observations where a negative value of supply appears within 7days of a positive value (the FIRST AND SECOND OBSERVATION of ID 3 and SECOND AND THIRD OBSERVATION of ID 5 in this example), considering the second observations are actually a refund of the earlier observation.&lt;/P&gt;&lt;P&gt;I have a code which is deleting all observations in a 7day window. In this example the code is deleting FIRST, SECOND AND THIRD OBSERVATIONS of ID 5. I need a code that deletes only the positive-negative pairs (to keep the first observation for ID 5).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2020 10:18:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700733#M2315</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2020-11-22T10:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations based on positive and negative supply values</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700735#M2316</link>
      <description>&lt;PRE&gt;data a1;
input ID date :date9. Supply;
format date date9.;
datalines;
1 03JAN19   90
2 02JAN19   30
2 15FEB2019 30
3 02JAN19   30
3 05JAN19   -30
3 30MAR19   30
4 03APR19   60
5 01FEB19   60
5 02FEB19   60
5 06FEB19   -60
6 01MAR19   30
6 01APR19   30
;

data have;
set a1;
n+1;
run;
data temp;
 set have;
 if id=lag(id) and dif(date)&amp;lt;=7 and supply&amp;lt;0 and supply=-lag(supply) ;
 keep n;
run;
data n;
 set temp;
 output;
 n=n-1;output;
run;
proc sql;
create table want(drop=n) as
select * from have 
 where n not in (select n from n);
quit;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Nov 2020 11:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700735#M2316</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-22T11:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations based on positive and negative supply values</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700746#M2317</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data a1;

input ID date :date9. Supply;

format date date9.;

datalines;

1 03JAN19   90

2 02JAN19   30

2 15FEB2019 30

3 02JAN19   30

3 05JAN19   -30

3 30MAR19   30

4 03APR19   60

5 01FEB19   60

5 02FEB19   60

5 06FEB19   -60

6 01MAR19   30

6 01APR19   30

;

data want;
 if _n_=1 then do;
  dcl hash h();
  h.definekey('supply');
  h.definedata('_iorc_');
  h.definedone();
 end;
 array t(-138061:2936547) _temporary_;
 call missing(of t(*),_iorc_);
 do _n_=1 by 1 until(last.id);
  set a1;
  by id;
  _iorc_=date;
  if sign(supply)=1 then h.replace();
  else if h.find(key:abs(supply))=0 then if intck('day',_iorc_,date)&amp;lt;=7 then do;
    t(date)=date;
    t(_iorc_)=_iorc_;
  end;
 end;
 do _n_=1 to _n_;
  set a1;
  if t(date) then continue;
  output;
 end;
 h.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Nov 2020 13:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700746#M2317</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-22T13:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations based on positive and negative supply values</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700748#M2318</link>
      <description>Thank you again.&lt;BR /&gt;Your code is working.&lt;BR /&gt;Is this possible to do it without using hash objects?&lt;BR /&gt;</description>
      <pubDate>Sun, 22 Nov 2020 14:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700748#M2318</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2020-11-22T14:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations based on positive and negative supply values</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700749#M2319</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 22 Nov 2020 14:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-based-on-positive-and-negative/m-p/700749#M2319</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2020-11-22T14:48:37Z</dc:date>
    </item>
  </channel>
</rss>

