BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
EinarRoed
Pyrite | Level 9

Hello!

We need to remove certain pesky characters from a freetext field we're reading from a source system.

Some of the things we must remove are:

  • Double double quotation marks (""). To be clear: The single character " two times in a row.
  • The carriage return symbol identified as '0D'x in SAS

This doesn't seem to work due to the use of ' in 0D'x:

	do chars_to_remove = '""', '0D'x';
		input_string = tranwrd(input_string, chars_to_remove, '');
	end;

Can you please suggest a good way to handle this?

1 ACCEPTED SOLUTION

Accepted Solutions
LeonidBatkhan
Lapis Lazuli | Level 10

Hi EinarRoed,

 

To remove "" use transtrn() function with trimn('') as the 3-rd argument:

 

input_string = transtrn(input_string, '""', trimn(''));

To further remove carriage return symbol along with all control symbols use compress() function with 'c' modifier as the 3-rd argument:

 

input_string = compress(input_string,,'c');

Hope this helps.

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

Try

tranwrd(input_string, trim(chars_to_remove), ' ');

The tranwrd function will insert a single blank even if you don't want it, switching to transtrn or using compbl will solve that issue.

LeonidBatkhan
Lapis Lazuli | Level 10

Hi EinarRoed,

 

To remove "" use transtrn() function with trimn('') as the 3-rd argument:

 

input_string = transtrn(input_string, '""', trimn(''));

To further remove carriage return symbol along with all control symbols use compress() function with 'c' modifier as the 3-rd argument:

 

input_string = compress(input_string,,'c');

Hope this helps.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 488 views
  • 3 likes
  • 3 in conversation