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:
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?
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.
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.
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.