<?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: Compress function for text variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108968#M30352</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. So,&lt;/P&gt;&lt;P&gt;if I've values such as "ab c", then I should use compress()&lt;/P&gt;&lt;P&gt;if I want to distinguish "ab c" from "abc" (that is I only want "abc") then I use strip() to handle heading or trailing blanks. But can I NOT even use strip() for such data selection, using just if text="abc" to achieve the goal?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 30 Aug 2012 17:17:49 GMT</pubDate>
    <dc:creator>Solph</dc:creator>
    <dc:date>2012-08-30T17:17:49Z</dc:date>
    <item>
      <title>Compress function for text variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108966#M30350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've a question about how SAS handles extra spaces in a variable. I was hoping to provide an example (below) with some of the data with 2 extra spaces before or after the text "abc" but somehow SAS strips the spaces off after reading in the data and becomes one value abc for all observations. But my question is quite simple. If I've data with spaces before or after some text for a variable, do I need to use the compress function to make sure I'm selecting only the text part?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I've 5 observations with text = "abc",&amp;nbsp; "&amp;nbsp; abc",&amp;nbsp; "abc&amp;nbsp; ",&amp;nbsp; "&amp;nbsp; abc&amp;nbsp; ", or "abcdef", I don't care about the extra spaces, and I want all 4 cases with only abc in it (I don't want the "abcdef" case), &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can I use just &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; IF text='abc'; &lt;/P&gt;&lt;P&gt;or I need to use the compression function:&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF COMPRESS(text)='abc'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I read somewhere that SAS's default is compressing spaces with statements such as the following. Is it correct? If so, I can just use IF text='abc' as it is redundant to use IF COMPESS(text)='abc';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if compress (var, &lt;SPAN style="font-family: 'Courier New',Courier,monospace;"&gt;''&lt;/SPAN&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; new_variable=compress (variable, &lt;SPAN style="font-family: 'Courier New',Courier,monospace;"&gt;''&lt;/SPAN&gt;);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------Example - though it seems SAS automatically compresses the data once reading in the data, &lt;/P&gt;&lt;P&gt;data aa; input text $ 1-10;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;abc&lt;/P&gt;&lt;P&gt;abc&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; abc&lt;/P&gt;&lt;P&gt;&amp;nbsp; abc&amp;nbsp;&amp;nbsp; &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;data aa1; set aa;&lt;/P&gt;&lt;P&gt;if text='abc' then v1=1;&lt;/P&gt;&lt;P&gt;proc print; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 17:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108966#M30350</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-08-30T17:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function for text variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108967#M30351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, you didn't mention what if the blank is in the middle of your char value, such as: 'ab c', do you still want to remove it? if yes, compress() can do it for sure. if no, then use strip() to take care of heading or trailing blanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 17:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108967#M30351</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-08-30T17:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function for text variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108968#M30352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. So,&lt;/P&gt;&lt;P&gt;if I've values such as "ab c", then I should use compress()&lt;/P&gt;&lt;P&gt;if I want to distinguish "ab c" from "abc" (that is I only want "abc") then I use strip() to handle heading or trailing blanks. But can I NOT even use strip() for such data selection, using just if text="abc" to achieve the goal?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 17:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108968#M30352</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-08-30T17:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function for text variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108969#M30353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai.kuo gave you the right answer.&amp;nbsp; Here's a little more detail.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use if text="abc" if you have trailing blanks, but not if you have leading blanks.&amp;nbsp; For leading blanks, you will need the strip function.&amp;nbsp; Your sample program does not give you the result that you think you are getting.&amp;nbsp; The INPUT instructions (input text $ 1-10;) will left-hand justify the characters found in columns 1-10.&amp;nbsp; So you actually do not have any leading blanks once the INPUT statement has run.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 17:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108969#M30353</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-08-30T17:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function for text variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108970#M30354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You stated "If I've data with spaces before or after some text for a variable, do I need to use the compress function to make sure I'm selecting only the text part?"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that's the case and you don't care about spaces in between (i.e., you don't want the 'a bc'), you only want ' abc', 'abc ', 'abc' then you can just use the STRIP function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF STRIP(text)='abc';&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 17:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108970#M30354</guid>
      <dc:creator>robby_beum</dc:creator>
      <dc:date>2012-08-30T17:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function for text variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108971#M30355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok strip it is based on your expertise from all. Off the topic, how can I create a sample data with leading blanks to test on it? Indeed I noticed SAS would automatically left adjust. Is there a way for me to make SAS not to do it so that I have leading blank data to be able to compare using strip vs not using strip?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 18:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108971#M30355</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-08-30T18:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function for text variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108972#M30356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Change the instructions on the INPUT statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;input @1 text $char10.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The $CHAR family of informats preserves the leading blanks it finds (and is also faster even if you have no leading blanks).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 18:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compress-function-for-text-variables/m-p/108972#M30356</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-08-30T18:14:35Z</dc:date>
    </item>
  </channel>
</rss>

