SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jose7
Obsidian | Level 7

Hi experts,

 

I'm using tranwrd in sas enterprice guide and works fine, but when i use it in the linux environment it does not work

data ALTAS_DEF;
set ALTAS_DEF;
First_name = tranwrd(First_name, 'ñ', 'n');

run;

i just want to change a letter for other one, do you know a work around about it ? or an equivalent function ?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20
For all your accented letters:
data EXAMPLE ;
%* Test string;
STR1 = 'aaâäÊÉŒñbb';
%* Single letter replacements;
STR2 = ktranslate( STR1
, 'AAAAAACEEEEIIIIDNOOOOOOUUUUYaaaaaaceeeeiiiidnoooooouuuuyy'
, 'ÀÁÂÃÅÄÇÈÉÊËÌÍÎÏÐÑÒÓÔÕØÖÙÚÛÜÝàáâãåäçèéêëìíîïðñòóôõøöùúûüýÿ' );
%* Double letter replacements;
STR3 = tranwrd ( STR2, 'Æ', 'AE' );
STR3 = tranwrd ( STR3, 'æ', 'ae' );
STR3 = tranwrd ( STR3, 'Œ', 'OE' );
STR3 = tranwrd ( STR3, 'œ', 'oe' );
STR3 = tranwrd ( STR3, 'ß', 'ss' );
run;
SAS does not support the regular expression syntax needed to do this in one go.

View solution in original post

5 REPLIES 5
Ksharp
Super User

If you only need to change a character ,NOT a word/string, try KTRANSLATE().

data s;
 set sashelp.class;
First_name = ktranslate(name, 'n','ñ');

run;
Jose7
Obsidian | Level 7
Thks, it works
ChrisNZ
Tourmaline | Level 20
For all your accented letters:
data EXAMPLE ;
%* Test string;
STR1 = 'aaâäÊÉŒñbb';
%* Single letter replacements;
STR2 = ktranslate( STR1
, 'AAAAAACEEEEIIIIDNOOOOOOUUUUYaaaaaaceeeeiiiidnoooooouuuuyy'
, 'ÀÁÂÃÅÄÇÈÉÊËÌÍÎÏÐÑÒÓÔÕØÖÙÚÛÜÝàáâãåäçèéêëìíîïðñòóôõøöùúûüýÿ' );
%* Double letter replacements;
STR3 = tranwrd ( STR2, 'Æ', 'AE' );
STR3 = tranwrd ( STR3, 'æ', 'ae' );
STR3 = tranwrd ( STR3, 'Œ', 'OE' );
STR3 = tranwrd ( STR3, 'œ', 'oe' );
STR3 = tranwrd ( STR3, 'ß', 'ss' );
run;
SAS does not support the regular expression syntax needed to do this in one go.
ChrisNZ
Tourmaline | Level 20

I'm using tranwrd in sas enterprice guide and works fine, but when i use it in the linux environment it does not work

This makes no sense. The SAS language is the very same on all platforms. I suspect you have another issue, like encoding.

Run this to verify:

%put &=sysencoding;

 

 

 

 

Tom
Super User Tom
Super User

It is usually not a good idea to insert non 7-bit ASCII character constants into your program.  Then the meaning of the code will change depending on the character encoding that is being used.

 

The Spanish character "enye" will be stored as different sets of bytes depending on the encoding you are using.  And for some single byte encodings it might not even exist.

 

To check what encoding SAS is using for your SAS session check the value of the ENCODING system option.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 867 views
  • 4 likes
  • 4 in conversation