<?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: removing duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-removing-duplicates/m-p/860865#M340055</link>
    <description>&lt;P&gt;Hi...I am not quite getting what I need. I need to remove duplicate records.&amp;nbsp;The criteria for the removal is that for the grouping of ID, Term, Department and Section, if there is at least one record where the entry for Condition is blank, then all records having a "W" for Condition are to be deleted. If either all entries for condition are blank or "W", then all records need to kept.If anyone can help it would be greatly appreciated. thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
    length ID 8 Term $ 9 Department $ 5 Type $ 5 Section $ 5 Condition $ 2;
    format ID F12. Term $char9. Department $char5. Type $char5. Section $char5. Condition $char2.;
    informat ID best12. Term $char9. Department $char5. Type $char5. Section $char5. Condition $char2.;
    infile datalines4 dlm='7F'x missover dsd;
    input ID : best32. Term : $char9. Department : $char5. Type : $char5. Section : $char5. Condition  : $CHAR2. ;
datalines4;
174636&amp;#127;2022-2023&amp;#127;AST&amp;#127;Attnd&amp;#127;F22D1&amp;#127; 
174636&amp;#127;2022-2023&amp;#127;AST&amp;#127;Attnd&amp;#127;W22&amp;#127; 
96905&amp;#127;2020-2021&amp;#127;BAA&amp;#127;Attnd&amp;#127;S20&amp;#127;W
96905&amp;#127;2020-2021&amp;#127;BAA&amp;#127;Attnd&amp;#127;W21B2&amp;#127; 
156968&amp;#127;2021-2022&amp;#127;BAA&amp;#127;Attnd&amp;#127;F21B2&amp;#127;W
156968&amp;#127;2021-2022&amp;#127;BAA&amp;#127;Attnd&amp;#127;W22B2&amp;#127;W
160642&amp;#127;2020-2021&amp;#127;BAA&amp;#127;Attnd&amp;#127;S21&amp;#127; 
160642&amp;#127;2020-2021&amp;#127;BAA&amp;#127;Attnd&amp;#127;W21B2&amp;#127;W
;;;;

 proc sort data=Have;
  by ID Term Department Type descending Condition;
run;

data want(drop=found);
 do until(last.Type);
  set Have;
  by ID Term Department Type;
  if Condition^='' then found=1;
 end;
 
 do until(last.Type);
  set Have;
  by  ID Term Department Type;
  if found then do; 
    if last.Type then output;
    end;
   else output;
 end;
run;


Want:

ID	Term	Department	Type	Section	Condition
96905	2020-2021	BAA	Attnd	W21B2	
156968	2021-2022	BAA	Attnd	F21B2	W
156968	2021-2022	BAA	Attnd	W22B2	W
160642	2020-2021	BAA	Attnd	S21	
174636	2022-2023	AST	Attnd	F22D1	
174636	2022-2023	AST	Attnd	W22	
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 25 Feb 2023 19:16:09 GMT</pubDate>
    <dc:creator>twildone</dc:creator>
    <dc:date>2023-02-25T19:16:09Z</dc:date>
    <item>
      <title>re: removing duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-removing-duplicates/m-p/860865#M340055</link>
      <description>&lt;P&gt;Hi...I am not quite getting what I need. I need to remove duplicate records.&amp;nbsp;The criteria for the removal is that for the grouping of ID, Term, Department and Section, if there is at least one record where the entry for Condition is blank, then all records having a "W" for Condition are to be deleted. If either all entries for condition are blank or "W", then all records need to kept.If anyone can help it would be greatly appreciated. thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
    length ID 8 Term $ 9 Department $ 5 Type $ 5 Section $ 5 Condition $ 2;
    format ID F12. Term $char9. Department $char5. Type $char5. Section $char5. Condition $char2.;
    informat ID best12. Term $char9. Department $char5. Type $char5. Section $char5. Condition $char2.;
    infile datalines4 dlm='7F'x missover dsd;
    input ID : best32. Term : $char9. Department : $char5. Type : $char5. Section : $char5. Condition  : $CHAR2. ;
datalines4;
174636&amp;#127;2022-2023&amp;#127;AST&amp;#127;Attnd&amp;#127;F22D1&amp;#127; 
174636&amp;#127;2022-2023&amp;#127;AST&amp;#127;Attnd&amp;#127;W22&amp;#127; 
96905&amp;#127;2020-2021&amp;#127;BAA&amp;#127;Attnd&amp;#127;S20&amp;#127;W
96905&amp;#127;2020-2021&amp;#127;BAA&amp;#127;Attnd&amp;#127;W21B2&amp;#127; 
156968&amp;#127;2021-2022&amp;#127;BAA&amp;#127;Attnd&amp;#127;F21B2&amp;#127;W
156968&amp;#127;2021-2022&amp;#127;BAA&amp;#127;Attnd&amp;#127;W22B2&amp;#127;W
160642&amp;#127;2020-2021&amp;#127;BAA&amp;#127;Attnd&amp;#127;S21&amp;#127; 
160642&amp;#127;2020-2021&amp;#127;BAA&amp;#127;Attnd&amp;#127;W21B2&amp;#127;W
;;;;

 proc sort data=Have;
  by ID Term Department Type descending Condition;
run;

data want(drop=found);
 do until(last.Type);
  set Have;
  by ID Term Department Type;
  if Condition^='' then found=1;
 end;
 
 do until(last.Type);
  set Have;
  by  ID Term Department Type;
  if found then do; 
    if last.Type then output;
    end;
   else output;
 end;
run;


Want:

ID	Term	Department	Type	Section	Condition
96905	2020-2021	BAA	Attnd	W21B2	
156968	2021-2022	BAA	Attnd	F21B2	W
156968	2021-2022	BAA	Attnd	W22B2	W
160642	2020-2021	BAA	Attnd	S21	
174636	2022-2023	AST	Attnd	F22D1	
174636	2022-2023	AST	Attnd	W22	
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2023 19:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-removing-duplicates/m-p/860865#M340055</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2023-02-25T19:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: re: removing duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-removing-duplicates/m-p/860866#M340056</link>
      <description>&lt;P&gt;Your code does not reflect your rules. First look for a blank, then use this as flag:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=found);
 do until(last.Type);
  set Have;
  by ID Term Department Type;
  if Condition = '' then found = 1;
 end;
 do until(last.Type);
  set Have;
  by  ID Term Department Type;
  if not found or condition ne 'W' then output; 
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2023 19:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-removing-duplicates/m-p/860866#M340056</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-25T19:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: re: removing duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-removing-duplicates/m-p/860867#M340057</link>
      <description>&lt;P&gt;Thanks Kurts.....works perofectly.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2023 19:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-removing-duplicates/m-p/860867#M340057</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2023-02-25T19:50:07Z</dc:date>
    </item>
  </channel>
</rss>

