In reply to Guido Wendland.

Thank you, Guido, it's an interesting approach. Indeed, your code will work, but only (as you mentioned) "if your original string does not contain spaces" which is rarely the case.
Replacing spaces by some exotic characters approach is also described in the SAS code Sample 39036: Eliminating duplicate characters in a string. But I believe it's rather dangerous as those "exotic" characters might be legitimate characters in the original data. That is why I would rather rely on a more universal and robust approach presented in this blog post.