Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Trimn retruns a null string of zero-length string. But here it is returning one blank character. Why?

Reply
Contributor
Posts: 49

Trimn retruns a null string of zero-length string. But here it is returning one blank character. Why?

data _null_;

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

   put string1=;

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

   put string2=;

run;

string1=* x *

string2=* x *

Super Contributor
Posts: 349

Re: Trimn retruns a null string of zero-length string. But here it is returning one blank character. Why?

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

Ask a Question
Discussion stats
  • 1 reply
  • 267 views
  • 0 likes
  • 2 in conversation