<?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: &amp;gt;,&amp;lt;,= &amp; Character Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157839#M263075</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Declare the length $5 for test variable. by doing this, it would show "Equal".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards;&lt;/P&gt;&lt;P&gt;Uma shanker Saini&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Dec 2013 09:25:27 GMT</pubDate>
    <dc:creator>umashankersaini</dc:creator>
    <dc:date>2013-12-02T09:25:27Z</dc:date>
    <item>
      <title>&gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157833#M263069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to create a new variable Test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data XXX;&lt;/P&gt;&lt;P&gt;set YYY;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; if Apple&amp;lt;Orange then Test=Y;&lt;/P&gt;&lt;P&gt;if Apple=Orange then Test=Equal;&lt;/P&gt;&lt;P&gt;if Apple&amp;gt;Orange then Test=N;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apple &amp;amp; Orange are Character Variables but have only numbers in them. When I run this code the Test field are all blanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I change the code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 02:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157833#M263069</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2013-11-28T02:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157834#M263070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Test="Y" etc otherwise you're assigning the variable Y to test, not the value. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 03:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157834#M263070</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-11-28T03:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157835#M263071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And adding to what Reeza says: That's why it's always worth to check the log and understand why log messages and warnings get created - eg. the ones about uninitialized variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 04:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157835#M263071</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-28T04:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157836#M263072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If APPLE and ORANGE are character variables and you want to compare their values as if they were the numbers that the character strings represent then you should use the INPUT() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length apple orange $32 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input apple orange ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; char = apple &amp;lt; orange ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num = input(apple,32.) &amp;lt; input(orange,32.) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put (_all_) (=);&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;11 2&lt;/P&gt;&lt;P&gt;1E20 200&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;apple=1 orange=2 char=1 num=1&lt;/P&gt;&lt;P&gt;apple=11 orange=2 char=1 num=0&lt;/P&gt;&lt;P&gt;apple=1E20 orange=200 char=1 num=0&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Nov 2013 00:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157836#M263072</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-11-29T00:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157837#M263073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data XXX;&lt;/P&gt;&lt;P&gt;set YYY;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; if Apple&amp;lt;Orange then Test='Y';&lt;/P&gt;&lt;P&gt;if Apple=Orange then Test='Equal';&lt;/P&gt;&lt;P&gt;if Apple&amp;gt;Orange then Test='N';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why instead of showing 'Equal' SAS shows 'E'?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 05:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157837#M263073</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2013-12-02T05:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157838#M263074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;include a statement that specifies the length of the new variable, e.g.&lt;/P&gt;&lt;P&gt;length test $5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't test it at the moment, but I think declaring a format would also work, e.g.&lt;/P&gt;&lt;P&gt;format test $5.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 05:13:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157838#M263074</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-12-02T05:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157839#M263075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Declare the length $5 for test variable. by doing this, it would show "Equal".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards;&lt;/P&gt;&lt;P&gt;Uma shanker Saini&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 09:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157839#M263075</guid>
      <dc:creator>umashankersaini</dc:creator>
      <dc:date>2013-12-02T09:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157840#M263076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further to the good advice already given about using the length statement and in answer to your question "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Why instead of showing 'Equal' SAS shows 'E'?&lt;/SPAN&gt;", the reason is that if you do not define the length of a variable it takes the length of the value that is first assigned to it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, for example, the following will set the length of variable &lt;SPAN style="font-family: 'courier new', courier;"&gt;var&lt;/SPAN&gt; to 1 as it is first assigned a value of "Y" which has a length of 1:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data test1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;&amp;nbsp; var="Y";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; var="Equal";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; var="N";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whereas the following will set the length of variable &lt;SPAN style="font-family: 'courier new', courier;"&gt;var&lt;/SPAN&gt; to 5 as it is first assigned a value of "Equal" which has a length of 5:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data test2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; var="Equal";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; var="Y";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; var="N";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using a &lt;SPAN style="font-family: 'courier new', courier;"&gt;length&lt;/SPAN&gt; statement allows you to set the maximum length you need without thinking about which value you assign to the variable first and it also makes it clear to the human reader.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 12:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157840#M263076</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-12-02T12:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157841#M263077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data a ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length apple orange $32 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input apple orange ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; char = apple &amp;lt; orange ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num = input(apple,32.) &amp;lt; input(orange,32.) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put (_all_) (=);&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;11 2&lt;/P&gt;&lt;P&gt;1E20 200&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;apple=1 orange=2 char=1 num=1&lt;/P&gt;&lt;P&gt;apple=11 orange=2 char=1 num=0&lt;/P&gt;&lt;P&gt;apple=1E20 orange=200 char=1 num=0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you everybody for the helpful comments. But regarding the given code, I don't understand&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;char = apple &amp;lt; orange ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num = input(apple,32.) &amp;lt; input(orange,32.) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put (_all_) (=);&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;11 2&lt;/P&gt;&lt;P&gt;1E20 200&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 13:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157841#M263077</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2013-12-02T13:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157842#M263078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;char = apple &amp;lt; orange ;&lt;/P&gt;&lt;P&gt;Is an assignment statement. It says to set the variable CHAR to value of the expression on the right of the equal sign.&amp;nbsp; In this case that is the boolean expression comparing the values of the variables apple and orange.&amp;nbsp; When the value of apple is less than the value of orange then CHAR will be set to 1 (true) , otherwise it will be set to zero (false).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;input(apple,32.) will interpret the character string that is in the variable APPLE using the informat 32.&amp;nbsp; So anything that looks like a number will be converted to a number.&amp;nbsp; In this case the input data for APPLE consists of '1' , '11', and '1E20' which will be interpreted by the input() function as the numbers 1, 11 and 1 times 10 to the 20th power (or 1 with 20 zeros after it).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;put (_all_) (=);&lt;/P&gt;&lt;P&gt;Says to output the values of the variables listed inside the first set of parentheses using the format operators listed inside the second set of parenthesis. The variable list _ALL_ means to use all of the variables currently defined.&amp;nbsp; There is only one format listed so it is applied to each variable. The = format operator in a PUT statement means to list the name of the variable followed by an equal sign and then the value of the variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CARDS;&lt;/P&gt;&lt;P&gt;Statement says to treat all lines following as data until there is a line with a semi-colon on it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The rest are the data lines.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 13:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157842#M263078</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-12-02T13:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: &gt;,&lt;,= &amp; Character Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157843#M263079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom was just giving you some examples of why you ought to convert your character fields to numeric fields when doing your comparisons.&amp;nbsp; Both "char=apple&amp;lt;orange" and "input(apple,32.)&amp;lt;input(orange,32.)" will return zeros or one dependent upon whether the condition to the right of the equal sign is true.&amp;nbsp; That form results in one of two numbers: 1 if if the condition is true and 0 if it isn't.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 13:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/gt-lt-Character-Variables/m-p/157843#M263079</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-12-02T13:54:06Z</dc:date>
    </item>
  </channel>
</rss>

