<?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 rows within a dataset that match on certain variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817350#M322638</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input sequence_num ID Date :ddmmyy10. payment;
format Date ddmmyy10.;
datalines;
1 1 1/1/2012   8  
2 1 1/2/2012   5  
3 1 1/2/2012  -5  
4 2 1/6/2012   7  
5 2 1/6/2012   7  
6 3 1/6/2012   13 
7 4 1/12/2012  10 
8 4 1/12/2012 -10 
;

proc sql;
   create table want as
   select * from have
   where payment not in
   (select payment * -1 from have)
   ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Jun 2022 19:31:30 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-06-09T19:31:30Z</dc:date>
    <item>
      <title>Delete rows within a dataset that match on certain variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817346#M322634</link>
      <description>&lt;P&gt;Update: selection solution actually doesn't work well in full data. See thread. Sorry for being hasty to accept a response!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with some payment data that has several variables in it (ID is the customer ID, date is the date of service, and payment is how much the customer paid). However, some of the payment data are refunds of prior purchases, that match the date of the original purchase but have a negative value of the purchase price. I need to remove both data rows of the purchase and the refund because it does not represent what was actually sold off by the end of the month. Below is an example of what I have and what I want. Note the "seqeunce_num" is just the row of the observation to make it easier to show what is deleted in the Want dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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&lt;TD&gt;1/12/2012&lt;/TD&gt;&lt;TD&gt;-10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;sequence_num&lt;/TD&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;payment&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/1/2012&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1/6/2012&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1/6/2012&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1/6/2012&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure what to do because using the nodupkey in proc sort only removes one of the claims (such as the refund) but not both (the original purchase and refund).&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 20:15:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817346#M322634</guid>
      <dc:creator>cmccor</dc:creator>
      <dc:date>2022-06-09T20:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows within a dataset that match on certain variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817350#M322638</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input sequence_num ID Date :ddmmyy10. payment;
format Date ddmmyy10.;
datalines;
1 1 1/1/2012   8  
2 1 1/2/2012   5  
3 1 1/2/2012  -5  
4 2 1/6/2012   7  
5 2 1/6/2012   7  
6 3 1/6/2012   13 
7 4 1/12/2012  10 
8 4 1/12/2012 -10 
;

proc sql;
   create table want as
   select * from have
   where payment not in
   (select payment * -1 from have)
   ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2022 19:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817350#M322638</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-06-09T19:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows within a dataset that match on certain variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817351#M322639</link>
      <description>&lt;P&gt;Updated: I thought this did work but when testing it on the larger data set, if two patients had matching sales, it would delete all of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need it to look within each patient and only delete the original purchase and refund if the date matches and the payment/refund amount are identical (given that one is positive and one is negative)&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 20:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817351#M322639</guid>
      <dc:creator>cmccor</dc:creator>
      <dc:date>2022-06-09T20:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows within a dataset that match on certain variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817353#M322640</link>
      <description>&lt;P&gt;You sure?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this seems to break it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input sequence_num ID Date :ddmmyy10. payment;
format Date ddmmyy10.;
datalines;
1 1 1/1/2012   8  
2 1 1/2/2012   5  
3 1 1/2/2012  -5  
3 2 1/2/2012  5 
4 2 1/6/2012   7  
5 2 1/6/2012   7  
6 3 1/6/2012   13 
7 4 1/12/2012  10 
8 4 1/12/2012 -10 
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2022 19:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817353#M322640</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-09T19:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows within a dataset that match on certain variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817357#M322641</link>
      <description>&lt;P&gt;I admit I got hasty in my response seeing it work on the smaller data sample I had pulled and when I tried it out on the larger data set it messed up. I need it to be within customers and be based on matching dates for them to make sure that they are the same sale and it's not just deleting any other sale.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 20:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817357#M322641</guid>
      <dc:creator>cmccor</dc:creator>
      <dc:date>2022-06-09T20:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows within a dataset that match on certain variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817438#M322668</link>
      <description>&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-with-the-same-absolute-value-in-PROC-SQL/td-p/816621" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-with-the-same-absolute-value-in-PROC-SQL/td-p/816621&lt;/A&gt;</description>
      <pubDate>Fri, 10 Jun 2022 12:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817438#M322668</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-10T12:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows within a dataset that match on certain variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817486#M322682</link>
      <description>What's your ultimate goal here in the end? Calculate total sales and number of sales?&lt;BR /&gt;One easy method to achieve that add a variable, 1/-1 for each row. If the row is positive it's 1, if it's negative it's -1. To get the number of transactions sum the variable. To get the amounts, summing the amounts will be fine. Average? Use the variable as weights. &lt;BR /&gt;&lt;BR /&gt;If the transactions are always on the same date this works fine.</description>
      <pubDate>Fri, 10 Jun 2022 15:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-within-a-dataset-that-match-on-certain-variables/m-p/817486#M322682</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-10T15:11:37Z</dc:date>
    </item>
  </channel>
</rss>

