<?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: Finding exact value of a character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266721#M52626</link>
    <description>&lt;P&gt;Trailing blanks won't cause a problem, but leading blanks could. &amp;nbsp;Try checking what is actually there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq;&lt;/P&gt;
&lt;P&gt;tables state;&lt;/P&gt;
&lt;P&gt;format state $char25,.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The FORMAT statement will preserve any leading blanks in the table.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Apr 2016 14:32:47 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-04-27T14:32:47Z</dc:date>
    <item>
      <title>Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266706#M52619</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found on occasional problem that I run into in SAS that I can't quite figure out. Is there a way to get the &lt;STRONG&gt;exact &lt;/STRONG&gt;reponse to a character variable in SAS? I usually use proc freq, but sometimes this does not work. I suspect it has to do with leading or trailing blanks. I&amp;nbsp;could use a SAS character function to supress trailing or leading blanks, but is there a way to actually see where those blanks are? Or is there another reason why this might occur? Any insight would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;state in ( &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"Virginia", "Georgia", "South Carolina" ) then south = "Yes";&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;state&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;south&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Virginia&lt;/TD&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Georgia&lt;/TD&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;South Carolina&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 13:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266706#M52619</guid>
      <dc:creator>Noob</dc:creator>
      <dc:date>2016-04-27T13:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266714#M52623</link>
      <description>&lt;P&gt;I would always use:&lt;/P&gt;
&lt;P&gt;if strip(state) in (...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or in fact, I would upper case them so as to avoid differences in case:&lt;/P&gt;
&lt;P&gt;if upcase(strip(state)) in (...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally speaking you should really know your data, so stripping off leading and training blanks should not be a problem. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 14:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266714#M52623</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-27T14:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266718#M52624</link>
      <description>&lt;P&gt;&lt;FONT face="times new roman,times" size="3"&gt;Thanks RW,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="times new roman,times" size="3"&gt;Is there a way to see&amp;nbsp;the actual value as it is entered? While the strip function will often solve the problem, it still doesn't give me the exact response. I will still never know if the value is "&lt;FONT color="#800080"&gt;South Carolina " &lt;FONT color="#333333"&gt;or&lt;/FONT&gt; "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#800080"&gt;South Carolina" &lt;FONT color="#333333"&gt;or something else entirely.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 14:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266718#M52624</guid>
      <dc:creator>Noob</dc:creator>
      <dc:date>2016-04-27T14:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266721#M52626</link>
      <description>&lt;P&gt;Trailing blanks won't cause a problem, but leading blanks could. &amp;nbsp;Try checking what is actually there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq;&lt;/P&gt;
&lt;P&gt;tables state;&lt;/P&gt;
&lt;P&gt;format state $char25,.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The FORMAT statement will preserve any leading blanks in the table.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 14:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266721#M52626</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-27T14:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266726#M52628</link>
      <description>&lt;P&gt;The typical way to see if you have leading or trailing spaces is to display the value with a hex format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'09'x are tabs and there are some other characters that are spaces. I can't remember all of them. Hopefully someone like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;can explain it better than I can. I know it exists but not how to actually use it and don't have time to mock up an example now.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 14:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266726#M52628</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-27T14:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266728#M52629</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82992"&gt;@Noob﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Display the character variable in question with the $HEX&lt;EM&gt;w&lt;/EM&gt;. format, where width &lt;EM&gt;w&lt;/EM&gt; is at least twice the length of the string contained in the character variable (or equal to twice the defined length of the character variable, to see the full picture). The result might look cryptic, but it tells you exactly what's in the character variable. You can see leading and trailing blanks, non-standard blanks, characters which would otherwise be invisible or hard to distinguish from one another (e.g. hyphen vs. dash) -- all in two-digit hexadecimal codes (which you can look up in an ASCII or similar table).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
c=cats('ABC','A0'x,'DEF');
d='ABC DEF';
proc print;
run; /* The two strings look perfectly equal. */

data test;
set have;
if c=d then put 'equal'; /* This "equal" will not appear! */
put c $hex14.; 
put d $hex14.;  /* Here you see why. */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: When copying non-breakable spaces from a post into SAS they seem to be replaced with ordinary spaces. The edited example above does not suffer from this issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Edit 2: improved wording)&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 16:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266728#M52629</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-27T16:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266730#M52630</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;were your ears burning &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 14:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266730#M52630</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-27T14:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266734#M52633</link>
      <description>&lt;P&gt;As far as I know &lt;STRONG&gt;in &lt;/STRONG&gt;operator excludes trimming blanks from comparison therefore i believe you have other characters within &lt;STRONG&gt;South Carolina &lt;/STRONG&gt;value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider the following example:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;a='a&amp;nbsp;&amp;nbsp; &amp;nbsp;';/*you have a tab here*/&lt;BR /&gt;if a in ('a') then put '1 ' a=;&lt;BR /&gt;a='a ';/*you have a space here*/&lt;BR /&gt;if a in ('a') then put '2 ' a=;&lt;BR /&gt;a='a';&lt;BR /&gt;if a in ('a') then put '3 ' a=;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 14:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266734#M52633</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-04-27T14:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266736#M52634</link>
      <description>&lt;P&gt;Although both @loko &amp;amp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;examples are correct, it seems the browser changes them all to the same thing so it doesn't work as expected if you copy the code and try and run it &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 14:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266736#M52634</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-27T14:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Finding exact value of a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266762#M52643</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33792"&gt;@Loko﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;Thank you all very much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue in my particular case was not with leading or trailing blanks but with an extra hidden space in between 'South'&amp;nbsp;and 'Carolina'. Your examples were enlightening and should help me again in the future.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 16:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-exact-value-of-a-character-variable/m-p/266762#M52643</guid>
      <dc:creator>Noob</dc:creator>
      <dc:date>2016-04-27T16:38:03Z</dc:date>
    </item>
  </channel>
</rss>

