<?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: Conditional deletions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327876#M271690</link>
    <description>In a database world, we would delete relevant rows in a SQL update statement something like:&lt;BR /&gt;Delete from table where id in( select distinct id from table where relevant condition)&lt;BR /&gt;;&lt;BR /&gt;I expect SAS SQL offers something similar.&lt;BR /&gt;It offers the benefit of speed as the data are updated,  not rewritten.&lt;BR /&gt;However it is not reversible</description>
    <pubDate>Thu, 26 Jan 2017 22:34:25 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2017-01-26T22:34:25Z</dc:date>
    <item>
      <title>Conditional deletions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327781#M271686</link>
      <description>&lt;P&gt;I have a dataset with multiple records with the same ID. If a specific condition exists for one of the records, I need to delete all the records with that same ID. How can I do this?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 17:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327781#M271686</guid>
      <dc:creator>jaulz</dc:creator>
      <dc:date>2017-01-26T17:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional deletions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327793#M271687</link>
      <description>&lt;P&gt;Generally you need to identify the record, select the Id to delete an then do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one example:&lt;/P&gt;
&lt;PRE&gt;data have;
   input id value;
   if value &amp;gt; 100 then Flag=1;
datalines;
1  10
1  15
1  25
2  12
2  125
2  16
3  .
3  1
;
run;

proc sql;
   create table want as
   select *
   from have
   where id ne (
      select distinct id
      from have
      where flag=1
      );
quit;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Jan 2017 18:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327793#M271687</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-26T18:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional deletions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327809#M271688</link>
      <description>&lt;P&gt;The output could also be achieved&amp;nbsp;using a merge step.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1 want2 ;
   input id value;
   if value &amp;gt; 100 then output want1 ;
   else output want2 ;
datalines;
1  10
1  15
1  130
2  12
2  125
2  16
3  .
3  1
;
run;

data want ;
merge want1 (in=a) want2 (in=b) ;
by id;
if (a=0) and (b=1) ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 18:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327809#M271688</guid>
      <dc:creator>anoopmohandas7</dc:creator>
      <dc:date>2017-01-26T18:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional deletions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327814#M271689</link>
      <description>&lt;P&gt;Assuming your data set is in order by ID, here is a fairly standard approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;ID_wanted='Y';&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if&amp;nbsp;&amp;nbsp;&amp;nbsp; /* some condition goes here */ then ID_wanted='N';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if ID_wanted='Y' then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop ID_wanted;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The top loop lets you examine all observations for an ID, and determine whether you want them or not.&amp;nbsp; The bottom loop reads in the same observations and outputs if the top loop determines that is appropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 18:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327814#M271689</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-26T18:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional deletions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327876#M271690</link>
      <description>In a database world, we would delete relevant rows in a SQL update statement something like:&lt;BR /&gt;Delete from table where id in( select distinct id from table where relevant condition)&lt;BR /&gt;;&lt;BR /&gt;I expect SAS SQL offers something similar.&lt;BR /&gt;It offers the benefit of speed as the data are updated,  not rewritten.&lt;BR /&gt;However it is not reversible</description>
      <pubDate>Thu, 26 Jan 2017 22:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327876#M271690</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-01-26T22:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional deletions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327877#M271691</link>
      <description />
      <pubDate>Thu, 26 Jan 2017 22:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-deletions/m-p/327877#M271691</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-01-26T22:35:29Z</dc:date>
    </item>
  </channel>
</rss>

