<?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: using IN operator in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613738#M179288</link>
    <description>&lt;P&gt;If you write 100-199 that will evaluate to the value -99.&amp;nbsp; Are the values of GROUP only integers? If so you can use colon to make a range of integers, like this&amp;nbsp; 100:199.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Dec 2019 15:12:01 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-12-24T15:12:01Z</dc:date>
    <item>
      <title>using IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613682#M179251</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to choose only rows with following condition:&lt;/P&gt;
&lt;P&gt;group=835&lt;/P&gt;
&lt;P&gt;OR&amp;nbsp;group=703&lt;/P&gt;
&lt;P&gt;&amp;nbsp; OR&amp;nbsp;group=705&lt;/P&gt;
&lt;P&gt;OR&amp;nbsp;group=853&lt;/P&gt;
&lt;P&gt;OR&amp;nbsp;group=855&lt;/P&gt;
&lt;P&gt;OR&amp;nbsp;group between 100 and 199&lt;/P&gt;
&lt;P&gt;OR&amp;nbsp;group between 300 and 399&lt;/P&gt;
&lt;P&gt;Is there option to write it in IN operator?&lt;/P&gt;
&lt;P&gt;In this way (using IN operator) I get wrong results&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;group IN(835,703,705,853,855,100-199,300-399)&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tbl1;
input ID group;
cards;
1 835
2 835
3 703 
4 703
5 100
6 101
7 199
8 200
9 300
10 500
11 399
;
run;

Data tbl2;
SET tbl1(where=(group IN(835,703,705,853,855,100-199,300-399)));
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 05:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613682#M179251</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-12-24T05:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: using IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613684#M179253</link>
      <description>&lt;P&gt;The valid character to define a range is a colon and not a dash.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run the code you've posted you'll see in the SAS log that it resolves to below.&lt;/P&gt;
&lt;PRE&gt;WHERE group in (-399, -199, 100, 300, 703, 705, 835, 853, 855);&lt;/PRE&gt;
&lt;P&gt;...which explains the unexpected result. It appears SAS doesn't require a comma in the list but just treats each value separately.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the colon for defining the ranges.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set tbl1(where=(group in(835,703,705,853,855,100:199,300:399)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...then you get in the SAS log the following resolution which should return what you expect.&lt;/P&gt;
&lt;PRE&gt;      WHERE group in (703, 705, 835, 853, 855) or ((group=INT(group)) and ((group&amp;gt;=100 and group&amp;lt;=199) or (group&amp;gt;=300 and 
      group&amp;lt;=399)));
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively you could use a format for selection.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value validVals(default=1)
    835,703,705,853,855 = '1'
    100-199,300-399 ='1'
    other='0'
  ;
run;

data tbl2;
  set tbl1(where=(put(group,validVals.)='1'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 00:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613684#M179253</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-12-27T00:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: using IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613722#M179280</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data tbl2;
SET tbl1(where=(group IN (835,703,705,853,855,100:199,300:399)));
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 11:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613722#M179280</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-24T11:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: using IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613738#M179288</link>
      <description>&lt;P&gt;If you write 100-199 that will evaluate to the value -99.&amp;nbsp; Are the values of GROUP only integers? If so you can use colon to make a range of integers, like this&amp;nbsp; 100:199.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 15:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613738#M179288</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-24T15:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: using IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613764#M179299</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;may also need to know that the : is only for a range of INTEGER values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect the IN to catch a value like 101.3 then you need to explicitly list it.&lt;/P&gt;
&lt;P&gt;Which may make the format approach more appealing if you have lots of decimal values.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 17:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-IN-operator/m-p/613764#M179299</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-24T17:27:41Z</dc:date>
    </item>
  </channel>
</rss>

