<?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 where group by in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803146#M316244</link>
    <description>&lt;P&gt;Simplified version of the dataset I have is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;INPUT ID match1 $ match2 $ not_relevant;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 "ABC" "ABC" 4&lt;BR /&gt;1 "XYZ" "XYZ" 29&lt;BR /&gt;2 "QQQ" "AAA" 5&lt;BR /&gt;2 "ABC" "ABC" 9&lt;BR /&gt;3 "EFG" "EFG" 7&lt;BR /&gt;3 "DEF" "DEF" 12&lt;BR /&gt;3 "LMK" LMK" 16&lt;/P&gt;&lt;P&gt;;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to compare match1 and match2, and if anywhere in the ID column match1 does not equal match2, I would like to remove all of the rows with that ID. So for this example dataset I want to remove all of ID 2 (rows 3 and 4) since row 3 does not have a match between match1 and match2. All I can figure out how to do so far is to delete the rows where they dont match, which isnt terribly helpful for this application. I assume it would be easier to make it a new data set with some wheres but I am unsure how to begin there. Any ideas / advice?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 21 Mar 2022 16:45:30 GMT</pubDate>
    <dc:creator>mancel3</dc:creator>
    <dc:date>2022-03-21T16:45:30Z</dc:date>
    <item>
      <title>Delete where group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803146#M316244</link>
      <description>&lt;P&gt;Simplified version of the dataset I have is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;INPUT ID match1 $ match2 $ not_relevant;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 "ABC" "ABC" 4&lt;BR /&gt;1 "XYZ" "XYZ" 29&lt;BR /&gt;2 "QQQ" "AAA" 5&lt;BR /&gt;2 "ABC" "ABC" 9&lt;BR /&gt;3 "EFG" "EFG" 7&lt;BR /&gt;3 "DEF" "DEF" 12&lt;BR /&gt;3 "LMK" LMK" 16&lt;/P&gt;&lt;P&gt;;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to compare match1 and match2, and if anywhere in the ID column match1 does not equal match2, I would like to remove all of the rows with that ID. So for this example dataset I want to remove all of ID 2 (rows 3 and 4) since row 3 does not have a match between match1 and match2. All I can figure out how to do so far is to delete the rows where they dont match, which isnt terribly helpful for this application. I assume it would be easier to make it a new data set with some wheres but I am unsure how to begin there. Any ideas / advice?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 16:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803146#M316244</guid>
      <dc:creator>mancel3</dc:creator>
      <dc:date>2022-03-21T16:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Delete where group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803159#M316252</link>
      <description>&lt;P&gt;Apologies, I dumbed down my dataset too much and forgot about an important exception. New example is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;BR /&gt;INPUT ID match1 $ match2 $ not_relevant;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 "ABC" "ABC" 4&lt;BR /&gt;1 "XYZ" "XYZ" 29&lt;BR /&gt;2 "QQQ" "AAA" 5&lt;BR /&gt;2 "ABC" "ABC" 9&lt;BR /&gt;3 "EFG" "EFG" 7&lt;BR /&gt;3 "DEF" "DEF" 12&lt;BR /&gt;3 "LMK" LMK" 16&lt;BR /&gt;3 "KEF" .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 38&lt;/P&gt;&lt;P&gt;;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;note that I do NOT want to delete ID 3's here, since the match2 column is blank. I only want to delete the whole group when match2 is not blank, and it does not match with match1. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 17:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803159#M316252</guid>
      <dc:creator>mancel3</dc:creator>
      <dc:date>2022-03-21T17:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Delete where group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803180#M316259</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I redrafted the have data step, and used a blank to represent the missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the following work for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines dsd;
   
   input
      id           :  8.
      match1       : $8.
      match2       : $8.
      not_relevant :  8.
   ;
   
   datalines;
1,"ABC","ABC",4
1,"XYZ","XYZ",29
2,"QQQ","AAA",5
2,"ABC","ABC",9
3,"EFG","EFG",7
3,"DEF","DEF",12
3,"LMK","LMK",16
3,"KEF",,38
;

data want(drop = remove);
   do until (last.id);
      set have;
      by id;
      
      if match1 ne match2 and not missing(match2) then
         remove = 1;
   end;
   
   do until (last.id);
      set have;
      by id;
      
      if not remove then
         output;
   end;
run;   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 17:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803180#M316259</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2022-03-21T17:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Delete where group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803183#M316262</link>
      <description>&lt;P&gt;Alternative:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  have
  have (
    in=remove
    rename=(match1=_m1 match2=_m2)
    where=(_m1 ne _m2 and _m2 ne "")
  )
;
by id;
if not remove;
drop _m1 _m2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 17:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803183#M316262</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-21T17:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Delete where group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803187#M316263</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   merge have
         have (in = remove where = (match1 ne match2 and not missing(match2)));
   by id;
   if not remove;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 17:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803187#M316263</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2022-03-21T17:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete where group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803312#M316310</link>
      <description>&lt;PRE&gt;data have;
   infile datalines dsd;
   
   input
      id           :  8.
      match1       : $8.
      match2       : $8.
      not_relevant :  8.
   ;
   
   datalines;
1,"ABC","ABC",4
1,"XYZ","XYZ",29
2,"QQQ","AAA",5
2,"ABC","ABC",9
3,"EFG","EFG",7
3,"DEF","DEF",12
3,"LMK","LMK",16
3,"KEF",,38
;

proc sql;
create table want as
select * from have
 where id not in 
(select id from have where match1 ne match2 and
 match1 is not missing and match2 is not missing);
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2022 12:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-where-group-by/m-p/803312#M316310</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-22T12:11:58Z</dc:date>
    </item>
  </channel>
</rss>

