<?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 Delete pair of observations for negative claims in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903651#M2696</link>
    <description>&lt;P&gt;I have the data in following format:&lt;BR /&gt;data have;&lt;BR /&gt;input id date :date9. Supply drug $;&lt;BR /&gt;datalines;&lt;BR /&gt;&lt;STRONG&gt;1 03JAN19 90 AB&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 02JAN19 -90 AB&lt;/STRONG&gt; &lt;BR /&gt;2 15FEB2019 30 AB &lt;BR /&gt;&lt;STRONG&gt;3 02JAN19 30 AB &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 05JAN19 -30 AB&lt;/STRONG&gt; &lt;BR /&gt;3 30MAR19 30 AB &lt;BR /&gt;4 03APR19 60 AB &lt;BR /&gt;5 01JAN19 60 CD &lt;BR /&gt;&lt;STRONG&gt;5 02FEB19 60 CD &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 06FEB19 -60 CD&lt;/STRONG&gt; &lt;BR /&gt;6 01MAR19 30 CD &lt;BR /&gt;6 01APR19 30 CD &lt;BR /&gt;7 01JAN19 60 CD &lt;BR /&gt;&lt;EM&gt;7 02FEB19 60 CD &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;7 06FEB19 -60 XY&lt;/EM&gt; &lt;BR /&gt;8 01MAR19 30 CD &lt;BR /&gt;8 01APR19 30 CD &lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;I need help with deleting negative supply of same drug in this data (the first and second observation for ID 1, the first and second observation for ID 3, second and third observation of ID 5 in this example, but not for second and third observation of ID 7), considering the second observations are actually a refund or reversal of the earlier observation (reversal within 7days of a visit).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks in advance for the help.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Nov 2023 13:58:48 GMT</pubDate>
    <dc:creator>dac_js</dc:creator>
    <dc:date>2023-11-17T13:58:48Z</dc:date>
    <item>
      <title>Delete pair of observations for negative claims</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903651#M2696</link>
      <description>&lt;P&gt;I have the data in following format:&lt;BR /&gt;data have;&lt;BR /&gt;input id date :date9. Supply drug $;&lt;BR /&gt;datalines;&lt;BR /&gt;&lt;STRONG&gt;1 03JAN19 90 AB&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 02JAN19 -90 AB&lt;/STRONG&gt; &lt;BR /&gt;2 15FEB2019 30 AB &lt;BR /&gt;&lt;STRONG&gt;3 02JAN19 30 AB &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 05JAN19 -30 AB&lt;/STRONG&gt; &lt;BR /&gt;3 30MAR19 30 AB &lt;BR /&gt;4 03APR19 60 AB &lt;BR /&gt;5 01JAN19 60 CD &lt;BR /&gt;&lt;STRONG&gt;5 02FEB19 60 CD &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 06FEB19 -60 CD&lt;/STRONG&gt; &lt;BR /&gt;6 01MAR19 30 CD &lt;BR /&gt;6 01APR19 30 CD &lt;BR /&gt;7 01JAN19 60 CD &lt;BR /&gt;&lt;EM&gt;7 02FEB19 60 CD &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;7 06FEB19 -60 XY&lt;/EM&gt; &lt;BR /&gt;8 01MAR19 30 CD &lt;BR /&gt;8 01APR19 30 CD &lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;I need help with deleting negative supply of same drug in this data (the first and second observation for ID 1, the first and second observation for ID 3, second and third observation of ID 5 in this example, but not for second and third observation of ID 7), considering the second observations are actually a refund or reversal of the earlier observation (reversal within 7days of a visit).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks in advance for the help.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 13:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903651#M2696</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2023-11-17T13:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations for negative claims</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903745#M2697</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/354291"&gt;@dac_js&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the data in following format:&lt;BR /&gt;data have;&lt;BR /&gt;input id date :date9. Supply drug $;&lt;BR /&gt;datalines;&lt;BR /&gt;&lt;STRONG&gt;1 03JAN19 90 AB&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;2 02JAN19 -90 AB&lt;/STRONG&gt; &lt;BR /&gt;2 15FEB2019 30 AB &lt;BR /&gt;&lt;STRONG&gt;3 02JAN19 30 AB &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;3 05JAN19 -30 AB&lt;/STRONG&gt; &lt;BR /&gt;3 30MAR19 30 AB &lt;BR /&gt;4 03APR19 60 AB &lt;BR /&gt;5 01JAN19 60 CD &lt;BR /&gt;&lt;STRONG&gt;5 02FEB19 60 CD &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;5 06FEB19 -60 CD&lt;/STRONG&gt; &lt;BR /&gt;6 01MAR19 30 CD &lt;BR /&gt;6 01APR19 30 CD &lt;BR /&gt;7 01JAN19 60 CD &lt;BR /&gt;&lt;EM&gt;7 02FEB19 60 CD &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;7 06FEB19 -60 XY&lt;/EM&gt; &lt;BR /&gt;8 01MAR19 30 CD &lt;BR /&gt;8 01APR19 30 CD &lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;I need help with deleting negative supply of same drug in this data (the first and second observation for ID 1, the first and second observation for ID 3, second and third observation of ID 5 in this example, but not for second and third observation of ID 7), considering the second observations are actually a refund or reversal of the earlier observation (reversal within 7days of a visit).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks in advance for the help.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But there is no "second observation for ID 1" in your sample data.&amp;nbsp; I presume the second obs in your sample should have ID=1&amp;nbsp; (not ID=2).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date :date9. Supply drug $;
format date date9.;
datalines;
1 03JAN19 90 AB
1 02JAN19 -90 AB
2 15FEB2019 30 AB
3 02JAN19 30 AB
3 05JAN19 -30 AB
3 30MAR19 30 AB
4 03APR19 60 AB
5 01JAN19 60 CD
5 02FEB19 60 CD
5 06FEB19 -60 CD
6 01MAR19 30 CD
6 01APR19 30 CD
7 01JAN19 60 CD
7 02FEB19 60 CD
7 06FEB19 -60 XY
8 01MAR19 30 CD
8 01APR19 30 CD
;

data want (drop=_:);
  set have (keep=id drug);
  by id drug  notsorted;
  merge have have (firstobs=2 keep=supply rename=(supply=_nxt_supply));

  retain _matches_prior_obs 0 ;
  /*If _matches prior obs or matches next obs, then do two things*/
  if _matches_prior_obs=1 or (-1*supply=_nxt_supply and last.drug=0) then do;
    delete;
    _matches_prior_obs=ifn(_matches_prior_obs=1,0,1);
  end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The program assumes that the matching pairs are always adjacent observations.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Nov 2023 00:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903745#M2697</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-11-18T00:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations for negative claims</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903774#M2698</link>
      <description>Thank you for your suggestion. I tried it, but it didn't work as expected. I  still have the negative values. Could you possibly offer any further guidance or an alternative solution? Thanks again for your help.</description>
      <pubDate>Sat, 18 Nov 2023 15:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903774#M2698</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2023-11-18T15:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations for negative claims</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903789#M2699</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/354291"&gt;@dac_js&lt;/a&gt;&amp;nbsp;I suggest to first try and create sample data that's fully representative for your real data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I assume the first two rows you've posted..&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1700355775791.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89987i9191C5AA218864D7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1700355775791.png" alt="Patrick_0-1700355775791.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;...should actually look like:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1700355829150.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89988i5BF26695A0D313F1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1700355829150.png" alt="Patrick_1-1700355829150.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Could there also be additional scenarios in your real data? Like a single correction for two wrong entries?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_2-1700355933763.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89989i551265F248E9352B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_2-1700355933763.png" alt="Patrick_2-1700355933763.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;...or is it possible that you've got a single summary correction for two wrong entries?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are corrections always after the fact or is it possible in your real data that a correction has been entered by mistake (a minus value) that then gets fixed with a positive value at a later date?&lt;/P&gt;
&lt;P&gt;....and so on...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to provide code logic that will work for all your cases you need to provide sample data that reflects all the possible cases in your real data and of course you also need to tell us how to treat these cases.&lt;/P&gt;
&lt;P&gt;Below some sample code that creates data for additional scenarios. Please amend this data as required so it reflects what you're really dealing with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date :date9. Supply drug $;
  format date date9.;
datalines;
1 02JAN19 90 AB
1 03JAN19 -90 AB
2 15FEB2019 30 AB
3 02JAN19 30 AB
3 05JAN19 -30 AB
3 30MAR19 30 AB
4 03APR19 60 AB
5 01JAN19 60 CD
5 02FEB19 60 CD
5 06FEB19 -60 CD
6 01MAR19 30 CD
6 01APR19 30 CD
7 01JAN19 60 CD
7 02FEB19 60 CD
7 06FEB19 -60 XY
8 01MAR19 30 CD
8 01APR19 30 CD
09 01apr19 -10 aa
09 02apr19 20  aa
10 01apr19 10  bb
10 02apr19 20  bb
10 03apr19 -10 bb
11 01apr19 10  cc
11 02apr19 10  cc
11 03apr19 -20 cc
12 02jan19 -90 dd
12 03jan19 90  dd
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 01:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903789#M2699</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-19T01:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations for negative claims</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903791#M2700</link>
      <description>&lt;P&gt;This version of the code includes a date range check.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date :date9. Supply drug $;
format date date9.;
datalines;
1 03JAN19 90 AB
1 02JAN19 -90 AB
2 15FEB2019 30 AB
3 02JAN19 30 AB
3 05JAN19 -30 AB
3 30MAR19 30 AB
4 03APR19 60 AB
5 01JAN19 60 CD
5 02FEB19 60 CD
5 06FEB19 -60 CD
6 01MAR19 30 CD
6 01APR19 30 CD
7 01JAN19 60 CD
7 02FEB19 60 CD
7 06FEB19 -60 XY
8 01MAR19 30 CD
8 01APR19 30 CD
;

data want (drop=_:);
  set have (keep=id drug);
  by id drug  notsorted;
  merge have 
        have (firstobs=2 keep=supply date rename=(date=_nxt_date supply=_nxt_supply));

  retain _delete_count 0 ;
  if last.drug=0 and supply&amp;gt;0 and -1*supply=_nxt_supply and _nxt_date&amp;lt;=date+7 then _delete_count=2;

  if _delete_count=0 then output;
  else _delete_count=_delete_count-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This program assumes data are grouped by ID and DRUG, and are sorted by ascending date within each ID/DRUG group.&amp;nbsp; I take it that obs 2, had the wrong date, but I left it there.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 05:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903791#M2700</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-11-19T05:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations for negative claims</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903809#M2701</link>
      <description>&lt;P&gt;Thank you very much for your response! You are right about the first two rows of sample data&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The cases I provided is more common but it is possible to have cases like this:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;11 01apr19 10  cc
11 02apr19 10  cc
11 03apr19 -20 cc&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The following type we do not need to deal with:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;12 02jan19 -90 dd
12 03jan19 90  dd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 16:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903809#M2701</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2023-11-19T16:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations for negative claims</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903836#M2702</link>
      <description>&lt;P&gt;Test if below does it for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date :date9. Supply drug $;
  format date date9.;
datalines;
1 01JAN19 30 AB
1 02JAN19 90 AB
1 03JAN19 -100 AB
1 04JAN19 -10 AB
2 15FEB2019 30 AB
3 02JAN19 30 AB
3 05JAN19 40 AB
3 30MAR19 30 AB
4 03APR19 60 AB
5 01JAN19 60 CD
5 02FEB19 60 CD
5 06FEB19 -60 CD
6 01MAR19 30 CD
6 01APR19 30 CD
7 01JAN19 60 CD
7 02FEB19 60 CD
7 06FEB19 -60 XY
8 01MAR19 30 CD
8 01APR19 30 CD
10 01apr19 10  bb
10 02apr19 20  bb
10 03apr19 -10 bb
11 01apr19 10  cc
11 02apr19 10  cc
11 03apr19 -20 cc
;

proc sort data=have out=inter;
  by id drug descending date descending Supply;
run;

data want(drop=_:);
  set inter;
  by id drug;
  retain _correction;
  if first.drug then _correction=0;

  if supply&amp;lt;0 then _correction=sum(_correction,supply);
  else
    do;
      _Supply_adjusted=sum(supply,_correction);
      _correction      =min(sum(_correction,supply),0);
      if _Supply_adjusted&amp;gt;0 then 
        do;
          supply=_Supply_adjusted;
          output;
        end;
    end;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Nov 2023 04:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903836#M2702</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-20T04:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: Delete pair of observations for negative claims</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903839#M2703</link>
      <description>&lt;P&gt;Thank you! Your code is working.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 05:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Delete-pair-of-observations-for-negative-claims/m-p/903839#M2703</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2023-11-20T05:09:49Z</dc:date>
    </item>
  </channel>
</rss>

