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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.