<?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: Subsetting based on multiple criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303205#M270446</link>
    <description>&lt;P&gt;Here some coding options. Should your dataset really be large (=millions of rows) then using the where clause is better as it sub-sets the data while reading and not only while writing.&lt;/P&gt;
&lt;P&gt;You should also use a where clause if your "dataset_old" is stored in a database as the where condition will get pushed to the database for execution (and so the rows don't get first transfered to SAS only to drop them there).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA dataset_new;
  SET dataset_old;
  IF var1="yes" or var2="yes" or var3="yes" then DELETE;
RUN;

DATA dataset_new;
  SET dataset_old;
  IF var1 ne "yes" and var2 ne "yes" and var3 ne "yes";
RUN;

DATA dataset_new;
  SET dataset_old;
  where var1 ne "yes" and var2 ne "yes" and var3 ne "yes";
RUN;

DATA dataset_new;
  SET dataset_old (where=(var1 ne "yes" and var2 ne "yes" and var3 ne "yes"));
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 07 Oct 2016 16:02:34 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2016-10-07T16:02:34Z</dc:date>
    <item>
      <title>Subsetting based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303202#M270445</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large data-set which I want to reduce to a smaller data-set, by excluding certain participants based on either of 3 criteria (for each criterium there is a yes/no variable). If a participant answers yes to either&amp;nbsp;one of&amp;nbsp;the three criteria, I want that specific participant&amp;nbsp;out of the data-set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the following procedure (sorry for the typing, I do not have the syntax available on my home computer. Working with SAS 9.4):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA dataset_new;&lt;/P&gt;&lt;P&gt;SET dataset_old;&lt;/P&gt;&lt;P&gt;IF &lt;EM&gt;variable&lt;/EM&gt;="yes" then DELETE;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I got errors and as you can see this is only one criterium, not three. Am I using the right statement and how could I incorporate the criterium 'either one of the criteria'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry if this is beginner-level, I'm learning!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards and many thanks,&lt;/P&gt;&lt;P&gt;Marjolein&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 15:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303202#M270445</guid>
      <dc:creator>Marjolein</dc:creator>
      <dc:date>2016-10-07T15:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303205#M270446</link>
      <description>&lt;P&gt;Here some coding options. Should your dataset really be large (=millions of rows) then using the where clause is better as it sub-sets the data while reading and not only while writing.&lt;/P&gt;
&lt;P&gt;You should also use a where clause if your "dataset_old" is stored in a database as the where condition will get pushed to the database for execution (and so the rows don't get first transfered to SAS only to drop them there).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA dataset_new;
  SET dataset_old;
  IF var1="yes" or var2="yes" or var3="yes" then DELETE;
RUN;

DATA dataset_new;
  SET dataset_old;
  IF var1 ne "yes" and var2 ne "yes" and var3 ne "yes";
RUN;

DATA dataset_new;
  SET dataset_old;
  where var1 ne "yes" and var2 ne "yes" and var3 ne "yes";
RUN;

DATA dataset_new;
  SET dataset_old (where=(var1 ne "yes" and var2 ne "yes" and var3 ne "yes"));
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Oct 2016 16:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303205#M270446</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-07T16:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303206#M270447</link>
      <description>&lt;P&gt;There's nothing wrong with what you have done. &amp;nbsp;While you can combine conditions into a single statement, you don't have to (at least not for the problem you described). &amp;nbsp;In theory, it would be perfectly fine to code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if varaible1='yes' then delete;&lt;/P&gt;
&lt;P&gt;if variable2='yes' then delete;&lt;/P&gt;
&lt;P&gt;if variable3='yes' then delete;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are getting an error, the first thing to check is whether you spelled the name of the variable correctly. &amp;nbsp;You could run a PROC CONTENTS on your data set to confirm the variable names. &amp;nbsp;It would also help track down the second possible source of an error. &amp;nbsp;Perhaps your variable is really numeric, but prints out as "yes" or "no" because it has a format applied to it. &amp;nbsp;So by running PROC CONTENTS you can see the true definition of your variable to get a better idea of what it contains. &amp;nbsp;If this turns out to be an issue, you could also run this test:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=mydata (obs=50);&lt;/P&gt;
&lt;P&gt;var variable;&lt;/P&gt;
&lt;P&gt;format variable;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will print a sampling of the data values, showing you what is actually contained rather than the formatted value.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 16:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303206#M270447</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-07T16:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303232#M270448</link>
      <description>Hi Patrick,&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for your very quick response. Looks good. Will apply it as&lt;BR /&gt;soon as I'm behind my computer at uni and if it works out I will let you&lt;BR /&gt;know!&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Fri, 07 Oct 2016 17:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303232#M270448</guid>
      <dc:creator>Marjolein</dc:creator>
      <dc:date>2016-10-07T17:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303234#M270449</link>
      <description>&lt;P&gt;Ahhhh. That may have gone wrong. I indeed applied a format to the data, so I guess it is numeric...&lt;/P&gt;&lt;P&gt;Will try it once I'm behind my computer at uni. Really helpful. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 17:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303234#M270449</guid>
      <dc:creator>Marjolein</dc:creator>
      <dc:date>2016-10-07T17:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303506#M270450</link>
      <description>&lt;P&gt;It worked! The variables were numeric indeed. Thanks a lot! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2016 07:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-based-on-multiple-criteria/m-p/303506#M270450</guid>
      <dc:creator>Marjolein</dc:creator>
      <dc:date>2016-10-10T07:52:17Z</dc:date>
    </item>
  </channel>
</rss>

