Giorgio Spedicato
Giorgio Spedicato

Reputation: 2503

filter specific unicode character in SAS

I need to replace a specific unicode character in SAS, exactly the U+0191 with a whitespace or blank. How can I do it by COMPRESS ? Thanks in advance.

Upvotes: 1

Views: 585

Answers (1)

Joe
Joe

Reputation: 63424

You should use the KCOMPRESS function rather than COMPRESS for compressing unicode characters, as it is considered safer for Unicode and DBCS environments.

However, it sounds like you actually want to TRANSLATE, or more accurately KTRANSLATE, which actually replaces characters with whitespace or other characters (as opposed to removing them, as COMPRESS does).

Here's an example:

data have;
  charvar = "Ƒellow Americans";
  fixed_charvar = translate(charvar,'F','Ƒ');
  kfixed_charvar= ktranslate(charvar,'F','Ƒ');
  put _all_;
run;

Here I convert U+0191 to a normal F; of course you can convert to space as you wish (Replace the 'F' with whatever you want it converted to).

This will work in an instance of SAS set up in Unicode mode; if you're running in WLATIN1 or similar, you may have more difficulty, particularly with actually passing SAS the U+0191 character.

Upvotes: 4

Related Questions