BookmarkSubscribeRSS Feed
abdelrahmanmaha
Calcite | Level 5

In this topic we will deal with removing special characters 

1- Tranwrd 

tranwrd(column, "?", " ")
input: "Hello?World"
output: "Hello World"
Note: the result is always 200 byte, so keep using length=<length>
good for: replacing or removing single character

document: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000215027.htm

2- Translate

Translate(column, "`~!@#$%^&*()-_=+\|[]{};:',.<>?/")
input: "Hel)lo?Wo.r*ld"
output: "HelloWorld"
Note: try to replace ? which used as "space" using tranwrd then use translate
good for:
1- removing special characters if spaces are exist
2- It also have some character option for lower, upper, and letters,...

documentation: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000215153.htm 

3- Compress and Kcompress 

compress(column, "c3b9"x)
compress(column,"`~!@#$%^&*()-_=+\|[]{};:',.<>?/")
c3b9 is the hexadecimal of ù
x is used for hexadecimal representation
input: "Hello World�"
output: "Hello World"
Note: use x if you need hex repr cause chars like � has different hex representation
take the string which has this special character to text to hex converted and use it's hex to remove it
good for:
1- removing hard special characters
2- It also have some modifiers in documentation which help a lot

Documentation:  http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212246.htm

 

4- kpropdata(COLUMNA ,'hex', 'utf-8') followed by Tranwrd #1

kpropdata(COLUMN ,'hex', 'utf-8') 
if you have this char "�" and followed compress and kcompress hex and normal text and not works
you should consider kpropdata which Removes or converts unprintable characters
also if you find hex "efbfbd" which refers to corrupted string
the only way which works with me was kpropdata followed by tranwrd

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 0 replies
  • 12303 views
  • 3 likes
  • 1 in conversation