<?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 keep specific characters in string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/664695#M198678</link>
    <description>&lt;P&gt;I want to keep only English characters ,hyphen "-" , and Arabic characters .this code worked fine for the&amp;nbsp; English characters and hyphen but it escape the Arabic characters&amp;nbsp; , how can I keep the Arabic&amp;nbsp;characters&amp;nbsp; too !!&lt;/P&gt;&lt;P&gt;that's a screenshot of the code and the output log&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (467).png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46583i100E13CE9C5E842C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot (467).png" alt="Screenshot (467).png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jun 2020 16:23:20 GMT</pubDate>
    <dc:creator>nour_anwar</dc:creator>
    <dc:date>2020-06-24T16:23:20Z</dc:date>
    <item>
      <title>keep specific characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/664695#M198678</link>
      <description>&lt;P&gt;I want to keep only English characters ,hyphen "-" , and Arabic characters .this code worked fine for the&amp;nbsp; English characters and hyphen but it escape the Arabic characters&amp;nbsp; , how can I keep the Arabic&amp;nbsp;characters&amp;nbsp; too !!&lt;/P&gt;&lt;P&gt;that's a screenshot of the code and the output log&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (467).png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46583i100E13CE9C5E842C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot (467).png" alt="Screenshot (467).png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 16:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/664695#M198678</guid>
      <dc:creator>nour_anwar</dc:creator>
      <dc:date>2020-06-24T16:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: keep specific characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/665834#M199138</link>
      <description>&lt;P&gt;As I can not enter Arabic letters on my swiss german keyboard, I went to use unicode symbols. The program below was run in a UTF-8 SAS session.&lt;/P&gt;
&lt;P&gt;Please note the use of KCOMPRESS to deal with multibyte character sets, COMPRESS can only handle single byte character sets. See here for more details&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/?docsetId=nlsref&amp;amp;docsetTarget=n01wgwo05gbv68n1w1u68i89pbtw.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://go.documentation.sas.com/?docsetId=nlsref&amp;amp;docsetTarget=n01wgwo05gbv68n1w1u68i89pbtw.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I but together a string with all the chars I want to keep and then use the "KI" modifiers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give it a try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length someText chars2keep $ 4096;
  chars2keep="- abcdefghijklmnopqrstuvwxyz";

  do arabicUnicode=0621x to 064Ax;
    arabic=unicode(cats("\u", put(arabicUnicode, hex4.)));
    chars2keep=cats(chars2keep, arabic);
  end;
  putlog chars2keep=;
  someText="*öäü*ab-cd_123_رياضة أنا أحب رياضتي وأنا سعيد حقا هنا لها حبي*";
  someText2=kcompress(someText, chars2keep, "ki");
  putlog (_all_) (=/);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For a next time please provide text, so that one can easily copy paste&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 16:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/665834#M199138</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-06-29T16:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: keep specific characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666082#M199236</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt;&amp;nbsp; thanks alot for help !!&lt;/P&gt;&lt;P&gt;i tried you code but I got this error: ERROR 72-185: The KCOMPRESS function call has too many arguments.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 13:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666082#M199236</guid>
      <dc:creator>nour_anwar</dc:creator>
      <dc:date>2020-06-30T13:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: keep specific characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666133#M199257</link>
      <description>&lt;P&gt;this has to do with the SAS Version, see here for more details:&amp;nbsp;&lt;A href="https://support.sas.com/kb/63/402.html" target="_blank"&gt;https://support.sas.com/kb/63/402.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You do need SAS9.4M6 for it to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To better understand how you run SAS, can you provide the SAS log of the code below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put NOTE: &amp;amp;=sysvlong &amp;amp;=sysscpl;
proc options group=languagecontrol;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your SAS session is using a single byte encoding, you should be able to just use the COMPRESS function&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 15:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666133#M199257</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-06-30T15:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: the o/p log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666213#M199298</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;209 %put NOTE: &amp;amp;=sysvlong &amp;amp;=sysscpl;&lt;BR /&gt;NOTE: SYSVLONG=9.04.01M3P062415 SYSSCPL=X64_8HOME&lt;BR /&gt;210 proc options group=languagecontrol;&lt;BR /&gt;211 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS (r) Proprietary Software Release 9.4 TS1M3&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Group=LANGUAGECONTROL&lt;BR /&gt;DATESTYLE=DMY Specifies the sequence of month, day, and year when ANYDTDTE, ANYDTDTM, or&lt;BR /&gt;ANYDTTME informat data is ambiguous.&lt;BR /&gt;DFLANG=ENGLISH Specifies the language for international date informats and formats.&lt;BR /&gt;EXTENDOBSCOUNTER=YES&lt;BR /&gt;Specifies whether to extend the maximum number of observations in a new SAS&lt;BR /&gt;data file.&lt;BR /&gt;LOCALEDATA=SASLOCALE&lt;BR /&gt;Specifies the location of the locale database.&lt;BR /&gt;NOLOGLANGCHG Disables changing the language of the SAS output when the LOCALE= option is&lt;BR /&gt;changed.&lt;BR /&gt;NOLOGLANGENG Write SAS log messages based on the values of the LOGLANGCHG, LSWLANG=, and&lt;BR /&gt;LOCALE= options when SAS started.&lt;BR /&gt;LSWLANG=LOCALE Specifies the language for SAS log and ODS messages when the LOCALE= option is&lt;BR /&gt;set after SAS starts.&lt;BR /&gt;MAPEBCDICTOASCII= Specifies the transcoding table that is used to convert characters from ASCII&lt;BR /&gt;to EBCDIC and EBCDIC to ASCII.&lt;BR /&gt;NONLDECSEPARATOR Disables formatting of numeric output using the decimal separator for the&lt;BR /&gt;locale.&lt;BR /&gt;NOODSLANGCHG Disables changing the language of the SAS message text in ODS output when the&lt;BR /&gt;LOCALE option is set after start up.&lt;BR /&gt;PAPERSIZE=LETTER Specifies the paper size to use for printing.&lt;BR /&gt;RSASIOTRANSERROR Displays a transcoding error when illegal values are read from a remote&lt;BR /&gt;application.&lt;BR /&gt;TIMEZONE= Specifies a time zone.&lt;BR /&gt;TRANTAB=(lat1lat1,lat1lat1,wlt1_ucs,wlt1_lcs,wlt1_ccl,,,)&lt;BR /&gt;Specifies the translation table catalog entries.&lt;BR /&gt;URLENCODING=SESSION&lt;BR /&gt;Specifies whether the argument to the URLENCODE function and to the URLDECODE&lt;BR /&gt;function is interpreted using the SAS session encoding or UTF-8 encoding.&lt;BR /&gt;NODBCS Disables double-byte character sets.&lt;BR /&gt;DBCSLANG=NONE Specifies a double-byte character set language.&lt;BR /&gt;DBCSTYPE=NONE Specifies the encoding method to use for a double-byte character set.&lt;BR /&gt;ENCODING=WLATIN1 Specifies the default character-set encoding for the SAS session.&lt;BR /&gt;LOCALE=AR_EG Specifies a set of attributes in a SAS session that reflect the language,&lt;BR /&gt;local conventions, and culture for a geographical region.&lt;BR /&gt;NONLSCOMPATMODE Encodes data using the SAS session encoding.&lt;BR /&gt;NOTE: PROCEDURE OPTIONS used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 20:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666213#M199298</guid>
      <dc:creator>nour_anwar</dc:creator>
      <dc:date>2020-06-30T20:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: keep specific characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666263#M199314</link>
      <description>&lt;P&gt;Seems to be the problem that has been discussed in &lt;A href="https://communities.sas.com/t5/SAS-Programming/RegEx-and-Arabic-letters/m-p/664689" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/RegEx-and-Arabic-letters/m-p/664689&lt;/A&gt; last week.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 05:05:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666263#M199314</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-07-01T05:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: the o/p log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666268#M199318</link>
      <description>&lt;P&gt;You are running SAS in the wlatin1 encoding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this SAS note&amp;nbsp;&lt;A href="https://support.sas.com/kb/18/577.html" target="_blank"&gt;https://support.sas.com/kb/18/577.html&lt;/A&gt;&amp;nbsp;to configure your SAS to deal with arabic letters. Set the LOCALE according to your needs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since this is using a single byte character set you can use the COMPRESS function. Instead of the loop in my sample program to add arabic letters you can simply type them in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also see here for supported LOCALE and ENCODING&amp;nbsp;&lt;A href="https://go.documentation.sas.com/?docsetId=nlsref&amp;amp;docsetTarget=p0yctvkmmbdwl2n1k87qd1nv1nu3.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://go.documentation.sas.com/?docsetId=nlsref&amp;amp;docsetTarget=p0yctvkmmbdwl2n1k87qd1nv1nu3.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 06:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666268#M199318</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-07-01T06:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: the o/p log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666271#M199320</link>
      <description>&lt;P&gt;If you can't use the 3rd argument of the kcompress() function then I guess you need to do something "ugly" along the line of below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data validChars;
  input validChars :$4.;
  output;
  if validChars ne upcase(validChars) then
    do;
      validChars = upcase(validChars);
      output;
    end;
  datalines;
a
b
d
e
_
;

data have;
  infile datalines truncover;
  input have_str $20.;
  datalines;
abc def ghi
acccb ss_s ghbik
abdd ee ffee
;


data want(drop=validChars _:);
  if _n_=1 then
    do;
      if 0 then set validChars;
      dcl hash h1(dataset:'validChars');
      h1.defineKey('validChars');
      h1.defineDone();
    end;
  
  set have;
  want_str=have_str;
  want_str=kcompress(want_str);
  _l=klength(want_str);
  length _char $4;
  do _i=1 to _l;
    _char=KSUBSTR(want_str, _i,1);
    if _char ne ' ' and h1.check(key:_char) ne 0 then 
      want_str=KTRANSLATE(want_str,' ',_char);
  end;
  want_str=kcompress(want_str);
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1593584388923.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46814i12892B6A907E531F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1593584388923.png" alt="Patrick_0-1593584388923.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 06:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666271#M199320</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-01T06:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: keep specific characters in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666276#M199323</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;The KCOMPRESS function call has too many arguments.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;You can still use function kcompress() with 2 arguments; just list all the unwanted characters as the second argument.&lt;/P&gt;
&lt;P&gt;A bit more tedious than listing the characters you want to keep, but still valid.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 06:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-specific-characters-in-string/m-p/666276#M199323</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-07-01T06:35:56Z</dc:date>
    </item>
  </channel>
</rss>

