<?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 how to remove a few selected obs from a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/480989#M124344</link>
    <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;I have a data set that i need to remove a few selected obs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to remove when 'ID'&amp;nbsp; and 'VAL' are equal and 'date'&amp;nbsp; value is&amp;nbsp; dot (date value should be available for other obs) and&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;more than one obs present.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;eg: From below data set I need to remove second obs(highlighted in red) only because it has same 'ID' and 'VAl' values&amp;nbsp; as in first obs and date is available in first obs and date is null not in second.Please help. Thank you&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;output needed&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id val date&amp;nbsp;&lt;BR /&gt;1 sd 2018-05-15&lt;BR /&gt;2 pr .&lt;BR /&gt;3 cr 2018-05-15&lt;BR /&gt;3 pr 2018-05-15&lt;BR /&gt;3 sd 2018-05-15&lt;BR /&gt;4 sd 2017-05-15&lt;BR /&gt;4 sd 2017-04-15&lt;BR /&gt;5 pd .&lt;BR /&gt;5 pd .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id val $ date $10.;
datalines;
1 sd 2018-05-15
&lt;FONT color="#FF0000"&gt;1 sd .&lt;/FONT&gt;
2 pr .
3 cr 2018-05-15
3 pr 2018-04-15
3 sd 2018-05-15
4 sd 2017-05-15
4 sd 2017-04-15&lt;BR /&gt;5 pd .&lt;BR /&gt;5 pd . 
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 25 Jul 2018 02:19:02 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2018-07-25T02:19:02Z</dc:date>
    <item>
      <title>how to remove a few selected obs from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/480989#M124344</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;I have a data set that i need to remove a few selected obs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to remove when 'ID'&amp;nbsp; and 'VAL' are equal and 'date'&amp;nbsp; value is&amp;nbsp; dot (date value should be available for other obs) and&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;more than one obs present.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;eg: From below data set I need to remove second obs(highlighted in red) only because it has same 'ID' and 'VAl' values&amp;nbsp; as in first obs and date is available in first obs and date is null not in second.Please help. Thank you&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;output needed&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id val date&amp;nbsp;&lt;BR /&gt;1 sd 2018-05-15&lt;BR /&gt;2 pr .&lt;BR /&gt;3 cr 2018-05-15&lt;BR /&gt;3 pr 2018-05-15&lt;BR /&gt;3 sd 2018-05-15&lt;BR /&gt;4 sd 2017-05-15&lt;BR /&gt;4 sd 2017-04-15&lt;BR /&gt;5 pd .&lt;BR /&gt;5 pd .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id val $ date $10.;
datalines;
1 sd 2018-05-15
&lt;FONT color="#FF0000"&gt;1 sd .&lt;/FONT&gt;
2 pr .
3 cr 2018-05-15
3 pr 2018-04-15
3 sd 2018-05-15
4 sd 2017-05-15
4 sd 2017-04-15&lt;BR /&gt;5 pd .&lt;BR /&gt;5 pd . 
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jul 2018 02:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/480989#M124344</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2018-07-25T02:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove a few selected obs from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/480990#M124345</link>
      <description>&lt;P&gt;You have date as a character variable, so you want to deselect certain cases with date=' ', not cases with date=dot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you never have more than one case per id with date=' ', then you can merge a subset of dataset ONE with another subset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge one (where=(date=' '))
        one (where=(date^=' ')) ;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For id's with only a single record, that record (whether date=' ' or not) will pass through.&amp;nbsp; For those id's with both a date=' ' and a non-blank date, the non-blank value will prevail, since it will be in the latter argument of the merge statement.&amp;nbsp; I.e. whenever you merge multiple data sets (or multiple subsets in this case) the right-most value of any common variable is the one that is kept when there are matched records.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 02:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/480990#M124345</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-25T02:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove a few selected obs from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/480999#M124353</link>
      <description>&lt;P&gt;The UPDATE&amp;nbsp;statement does exactly that (if you want to just keep the latest non-missing data for each VAL ID group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
input ID VAL $ DATE : $10.;
cards;
1 sd 2018-05-15
2 pr .
3 cr 2018-05-15
3 pr 2018-05-15
3 sd 2018-05-15
4 sd 2017-05-15 &amp;lt;=removed, replaced with next record
4 sd 2017-04-15
5 pd .
5 pd .          &amp;lt;=removed, no value to add
run;
data WANT;
  update HAVE(obs=0) HAVE;
  by ID VAL;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;ID&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;VAL&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;DATE&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;sd&lt;/TD&gt;
&lt;TD class="l data"&gt;2018-05-15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;pr&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;cr&lt;/TD&gt;
&lt;TD class="l data"&gt;2018-05-15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;pr&lt;/TD&gt;
&lt;TD class="l data"&gt;2018-05-15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;sd&lt;/TD&gt;
&lt;TD class="l data"&gt;2018-05-15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;sd&lt;/TD&gt;
&lt;TD class="l data"&gt;2017-04-15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="l data"&gt;pd&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;[&amp;nbsp; Edit: Sorry &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, it looks like you should have been just 3&amp;nbsp;minutes faster &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; &amp;nbsp;]&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 04:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/480999#M124353</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-07-25T04:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove a few selected obs from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/481000#M124354</link>
      <description>&lt;P&gt;A classic example of when to use the UPDATE statement.&amp;nbsp; Update is intended to apply transactions to a dataset. In particular missing values are treated as meaning no change should be made.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally you need a master and transaction dataset, but you can use an empty version of your source data as the "master".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  update one(obs=0) one;
  by id val;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jul 2018 04:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-a-few-selected-obs-from-a-dataset/m-p/481000#M124354</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-25T04:06:38Z</dc:date>
    </item>
  </channel>
</rss>

