<?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 SAS8; How to remove special characters from string? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59186#M16679</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am having difficulty removing special characters from string in SAS8, how can I remove them?&lt;BR /&gt;
&lt;BR /&gt;
For example,&lt;BR /&gt;
&lt;BR /&gt;
If I have the string abëd34Ý90$#$%a&lt;BR /&gt;
and would like to remove ë and Ý - how can I do this?&lt;BR /&gt;
&lt;BR /&gt;
Please note that I would only like to keep the following characters (ignoring the case):&lt;BR /&gt;
&lt;BR /&gt;
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&amp;amp;*()-_=+\|[]{};:',."&amp;lt;&amp;gt;?/&lt;BR /&gt;
and the space characters such as blankspace, tab character and new line character.&lt;BR /&gt;
&lt;BR /&gt;
I was able to accomplish this by defining an escape character and by using the compress function with the 'k' flag in SAS9 but we are still few months away from migrating to SAS9 in our production environment and thus I have to program in SAS8.</description>
    <pubDate>Wed, 05 Jan 2011 16:16:54 GMT</pubDate>
    <dc:creator>mkhan2010</dc:creator>
    <dc:date>2011-01-05T16:16:54Z</dc:date>
    <item>
      <title>SAS8; How to remove special characters from string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59186#M16679</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am having difficulty removing special characters from string in SAS8, how can I remove them?&lt;BR /&gt;
&lt;BR /&gt;
For example,&lt;BR /&gt;
&lt;BR /&gt;
If I have the string abëd34Ý90$#$%a&lt;BR /&gt;
and would like to remove ë and Ý - how can I do this?&lt;BR /&gt;
&lt;BR /&gt;
Please note that I would only like to keep the following characters (ignoring the case):&lt;BR /&gt;
&lt;BR /&gt;
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&amp;amp;*()-_=+\|[]{};:',."&amp;lt;&amp;gt;?/&lt;BR /&gt;
and the space characters such as blankspace, tab character and new line character.&lt;BR /&gt;
&lt;BR /&gt;
I was able to accomplish this by defining an escape character and by using the compress function with the 'k' flag in SAS9 but we are still few months away from migrating to SAS9 in our production environment and thus I have to program in SAS8.</description>
      <pubDate>Wed, 05 Jan 2011 16:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59186#M16679</guid>
      <dc:creator>mkhan2010</dc:creator>
      <dc:date>2011-01-05T16:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS8; How to remove special characters from string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59187#M16680</link>
      <description>I was able to solve this problem however my solution is not very elegant. If you have a better solution, please share.&lt;BR /&gt;
&lt;BR /&gt;
First, I defined an escape character at the top of my code:&lt;BR /&gt;
&lt;BR /&gt;
ODS escapechar='\';&lt;BR /&gt;
&lt;BR /&gt;
I called the string variable holding the string LONG_DESCRIPTION.&lt;BR /&gt;
&lt;BR /&gt;
here is the code:&lt;BR /&gt;
&lt;BR /&gt;
SPECIALCHAR = VERIFY(UPCASE(LONG_DESCRIPTION),"ABCDEFGHIJKLMNOP&lt;BR /&gt;
              QRSTUVWXYZ1234567890`~!@#$%¬&amp;amp;*()-_+={}[];:&amp;lt;&amp;gt;./?",&lt;BR /&gt;
              ",\\|'\n\t\_",'"');&lt;BR /&gt;
&lt;BR /&gt;
DO WHILE (SPECIALCHAR NE 0);&lt;BR /&gt;
   THECHAR=SUBSTR(LONG_DESCRIPTION,SPECIALCHAR,1);&lt;BR /&gt;
   LONG_DESCRIPTION = COMPRESS(LONG_DESCRIPTION,THECHAR);&lt;BR /&gt;
&lt;BR /&gt;
   SPECIALCHAR = VERIFY(UPCASE(LONG_DESCRIPTION),"ABCDEFGHIJKLMNOP&lt;BR /&gt;
               QRSTUVWXYZ1234567890`~!@#$%¬&amp;amp;*()-_+={}[];:&amp;lt;&amp;gt;./?",&lt;BR /&gt;
               ",\\|'\n\t\_",'"');&lt;BR /&gt;
&lt;BR /&gt;
END;

Message was edited by: mkhan2010</description>
      <pubDate>Wed, 05 Jan 2011 17:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59187#M16680</guid>
      <dc:creator>mkhan2010</dc:creator>
      <dc:date>2011-01-05T17:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS8; How to remove special characters from string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59188#M16681</link>
      <description>I used to do this by means of the translate function (if memory serves me well I should add since I don't have SAS at hand). Somewhat like&lt;BR /&gt;
[pre]&lt;BR /&gt;
target_string = translate(original_string,'','ëï') ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Note however that variable target_string will inherit its length from variable original_string which means that the resulting string will have the removed characters "replaced" by "padding" blanks.</description>
      <pubDate>Thu, 06 Jan 2011 07:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59188#M16681</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2011-01-06T07:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS8; How to remove special characters from string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59189#M16682</link>
      <description>In SAS8 removing an uncertain list of symbols was simplified by defining what you need to keep. That is now a feature in SAS9, but for SAS8 the approach was like: &lt;BR /&gt;
supposing you want only the numeric and alphabetic characters to be kept[pre]reduced = ( compress( original&lt;BR /&gt;
                    , compress( lowcase(original)&lt;BR /&gt;
                              , 'qwertyuiopasdfghjklzxcvbnm1234567890'&lt;BR /&gt;
 /* these are the alpha and numeric characters on my keyboard&lt;BR /&gt;
   once these are removed what is left are the ones I don't want &lt;BR /&gt;
   so these are the ones I want to compres out of the original string */&lt;BR /&gt;
                              ) &lt;BR /&gt;
                    )&lt;BR /&gt;
                     &lt;BR /&gt;
          ) ;[/pre]hope that helps</description>
      <pubDate>Thu, 06 Jan 2011 17:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/59189#M16682</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-01-06T17:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS8; How to remove special characters from string?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/343410#M63375</link>
      <description>&lt;P&gt;Since the original question was posted in 2011, it's assumed that by now&amp;nbsp;SAS®9 has been installed, therefore this solution is written for customers using&amp;nbsp;SAS®9 technology.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp; x=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'abëd34Ý90$#$%a'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp; new=compress(x,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&amp;amp;*()-_=+\|[]{};:',.&amp;lt;&amp;gt;?/ "&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; , &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"kis"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The COMPRESS function is typically used to remove&amp;nbsp;unwanted characters from a&amp;nbsp;variable, but in this example,&amp;nbsp;the characters to keep are specified.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In&amp;nbsp;the second argument of the COMPRESS function, specify&amp;nbsp;characters that you want to keep in X, and specify in the third argument any modifiers. In this example, the modifiers used are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;'k' keeps the characters in the list instead of removing them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'i'&amp;nbsp; ignores the case of the characters to be kept or removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 's' adds space characters (blank, horizontal tab, vertical tab, carriage return, line feed, and form feed) to the list of characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although there are different ways to solve this problem, I chose this approach for simplicity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 16:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS8-How-to-remove-special-characters-from-string/m-p/343410#M63375</guid>
      <dc:creator>kmw</dc:creator>
      <dc:date>2017-03-22T16:59:58Z</dc:date>
    </item>
  </channel>
</rss>

