BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
msharma1788
Calcite | Level 5

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.

       

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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");
ballardw
Super User

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','áéñÑ');

msharma1788
Calcite | Level 5
Thanks! this really helps 🙂
Ksharp
Super User
data have;
 want=basechar('José');
 put want=;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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