<?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 Deleting / Keeping a subset of observations in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Keeping-a-subset-of-observations/m-p/559202#M17118</link>
    <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Forgive me if my code is a bit elementary, but I code use some help with a simple data step question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to keep a subset of observations in my data. I've often done this in the past by using if var = "..." then delete in a data step. However, if I did it that way, I would have far too many to delete. Alternatively, if i did it by using if var ne "..." then delete, I would have to use a bunch of data steps and then merge into a large file, which is also not super convenient. I'm wondering can I do something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;keep if var1 = "CharacterName";&lt;BR /&gt;keep if var1 = "CharacterName1";&lt;BR /&gt;keep if var1 = "CharacterName2";&lt;BR /&gt;keep if var1 = "CharacterName3";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I run this, it doesn't work of course.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2019 02:41:36 GMT</pubDate>
    <dc:creator>r4321</dc:creator>
    <dc:date>2019-05-16T02:41:36Z</dc:date>
    <item>
      <title>Deleting / Keeping a subset of observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Keeping-a-subset-of-observations/m-p/559202#M17118</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Forgive me if my code is a bit elementary, but I code use some help with a simple data step question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to keep a subset of observations in my data. I've often done this in the past by using if var = "..." then delete in a data step. However, if I did it that way, I would have far too many to delete. Alternatively, if i did it by using if var ne "..." then delete, I would have to use a bunch of data steps and then merge into a large file, which is also not super convenient. I'm wondering can I do something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;keep if var1 = "CharacterName";&lt;BR /&gt;keep if var1 = "CharacterName1";&lt;BR /&gt;keep if var1 = "CharacterName2";&lt;BR /&gt;keep if var1 = "CharacterName3";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I run this, it doesn't work of course.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 02:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Keeping-a-subset-of-observations/m-p/559202#M17118</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2019-05-16T02:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting / Keeping a subset of observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Keeping-a-subset-of-observations/m-p/559207#M17120</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83117"&gt;@r4321&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The KEEP statement defines variables (columns) you want to keep in your output data set (the one defined using DATA ....). SAS tables are rectangular so it's either keep a column or don't. Also for this reason a KEEP statement is never conditional.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want to remove rows. With SAS you normally simply create a new table (WANT in your case) and then select the rows you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Syntax you could use:&lt;/P&gt;
&lt;PRE&gt;if var1 in ('CharacterName', 'CharacterName1',....);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 03:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Keeping-a-subset-of-observations/m-p/559207#M17120</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-16T03:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting / Keeping a subset of observations</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Keeping-a-subset-of-observations/m-p/559787#M17130</link>
      <description>Thank you!</description>
      <pubDate>Fri, 17 May 2019 20:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Keeping-a-subset-of-observations/m-p/559787#M17130</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2019-05-17T20:21:12Z</dc:date>
    </item>
  </channel>
</rss>

