<?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: Data step:  Select when range of integers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573958#M162100</link>
    <description>&lt;P&gt;Have you checked does next simplified code work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data New;
     set Old;
     select (var1);
         ...
         when (101:109) x=1;
         when (201:209) x=2;
         when (301:309) x=3;
         ...
         otherwise;
     end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you mean for any range #01 to #09 where # is any digit ?&lt;/P&gt;
&lt;P&gt;Then try:&amp;nbsp; &lt;STRONG&gt;if&amp;nbsp;mod(var1, 100) between 1 and 9 then x=1;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2019 18:02:59 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2019-07-16T18:02:59Z</dc:date>
    <item>
      <title>Data step:  Select when range of integers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573952#M162097</link>
      <description>&lt;P&gt;Very asinine question, but why doesn't the following syntax in the when statement of the select block not work to set x=1 for any values of var 1 between 101-109, 201-209, 301-309?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data New;
&amp;nbsp; &amp;nbsp; &amp;nbsp;set Old;
&amp;nbsp; &amp;nbsp; &amp;nbsp;select (var1);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;when (101:109, 201:209, 301:309) x=1;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;otherwise;
&amp;nbsp; &amp;nbsp; &amp;nbsp;end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get an error.&amp;nbsp; I have also tried using -- (no error but doesn't work), - (just subtracts), to (error), between (error)...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;scratching my head...&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 17:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573952#M162097</guid>
      <dc:creator>Jayme</dc:creator>
      <dc:date>2019-07-16T17:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: Data step:  Select when range of integers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573954#M162098</link>
      <description>&lt;P&gt;Because the WHEN clause of the SELECT/END statement doesn't support that syntax.&amp;nbsp; Note you would only get subtraction if you asked for subtraction by using a - between two values in an expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the IN operator does support using N:M as a shortcut for a range of integers.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input var1 @@ ;
  x=var1 in (101:109, 201:209, 301:309);
  select ;
    when (var1 in (101:109, 201:209, 301:309)) y=1;
    otherwise y=0;
  end;
  output;
cards;
1 101 105.6 200 209 305 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs     var1    x    y

 1       1.0    0    0
 2     101.0    1    1
 3     105.6    0    0
 4     200.0    0    0
 5     209.0    1    1
 6     305.0    1    1&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jul 2019 17:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573954#M162098</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-16T17:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Data step:  Select when range of integers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573956#M162099</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281748"&gt;@Jayme&lt;/a&gt;&amp;nbsp; &amp;nbsp;i would think you need an IN operator to execute without errors unless you use that an assignment to initialize value at compile time in array, retain statement etc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data New;
     set Old;
     select ;
         ...
         when (var1 in (101:109, 201:209, 301:309)) x=1;
         ...
         otherwise;
     end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jul 2019 17:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573956#M162099</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-16T17:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Data step:  Select when range of integers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573958#M162100</link>
      <description>&lt;P&gt;Have you checked does next simplified code work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data New;
     set Old;
     select (var1);
         ...
         when (101:109) x=1;
         when (201:209) x=2;
         when (301:309) x=3;
         ...
         otherwise;
     end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you mean for any range #01 to #09 where # is any digit ?&lt;/P&gt;
&lt;P&gt;Then try:&amp;nbsp; &lt;STRONG&gt;if&amp;nbsp;mod(var1, 100) between 1 and 9 then x=1;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 18:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/573958#M162100</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-07-16T18:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Data step:  Select when range of integers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/585986#M167219</link>
      <description>&lt;P&gt;Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 00:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-Select-when-range-of-integers/m-p/585986#M167219</guid>
      <dc:creator>runrunbunny</dc:creator>
      <dc:date>2019-09-04T00:27:19Z</dc:date>
    </item>
  </channel>
</rss>

