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.
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','áéñÑ');
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");
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','áéñÑ');
data have;
want=basechar('José');
put want=;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.