BookmarkSubscribeRSS Feed
devarayalu
Fluorite | Level 6

data _null_;

   string1='*' || tranwrd('abcxabc', 'abc', trimn('')) || '*';

   put string1=;

   string2='*' || tranwrd('abcxabc', 'abc', '') || '*';

   put string2=;

run;

string1=* x *

string2=* x *

1 REPLY 1
shivas
Pyrite | Level 9

Hi,

From SAS documentation,

The TRANWRD function replaces all occurrences of a given substring within a character string. The TRANWRD function does not remove trailing blanks in the target string and the replacement string.

TRANWRD uses a single blank instead when the replacement string has a length of zero.

Try using compress to remove all the blank spaces,if you want.

data _null_;

   string1='*' || compress(tranwrd('abcxabc', 'abc', trimn(''))) || '*';

   put string1=;

   string2='*' || compress('abcxabc', 'abc', '') || '*';

   put string2=;

run;

Thanks,

Shiva

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1079 views
  • 0 likes
  • 2 in conversation