<?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: Subsetting where statement with blank space producing unexpected results in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739036#M230614</link>
    <description>&lt;P&gt;SAS stores character strings as fixed length padded with spaces.&lt;/P&gt;
&lt;P&gt;So when it compares two strings it ignores the trailing spaces.&lt;/P&gt;</description>
    <pubDate>Tue, 04 May 2021 18:54:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-05-04T18:54:41Z</dc:date>
    <item>
      <title>Subsetting where statement with blank space producing unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739034#M230612</link>
      <description>&lt;P&gt;Can someone explain why this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	set sashelp.class;
	where name='Alice';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;gives the same results as this (space after Alice)?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	set sashelp.class;
	where name='Alice ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would think the blank space would cause SAS to not evaluate it as equivalent.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 18:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739034#M230612</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2021-05-04T18:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting where statement with blank space producing unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739036#M230614</link>
      <description>&lt;P&gt;SAS stores character strings as fixed length padded with spaces.&lt;/P&gt;
&lt;P&gt;So when it compares two strings it ignores the trailing spaces.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 18:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739036#M230614</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-04T18:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting where statement with blank space producing unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739038#M230615</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Since trailing blanks are ignored in a comparison,&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;'fox '&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;is equivalent to&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;'fox'&lt;/CODE&gt;&lt;SPAN&gt;. However, because blanks at the beginning and in the middle of a character value are significant to SAS,&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;' fox'&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;is not equivalent to&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;'fox'&lt;/CODE&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/p00iah2thp63bmn1lt20esag14lh.htm#p1vu0ts68u42xun141p7vt4ne29k" target="_blank"&gt;https://documentation.sas.com/doc/en/lrcon/9.4/p00iah2thp63bmn1lt20esag14lh.htm#p1vu0ts68u42xun141p7vt4ne29k&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2 id="p1vu0ts68u42xun141p7vt4ne29k" class="xisDoc-title"&gt;Character Comparisons&lt;/H2&gt;
&lt;P class="xisDoc-paragraph"&gt;You can perform comparisons on character operands, but the comparison always yields a numeric result (1 or 0). Character operands are compared character by character from left to right. Character order depends on the collating sequence, usually ASCII or EBCDIC, used by your computer.&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;For example, in the EBCDIC and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN aria-live="polite"&gt;&lt;BUTTON class="Glossary_term__1sogC LinkButton_button__17uC9" aria-label="ASCII collating sequences"&gt;&lt;SPAN class="xisDoc-glossTerm" data-gloss-term="1"&gt;ASCII collating sequences&lt;/SPAN&gt;&lt;/BUTTON&gt;&lt;/SPAN&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;G&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is greater than&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;A&lt;/CODE&gt;. Therefore, this expression is true:&lt;/P&gt;
&lt;PRE class="xisDoc-codeFragment"&gt;&lt;CODE&gt;'Gray'&amp;gt;'Adams'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xisDoc-paragraph"&gt;Two-&lt;SPAN aria-live="polite"&gt;&lt;BUTTON class="Glossary_term__1sogC LinkButton_button__17uC9" aria-label="character values"&gt;&lt;SPAN class="xisDoc-glossTerm" data-gloss-term="1"&gt;character values&lt;/SPAN&gt;&lt;/BUTTON&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of unequal length are compared as if blanks were attached to the end of the shorter value before the comparison is made. A blank, or missing character value, is smaller than any other printable character value. For example, because&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;.&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is less than&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;h&lt;/CODE&gt;, this expression is true:&lt;/P&gt;
&lt;PRE class="xisDoc-codeFragment"&gt;&lt;CODE&gt;'C. Jones'&amp;lt;'Charles Jones'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xisDoc-paragraph"&gt;Since trailing blanks are ignored in a comparison,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;'fox '&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is equivalent to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;'fox'&lt;/CODE&gt;. However, because blanks at the beginning and in the middle of a character value are significant to SAS,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;' fox'&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is not equivalent to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;'fox'&lt;/CODE&gt;.&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;You can compare only a specified prefix of a character expression by using a colon (:) after the comparison operator. SAS truncates the longer value to the length of the shorter value during the comparison. In the following example, the colon modifier after the equal sign tells SAS to look at only the first character of values of the variable LastName and to select the observations with names beginning with the letter&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;S&lt;/CODE&gt;:&lt;/P&gt;
&lt;PRE class="xisDoc-codeFragment"&gt;&lt;CODE&gt;if lastname=:'S';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xisDoc-paragraph"&gt;Because printable characters are greater than blanks, both of the following statements select observations with values of LastName that are greater than or equal to the letter&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-inlineCode"&gt;S&lt;/CODE&gt;:&lt;/P&gt;
&lt;UL class="xisDoc-listUnordered"&gt;
&lt;LI class="xisDoc-item"&gt;&lt;CODE class="xisDoc-inlineCode"&gt;if lastname&amp;gt;='S';&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI class="xisDoc-item"&gt;&lt;CODE class="xisDoc-inlineCode"&gt;if lastname&amp;gt;=:'S';&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV id="n08pxicc2vpiefn162oz020re0nz" class="xisDoc-note"&gt;&lt;SPAN class="xisDoc-noteGenText"&gt;Note:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;If you compare a zero-length character value with any other character value in either an IN: comparison or an EQ: comparison, the two-character values are not considered equal. The result always evaluates to 0, or false.&lt;/DIV&gt;
&lt;P class="xisDoc-paragraph"&gt;The operations that are discussed in this section show you how to compare entire character strings and the beginnings of character strings. Several SAS&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN aria-live="polite"&gt;&lt;BUTTON class="Glossary_term__1sogC LinkButton_button__17uC9" aria-label="character functions"&gt;&lt;SPAN class="xisDoc-glossTerm" data-gloss-term="1"&gt;character functions&lt;/SPAN&gt;&lt;/BUTTON&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;enable you to search for and extract values from within character strings. See&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A tabindex="0" href="https://documentation.sas.com/doc/en/lefunctionsref/9.4/titlepage.htm" target="_blank"&gt;&lt;I&gt;SAS Functions and CALL Routines: Reference&lt;/I&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for complete descriptions of all SAS functions.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 18:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739038#M230615</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-04T18:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting where statement with blank space producing unexpected results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739041#M230617</link>
      <description>Thank you for the detailed response Reeza, very helpful!</description>
      <pubDate>Tue, 04 May 2021 19:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-where-statement-with-blank-space-producing-unexpected/m-p/739041#M230617</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2021-05-04T19:35:28Z</dc:date>
    </item>
  </channel>
</rss>

