<?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: How to delete rows from table based on another table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841200#M332601</link>
    <description>&lt;P&gt;Thank you! Super easy way to do this, not sure how I didn't think of this.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Oct 2022 18:01:46 GMT</pubDate>
    <dc:creator>Sas_noob25</dc:creator>
    <dc:date>2022-10-27T18:01:46Z</dc:date>
    <item>
      <title>How to delete rows from table based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841190#M332593</link>
      <description>&lt;P&gt;I have a problem I'm trying to solve, and not really sure where to start.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two tables Table A and Table B. I'm trying to delete ALL of the customer IDs from Table A if they appear in Table B, but Table A sometimes has multiple entries for the same customer ID. My end result should be Table A with only records that are not in Table B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;Table A&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer ID&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5/7/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5/11/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;5/8/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;5/9/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;5/10/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5/11/2020&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table B&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer ID&lt;/TD&gt;&lt;TD&gt;Delete Flag&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example I would only want Customer ID C to show up in my final table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a few thousand rows of data in Table A that I'm checking against. Any help is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 17:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841190#M332593</guid>
      <dc:creator>Sas_noob25</dc:creator>
      <dc:date>2022-10-27T17:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows from table based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841193#M332595</link>
      <description>&lt;P&gt;This is relatively straightforward with a subquery like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I have altered the name of the variable "Customer ID". It can work as a named literal like this: 'Customer ID'n&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
   create table want as
   select * from A
  where customer_ID not in (select customer_ID from B);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Oct 2022 17:35:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841193#M332595</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2022-10-27T17:35:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows from table based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841194#M332596</link>
      <description>&lt;P&gt;If data size and performance is an issue, use a hash object:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set a;
if _n_ 01
then do;
  declare hash b (dataset:"b");
  b.definekey("customer_id");
  b.definedone();
end;
if b.check() ne 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Oct 2022 17:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841194#M332596</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-27T17:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows from table based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841195#M332597</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=tableB out=b_unique nodupkey;
by customerID;
run;

proc sort data=tableA;
by customerID;

data tableC;
merge tableA(in=ina) b_unique(in=inb drop=deleteflag);
by customerID;
if not inb;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A SQL way that will delete records from the table - test thoroughly before using something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tableA;
infile cards dlm='09'x;
input CustomerID  $	Date : ddmmyy10.;
format date date9.;
cards;
A	5/7/2020
A	5/11/2020
B	5/8/2020
B	5/9/2020
B	5/10/2020
C	5/11/2020
;;;;
run;

data tableB;
infile cards dlm='09'x;
input CustomerID $	DeleteFlag $;
cards;
B	Y
B	Y
A	Y
;;;;
run;

proc sql;
delete * from tableA where customerID  in (select distinct(CustomerID) from TableB);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Oct 2022 17:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841195#M332597</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-27T17:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows from table based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841200#M332601</link>
      <description>&lt;P&gt;Thank you! Super easy way to do this, not sure how I didn't think of this.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 18:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841200#M332601</guid>
      <dc:creator>Sas_noob25</dc:creator>
      <dc:date>2022-10-27T18:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete rows from table based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841201#M332602</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This step below worked as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt;proc sort data=tableB out=b_unique nodupkey;
by customerID;
run;

proc sort data=tableA;
by customerID;

data tableC;
merge tableA(in=ina) b_unique(in=inb drop=deleteflag);
by customerID;
if not inb;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Oct 2022 18:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-rows-from-table-based-on-another-table/m-p/841201#M332602</guid>
      <dc:creator>Sas_noob25</dc:creator>
      <dc:date>2022-10-27T18:12:21Z</dc:date>
    </item>
  </channel>
</rss>

