<?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: Match and remove rows in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828446#M35426</link>
    <description>&lt;P&gt;Are the data sorted?&amp;nbsp; If so, and if data set 2 never has more than one observation per id, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge ds1 (in=in1)    ds2 (keep=id  in=in2);
  by id;
  if in1=in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 12 Aug 2022 12:23:02 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-08-12T12:23:02Z</dc:date>
    <item>
      <title>Match and remove rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828422#M35420</link>
      <description>&lt;P&gt;Hi guys, is there a way to remove rows in a file that are not present in a second file by matching the column ID?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example suppose to have:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data set1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AGE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Role&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35-50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 55-60&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35-50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35-50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35-50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; E&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and data set2&lt;/P&gt;&lt;P&gt;&amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Hours&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vacancies&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;900&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 21&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 54&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 45&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like the data set1 to become:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AGE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Role&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 55-60&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35-50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;005&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35-50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; E&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 08:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828422#M35420</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-08-12T08:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Match and remove rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828424#M35421</link>
      <description>&lt;P&gt;Yes there is. Please show us some data. Makes it much easier to provide a usable code answer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 08:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828424#M35421</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-12T08:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Match and remove rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828427#M35422</link>
      <description>&lt;P&gt;Use a &lt;A href="https://documentation.sas.com/doc/de/pgmsascdc/9.4_3.4/lecompobjref/part-2.htm" target="_blank" rel="noopener"&gt;hash&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set ds1;
if _n_ = 1
then do;
  declare hash ds2 (dataset:"ds2");
  ds2.definekey("id");
  ds2.definedone();
end;
if ds2.check() = 0; /* CHECK method returns zero if successful */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, provide example data in data steps with datalines.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 09:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828427#M35422</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-12T09:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Match and remove rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828429#M35423</link>
      <description>&lt;P&gt;Here is two different approaches with the same result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Example Data */
data set1;
input ID $ AGE $ Role $;
datalines;
001 35-50 A 
002 55-60 B 
003 35-50 C 
004 35-50 D 
005 35-50 E 
;

data set2;
input ID $ Hours Vacancies;
datalines;
002 900 21 
003 456 54 
005 45  0  
;

/* Proc SQL Approach */
proc sql;
   create table want as
   select set1.*
   from set1, set2
   where set1.ID = set2.ID
   ;
quit;

/* Data Step Hash Approach */
data want;
   if _N_ = 1 then do;
      dcl hash h(dataset : 'set2');
      h.definekey('ID');
      h.definedone();
   end;

   set set1;

   if h.check() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Aug 2022 10:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828429#M35423</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-12T10:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Match and remove rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828442#M35425</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Example Data */
data set1;
input ID $ AGE $ Role $;
datalines;
001 35-50 A 
002 55-60 B 
003 35-50 C 
004 35-50 D 
005 35-50 E 
;

data set2;
input ID $ Hours Vacancies;
datalines;
002 900 21 
003 456 54 
005 45  0  
;

/* Proc SQL Approach */
proc sql;
   create table want as
   select set1.*
   from set1
   where ID in (select ID from set2)
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Aug 2022 12:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828442#M35425</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-08-12T12:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Match and remove rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828446#M35426</link>
      <description>&lt;P&gt;Are the data sorted?&amp;nbsp; If so, and if data set 2 never has more than one observation per id, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge ds1 (in=in1)    ds2 (keep=id  in=in2);
  by id;
  if in1=in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Aug 2022 12:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Match-and-remove-rows/m-p/828446#M35426</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-08-12T12:23:02Z</dc:date>
    </item>
  </channel>
</rss>

