<?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 a record if a matching record is found from the same dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258436#M49775</link>
    <description>&lt;P&gt;I would caution the approach, as you may not want to delete all the records associated, but going from the data you posted - and I would also point out that its a good idea to post test data in the form of a datastep as illustrated:&lt;/P&gt;
&lt;PRE&gt;data have;
	input vendor $ job $ grade payment;
datalines;
ABC	Boxes	01	3500.00
XYZ	Tape	01	2000.00
LMN	Straps	02	1500.00
ABC	Pins	02	1200.00
LMN	Straps	02	0.00
ABC	Boxes	01	3500.00
LMN	Straps	02	0.00
ABC	Boxes	01	0.00
;
run;

proc sql undopolicy=none;
  delete from HAVE A
  where exists(select distinct VENDOR from HAVE where VENDOR=A.VENDOR and JOB=A.JOB and PAYMENT=0);
quit;&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Mar 2016 09:29:33 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-03-23T09:29:33Z</dc:date>
    <item>
      <title>Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258427#M49769</link>
      <description>&lt;P&gt;I've come across a strange situation where I've to delete a record if there is any other record having the matching key variables. Any help would be highly appreciated.&amp;nbsp;My requirement is to drop both these records from further processing.&amp;nbsp;My sample data looks like below&amp;nbsp;where the fields&amp;nbsp;Vendor, Job and Grade are the key variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="296"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="40"&gt;&am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R&gt;
&lt;TR&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;LMN&lt;/TD&gt;
&lt;TD&gt;Straps&lt;/TD&gt;
&lt;TD&gt;02&lt;/TD&gt;
&lt;TD&gt;$0.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;ABC&lt;/TD&gt;
&lt;TD&gt;Boxes&lt;/TD&gt;
&lt;TD&gt;01&lt;/TD&gt;
&lt;TD&gt;$0.00&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;A record has to be dropped from further processing if there is another record anywhere in the table having the amount field(Payment) a value $0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Considering this the&amp;nbsp;record #1 for vendor ABC having Payment $3500 should be deleted because there is another record #8 where Payment is $0, but #6 having Payment $3500 should be processed because #8 is no more available as it is already&amp;nbsp;matched(/deleted along)&amp;nbsp;with #1. Similarly #5 for vendor LMN should also be dropped as there is a matching record at #7 having payment $0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 09:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258427#M49769</guid>
      <dc:creator>pawan</dc:creator>
      <dc:date>2016-03-23T09:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258436#M49775</link>
      <description>&lt;P&gt;I would caution the approach, as you may not want to delete all the records associated, but going from the data you posted - and I would also point out that its a good idea to post test data in the form of a datastep as illustrated:&lt;/P&gt;
&lt;PRE&gt;data have;
	input vendor $ job $ grade payment;
datalines;
ABC	Boxes	01	3500.00
XYZ	Tape	01	2000.00
LMN	Straps	02	1500.00
ABC	Pins	02	1200.00
LMN	Straps	02	0.00
ABC	Boxes	01	3500.00
LMN	Straps	02	0.00
ABC	Boxes	01	0.00
;
run;

proc sql undopolicy=none;
  delete from HAVE A
  where exists(select distinct VENDOR from HAVE where VENDOR=A.VENDOR and JOB=A.JOB and PAYMENT=0);
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2016 09:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258436#M49775</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-23T09:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258445#M49783</link>
      <description>You didn't post the result yet.

&lt;PRE&gt;
data have;
infile datalines expandtabs;
	input vendor $ job $ grade payment;
datalines;
ABC	Boxes	01	3500.00
XYZ	Tape	01	2000.00
LMN	Straps	02	1500.00
ABC	Pins	02	1200.00
LMN	Straps	02	0.00
ABC	Boxes	01	3500.00
LMN	Straps	02	0.00
ABC	Boxes	01	0.00
;
run;
proc sort data=have ;by vendor  job  grade;run;
data want;
 ina=0;inb=0;
 merge have(where=(payment ne 0) in=ina)
 have(rename=(payment=_payment) where=(_payment eq 0) in=inb);
 by vendor  job  grade;
 if not inb;
 run;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2016 09:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258445#M49783</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-23T09:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258470#M49799</link>
      <description>It worked like a Gem!! Thanks, but just wondering why are those 2 fields ina &amp;amp; inb, initialised 0's, not taken for output. How did they disappear? I'm not seeing a DROP here.. Anyways, thanks so much.</description>
      <pubDate>Wed, 23 Mar 2016 12:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258470#M49799</guid>
      <dc:creator>pawan</dc:creator>
      <dc:date>2016-03-23T12:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258473#M49800</link>
      <description>&lt;P&gt;Thanks RW9, Sorry for not mentioning my approach trials there but the solution provided&amp;nbsp;by Ksharp is really sharp and helped&amp;nbsp;in what I needed.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 12:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258473#M49800</guid>
      <dc:creator>pawan</dc:creator>
      <dc:date>2016-03-23T12:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258568#M49833</link>
      <description>&lt;P&gt;The In= dataset option creates a temporary variable whose value is not saved to the output dataset unless you explicitly assign it to another variable. There are several&amp;nbsp;options on a SET or INFILE statement that do this&amp;nbsp;also&amp;nbsp;such as END NOBS POINT EOV FILENAME FILEVAR LENGTH LINE&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 15:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258568#M49833</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-23T15:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258734#M49897</link>
      <description>&lt;P&gt;Yepp that is true but my question was why did Ksharp initialise those variables with 0's. Is the default&amp;nbsp;assignment different from&amp;nbsp;this? I didnt understand how did the behavior of this step changed completely with just inclusion of that "Initialisisng step".&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 06:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258734#M49897</guid>
      <dc:creator>pawan</dc:creator>
      <dc:date>2016-03-24T06:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258736#M49898</link>
      <description>By default,ina , inb will retain its value . 
I reset them to avoid such problem .</description>
      <pubDate>Thu, 24 Mar 2016 06:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258736#M49898</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-24T06:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a record if a matching record is found from the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258740#M49900</link>
      <description>&lt;P&gt;Oh! It makes sense now. Thanks a lot! And now I can throw my 100 lines of&amp;nbsp;code away into trash and just use this master piece!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 07:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-record-if-a-matching-record-is-found-from-the-same/m-p/258740#M49900</guid>
      <dc:creator>pawan</dc:creator>
      <dc:date>2016-03-24T07:22:06Z</dc:date>
    </item>
  </channel>
</rss>

