<?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: Between Operator for Char Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162794#M31549</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I too believe its the character conversation taking place. &lt;/P&gt;&lt;P&gt;Thanks for giving your thought &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Feb 2015 12:07:41 GMT</pubDate>
    <dc:creator>Pra</dc:creator>
    <dc:date>2015-02-11T12:07:41Z</dc:date>
    <item>
      <title>Between Operator for Char Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162791#M31546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a scenario where&amp;nbsp; BETWEEN Operator is not working as expected.Please help me in understanding what could be the possible reason for this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;751 DATA VS;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;752 SET STUDY.VS;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;753 KEEP USUBJID VISIT VSTESTCD VSTEST VSORRES VSORRESU ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;754 WHERE VSTESTCD ='WEIGHT' AND VSORRES BETWEEN '35' AND '150'; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;755&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;756 /*WHERE&amp;nbsp; (VSTESTCD='WEIGHT') AND (INPUT(VSORRES,BEST.) BETWEEN 35 AND 150);*/ This is working &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;757 RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;NOTE: There were 6 observations read from the data set STUDY.VS.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style=": ; color: #ff0000; font-family: 'SAS Monospace';"&gt;&lt;SPAN style="font-size: 8pt;"&gt; WHERE (VSTESTCD='WEIGHT') and (VSORRES&amp;gt;='150' and VSORRES&amp;lt;='35'); - Please help in &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.6666669845581px;"&gt;comprehending&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; how the condition was negated.&amp;nbsp; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;NOTE: The data set WORK.VS has 6 observations and 6 variables.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;NOTE: Compressing data set WORK.VS increased size by 100.00 percent.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt; Compressed is 2 pages; un-compressed would require 1 pages.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;NOTE: DATA statement used (Total process time):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 8.0pt; font-family: 'SAS Monospace';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;VSORRES : CHAR VARIABLE HAVING NUMERIC VALUES &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 10:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162791#M31546</guid>
      <dc:creator>Pra</dc:creator>
      <dc:date>2015-02-11T10:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Between Operator for Char Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162792#M31547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, to be honest I am not really going to look at the why this is happening and there is a simple reason, I would never recommend to use character data in a place where numeric data is expected.&amp;nbsp; Its simply bad and lazy coding practice and leads to these kind of issues.&amp;nbsp; I would suggest explicitly writing the where as you expect it to perform:&lt;/P&gt;&lt;P&gt;where vstestcd="WEIGHT" and 35 &amp;lt;= input(vsorres,best.) &amp;lt;= 150;&lt;/P&gt;&lt;P&gt;From the above statement we can clearly see that we are doing a numeric test and the upper and lower boundary (plus whether ton include the boundaries) is clearly shown and no "guessing" needs to take place.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As for the why it is doing that, well, could be any number of reasons, perhaps when it converts the character data to numeric (which is what it is doing, your just leaving it to fate to decide what to do), it is sorting the information it has, hence "150" as text appears before "35". &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 11:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162792#M31547</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-02-11T11:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Between Operator for Char Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162793#M31548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Usually Character comparisons happens character by character from left to right, if you use any comparison operators like &amp;lt; , &amp;gt; etc . '150' might appear to be a smaller value when compared to '35', so you may not get what you want. Better convert them to integer&amp;nbsp; before you do anything on them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Karthik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 11:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162793#M31548</guid>
      <dc:creator>Karthikeyan</dc:creator>
      <dc:date>2015-02-11T11:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Between Operator for Char Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162794#M31549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I too believe its the character conversation taking place. &lt;/P&gt;&lt;P&gt;Thanks for giving your thought &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 12:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162794#M31549</guid>
      <dc:creator>Pra</dc:creator>
      <dc:date>2015-02-11T12:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Between Operator for Char Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162795#M31550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Think about it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;data&lt;/STRONG&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;_null_&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;x&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;'35'&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; min &lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;'150'&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;put&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; x=;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;x&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;150&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 12:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162795#M31550</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-02-11T12:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Between Operator for Char Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162796#M31551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the question here?&lt;/P&gt;&lt;P&gt;Are you surprised that SAS let you specify the higher value first when using the BETWEEN operator?&amp;nbsp; That is a nice enhancement that SAS allows that some other languages do not allow. Makes the BETWEEN operator work more like natural language.&amp;nbsp; Works the same way with numeric variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; data x; set sashelp.class ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where age between 12 and 9 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where also name between 'Sara' and 'Adam';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;NOTE: WHERE clause has been augmented.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;NOTE: There were 6 observations read from the data set SASHELP.CLASS.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE (age&amp;gt;=9 and age&amp;lt;=12) and (name&amp;gt;='Adam' and name&amp;lt;='Sara');&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;NOTE: The data set WORK.X has 6 observations and 5 variables.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or are you confused about the lexical ordering of character variables?&amp;nbsp; '150' is less than '35' because '1' is less than '3' .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 14:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162796#M31551</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-02-11T14:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Between Operator for Char Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162797#M31552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Run this program an look at the results. It may help you see the difference in character variable order compared with numeric. It creates some character variables that look like numbers, sorts them and prints the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input x $;&lt;BR /&gt;datalines;&lt;BR /&gt;1 &lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;10&lt;BR /&gt;25&lt;BR /&gt;38&lt;BR /&gt;150&lt;BR /&gt;220&lt;BR /&gt;3487&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=test; by x;run;&lt;BR /&gt;proc print data=test;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 15:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Between-Operator-for-Char-Variable/m-p/162797#M31552</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-02-11T15:20:46Z</dc:date>
    </item>
  </channel>
</rss>

