<?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: How to filter a data set based on a table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756361#M238763</link>
    <description>&lt;P&gt;Another approach is to create and use a format&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $myfilter
    'x'='1'
    'y'='1'
    'z'='1'
    'n'='1'
    other='0'
  ;
run;

data have;
  do col1='a','x','b','z';
    output;
  end;
run;

data filtered;
  set have;
  if put(col1,$myfilter.) ne '1';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Format can also get created dynamically from tables and one could also use hash table lookups for filtering data based on matches to another table. But these are both things for a bit later in your SAS journey.&lt;/P&gt;</description>
    <pubDate>Sat, 24 Jul 2021 03:28:48 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-07-24T03:28:48Z</dc:date>
    <item>
      <title>How to filter a data set based on a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756277#M238740</link>
      <description>&lt;P&gt;I am new to SAS and I know this is a simple question but any help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset and I want to filter it based on specific column.&lt;/P&gt;&lt;P&gt;So the code I have is as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data filtered;
       set have;
where col1 in ("x", "y", "z");
run;&lt;/PRE&gt;&lt;P&gt;This way of filtering is logical as long as there is not a large number of parameters to filter on. But lets say instead of x , y, and z I have a list of 20 different parameters. For example, x, y, z, a, b, ...., n. I think the easier way is that I create a table such as bellow:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data selected_par;
   input parameter_name $1.  ;
   datalines;
x
y
z
n
;&lt;/PRE&gt;&lt;P&gt;and then I filter my data set based on this table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I don't know how to filter my dataset using this &lt;STRONG&gt;selected_par&lt;/STRONG&gt; SAS table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 17:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756277#M238740</guid>
      <dc:creator>Al_senior</dc:creator>
      <dc:date>2021-07-23T17:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter a data set based on a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756281#M238741</link>
      <description>&lt;P&gt;A concrete example of how you expect things to work might help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use Proc SQL and a join. Something like this might work:&lt;/P&gt;
&lt;PRE&gt;Proc sql; 
   create table filtered as
   select a.*
   from have as a inner join selected_par as b
           on a.col1 = b.parameter_name
   ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jul 2021 18:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756281#M238741</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-23T18:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter a data set based on a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756305#M238744</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/387876" target="_blank"&gt;Al_senior&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;You can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table filtered as
   select * from have
   where col1 in (select parameter_name from selected_par);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 19:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756305#M238744</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2021-07-23T19:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter a data set based on a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756361#M238763</link>
      <description>&lt;P&gt;Another approach is to create and use a format&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $myfilter
    'x'='1'
    'y'='1'
    'z'='1'
    'n'='1'
    other='0'
  ;
run;

data have;
  do col1='a','x','b','z';
    output;
  end;
run;

data filtered;
  set have;
  if put(col1,$myfilter.) ne '1';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Format can also get created dynamically from tables and one could also use hash table lookups for filtering data based on matches to another table. But these are both things for a bit later in your SAS journey.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 03:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756361#M238763</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-07-24T03:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter a data set based on a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756409#M238803</link>
      <description>&lt;P&gt;Thank you so much for the solution. I know that might be a bit crazy but would please have a look at my latest question and tell me if what I want to do is even feasible?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 15:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-filter-a-data-set-based-on-a-table/m-p/756409#M238803</guid>
      <dc:creator>Al_senior</dc:creator>
      <dc:date>2021-07-24T15:47:20Z</dc:date>
    </item>
  </channel>
</rss>

