TRANWRD SUBSTR

Reply
Occasional Contributor
Posts: 16

TRANWRD SUBSTR

hello, I want to replace a substr in a text to some else, somehow the following does not work. Any ideas? If I assign the string values to the temp_str and new_str, the F1 is updated as intended. Thank you,

DATA TEST;

F1 = "9999,'ABC', 110,2,    0.00,    0.00, 14, 17,1.02454,  27.9937,1";

CALL SCAN(F1,5,POS,LEN,',');

TEMP_STR = SUBSTR(F1,1,POS-2);

NEW_STR = CAT(SUBSTR(F1,1,POS-3),'1');

F1 = TRANWRD(F1,TEMP_STR,NEW_STR);

RUN;

Super User
Posts: 11,134

Re: TRANWRD SUBSTR

It is a good idea describe the intended output instead of just "doesn't work".

You're not getting the match you expect because both TEMP_STR and NEW_STR are 200 characters long and all of them are used in the comparison.

You may want:

TRANWRD(F1,strip(TEMP_STR),strip(NEW_STR))

Occasional Contributor
Posts: 16

Re: TRANWRD SUBSTR

the STRIP worked. so by default, the substr is 200 characters long?

Super User
Posts: 11,134

Re: TRANWRD SUBSTR

The result of CAT, and many other string functions, is 200 unless you define the variable first. But even with a defined length you would likely have the comparison for some values with the trailing blanks. So it is a good idea to STRIP values. Though you need other approaches if you want leading blanks compared...

Ask a Question
Discussion stats
  • 3 replies
  • 246 views
  • 0 likes
  • 2 in conversation