<?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 IF-THE-ELSE Numeric Range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337562#M76670</link>
    <description>&lt;P&gt;This should be a pretty easy one, but I can't find the answer anywhere...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to recode into a new variable using IF-THEN-ELSE statments. How do&amp;nbsp;I incorporate a range of values for a numeric variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF walk4rec10 = . THEN wcat = .;&lt;BR /&gt; ELSE IF walk4rec10 = (-1, 0) THEN wcat = 0;&lt;BR /&gt; ELSE IF walk4rec10 = (1:3) THEN wcat = 1;&lt;BR /&gt; ELSE IF walk4rec10 &amp;gt; 3 THEN wcat = 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2017 20:47:12 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2017-03-02T20:47:12Z</dc:date>
    <item>
      <title>IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337562#M76670</link>
      <description>&lt;P&gt;This should be a pretty easy one, but I can't find the answer anywhere...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to recode into a new variable using IF-THEN-ELSE statments. How do&amp;nbsp;I incorporate a range of values for a numeric variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF walk4rec10 = . THEN wcat = .;&lt;BR /&gt; ELSE IF walk4rec10 = (-1, 0) THEN wcat = 0;&lt;BR /&gt; ELSE IF walk4rec10 = (1:3) THEN wcat = 1;&lt;BR /&gt; ELSE IF walk4rec10 &amp;gt; 3 THEN wcat = 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337562#M76670</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2017-03-02T20:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337564#M76672</link>
      <description>This should work:&lt;BR /&gt;&lt;BR /&gt;IF walk4rec10 = . THEN wcat = .;&lt;BR /&gt;ELSE IF walk4rec10 &amp;gt;= -1 and walk4rec10 &amp;lt;=0 THEN wcat = 0;&lt;BR /&gt;ELSE IF walk4rec10 &amp;gt;= 1 and walk4rec10 &amp;lt;= 3 THEN wcat = 1;&lt;BR /&gt;ELSE IF walk4rec10 &amp;gt; 3 THEN wcat = 2;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:51:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337564#M76672</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T20:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337570#M76675</link>
      <description>&lt;PRE&gt;data have;
  input IF walk4rec10;
  cards;
-5
-2
-1
0
1
2
3
4
5
;
data want;
  set have;
  IF -1 &amp;lt;=walk4rec10&amp;lt;=0 THEN wcat = 0;
  ELSE IF 1&amp;lt;=walk4rec10&amp;lt;=3 THEN wcat = 1;
  ELSE IF walk4rec10 &amp;gt; 3 THEN wcat = 2;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337570#M76675</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-02T20:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337571#M76676</link>
      <description>&lt;P&gt;If walk4rec10 does not contain float values, then you could also do this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF walk4rec10 = . THEN wcat = .;
 ELSE IF walk4rec10 in (-1,0)  THEN wcat = 0;
 ELSE IF walk4rec10 in (1,2,3) THEN wcat = 1;
 ELSE IF walk4rec10 &amp;gt; 3 THEN wcat = 2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337571#M76676</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T20:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337575#M76677</link>
      <description>&lt;P&gt;It is not clear if walk4rec is integer. This will work whether&amp;nbsp;it is or not:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select;
	when (missing(walk4rec10)) wcat = .;
	when (walk4rec10 in (-1, 0)) wcat = 0;
	when (1 &amp;lt;= walk4rec10 &amp;lt;= 3) wcat = 1;
	otherwise wcat = 2;
	end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337575#M76677</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-02T21:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337577#M76678</link>
      <description>Using the IN operator converts the variable to character...</description>
      <pubDate>Thu, 02 Mar 2017 21:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337577#M76678</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2017-03-02T21:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337580#M76680</link>
      <description>&lt;P&gt;in operator works with both numeric and character data. It does not convert anything. Can you give us the cdoe you are using?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:04:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337580#M76680</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T21:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337581#M76681</link>
      <description>Using the IN operator was converting the variable to character, so I abandoned it. This was my original source: &lt;A href="http://support.sas.com/kb/13/533.html" target="_blank"&gt;http://support.sas.com/kb/13/533.html&lt;/A&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337581#M76681</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2017-03-02T21:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337583#M76682</link>
      <description>&lt;P&gt;The note seems to be specific to this scenario: "If a range is used with the IN operator and the IN operator is used again in the same step, you may receive the following error:"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is no range in the code I sent. A usage of range with 'in' would look like this per the same SAS note:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if x in(1:3,5) then y=2;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337583#M76682</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T21:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337584#M76683</link>
      <description>&lt;P&gt;This is the original syntax&amp;nbsp;I was using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF walk4rec10 = . THEN wcat = .;&lt;BR /&gt; ELSE IF walk4rec10 IN(-1,0) THEN wcat = 0;&lt;BR /&gt; ELSE IF walk4rec10 IN(1:3) THEN wcat = 1;&lt;BR /&gt; ELSE IF walk4rec10 &amp;gt; 3 THEN wcat = 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was getting a message saying that numeric values were converted to character.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I just rewrote&amp;nbsp;the syntax in order to post it here, the "conversion message" was absent. Go figure. I have no explanation for that!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337584#M76683</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2017-03-02T21:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337587#M76684</link>
      <description>&lt;P&gt;Your&lt;EM&gt; source&lt;/EM&gt; describes an unrelated problem corrected in SAS 9.2. The IN operator doesn't convert its operators if they are of the same type.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337587#M76684</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-02T21:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337589#M76685</link>
      <description>&lt;P&gt;Oh, I see. You had the range in the second statement with IN, which is why you probably got an unexpected result. Frankly, I did not know about that issue. But it can be easily cirucmvented by either specifying IN (1,2,3) or if it is a larger range, using the comparison &amp;nbsp;operators (&amp;gt; and &amp;lt; &lt;EM&gt;OR&lt;/EM&gt; &amp;gt;= and &amp;lt;=).&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337589#M76685</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T21:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337591#M76687</link>
      <description>&lt;P&gt;I'd guess that your original code had a length or format statement in it that set wcat to character type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337591#M76687</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-02T21:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337594#M76688</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36911"&gt;@_maldini_&lt;/a&gt;&amp;nbsp;I would love to see an example of a numeric variable where IN converts it to character.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337594#M76688</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-02T21:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337596#M76689</link>
      <description>&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337596#M76689</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-02T21:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THE-ELSE Numeric Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337680#M76727</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36911"&gt;@_maldini_&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;This is the original syntax&amp;nbsp;I was using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF walk4rec10 = . THEN wcat = .;&lt;BR /&gt; ELSE IF walk4rec10 IN(-1,0) THEN wcat = 0;&lt;BR /&gt; ELSE IF walk4rec10 IN(1:3) THEN wcat = 1;&lt;BR /&gt; ELSE IF walk4rec10 &amp;gt; 3 THEN wcat = 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was getting a message saying that numeric values were converted to character.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Post the entire log including any messages for the code generating that message. It could well be that the conversion is happening somewhere else in the code and you are only providing part of the problem.&lt;/P&gt;
&lt;P&gt;Also post LOG and code using code boxes brough up by the {i} menu icon. The forum message boxes sometimes get reformatted and odd artifacts have been known to appear in code.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 00:30:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THE-ELSE-Numeric-Range/m-p/337680#M76727</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-03T00:30:13Z</dc:date>
    </item>
  </channel>
</rss>

