SAS String Function Tranwrd ( )

<< Go Back to SAS String Functions.

SAS TRANWRD () function works as find and replace utility. It takes 3 arguments; first is source string; second is string to be replaced and last one is string to be replaced by. TRANWRD will find out every occurrence of the second argument in the first argument and will replace it with the third argument.

TRANWRD () function has been demonstrated below;

SAS TRANWRD ( ) Function:

SYNTAX: TRANWRD (source_string, str_to_be_replaced, str_to_be_replaced_by);

Example: SAS TRANWRD ( ) Function

SAS Code:

proc print data = temp;

run;

PROC PRINT OUTPUT :

data temp;

str = "Mr John D'Suza";

new_str = tranwrd(str,"Mr", "Dr");

run;

Obs

1

str

Mr John D'Suza

new_str

Dr John D'Suza

* Please note this code has compiled on SAS 9.2 Platform.

We can observe from the output that; string “Mr” in str is replaced by “Dr”

Other Variants of TRANWRD () Function:

TRANSLATE (): This is used to replace the occurrences of single characters.

<< Go Back to SAS String Functions.