DATA Step, Macro, Functions and more

Invalid ASCII character in name.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Invalid ASCII character in name.

Requirement is to replace invalid character with valid character.

In case a dataset has the below values.

FIELD

FLDVALUE

FNAME

José

LNAME

Colón

LNAME

Colón

LNAME

Burgos-Suárez

LNAME

Nogueras-López

LNAME

Camacho-De León

LNAME

Padilla-Rodríguez

LNAME

Vilaró

MID

C>

LNAME

Vázquez-Hernández

LNAME

Montaño

LNAME

Camacho-De León

FNAME

Michaéla

We need the value as José = Jose

                                    Burgos-Suárez= Burgos-Suarez                

This data id pulled from EFT File and we need to reformat this data.

 

Please suggest.

       


Accepted Solutions
Solution
‎02-15-2018 02:26 AM
Super User
Posts: 13,347

Re: Invalid ASCII character in name.

Posted in reply to msharma1788

You do not tell us all characters are "invalid".

Likely you are looking for the TRANSLATE function which you provide a search string and a replacement string. Every character in the search string would be replaced by the corresponding character in the replacement string.

Suppose I want to replace > with a space and ! with and L in a variable then

 

str = translate(str,' L','>!');

 

note that the replacement list comes first and the search list of characters second. The number of characters in the replacement and search lists must match. if you want to replace every value in the search list with a blank then you need one blank for each character such as

str = translate(str,' ','!@#$%^&*()');

you would also need to ensure that you have the matching cases such as

str = translate(str,'aenN','áéñÑ');

View solution in original post


All Replies
Super User
Super User
Posts: 9,441

Re: Invalid ASCII character in name.

Posted in reply to msharma1788

Use National Language support, change SAS session to UTF-8 encoding.  Do a tranwrd() stastement for each character to change e.g.

want=tranwrd(have,"é","e");
Solution
‎02-15-2018 02:26 AM
Super User
Posts: 13,347

Re: Invalid ASCII character in name.

Posted in reply to msharma1788

You do not tell us all characters are "invalid".

Likely you are looking for the TRANSLATE function which you provide a search string and a replacement string. Every character in the search string would be replaced by the corresponding character in the replacement string.

Suppose I want to replace > with a space and ! with and L in a variable then

 

str = translate(str,' L','>!');

 

note that the replacement list comes first and the search list of characters second. The number of characters in the replacement and search lists must match. if you want to replace every value in the search list with a blank then you need one blank for each character such as

str = translate(str,' ','!@#$%^&*()');

you would also need to ensure that you have the matching cases such as

str = translate(str,'aenN','áéñÑ');

Occasional Contributor
Posts: 5

Re: Invalid ASCII character in name.

Thanks! this really helps Smiley Happy
Super User
Posts: 10,695

Re: Invalid ASCII character in name.

Posted in reply to msharma1788
data have;
 want=basechar('José');
 put want=;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 129 views
  • 0 likes
  • 4 in conversation