substr (s,p,n) with the character position command
function: The substitution and extraction of SAS characters.
Grammar:
1. Extract: New=substr (old,p,n)
Start extracting n-length characters from the first character of the variable old, and name it the variable new.
such as: New=substr (old,2,3); old= "ABCDEFG"; new= "BCD";
2. Replacement: substr (old,p,n) = "XXX"
The first character of the variable old is replaced by n characters, and the replacement content is "XXX".
such as: old= "ABCDEFG"; substr (old,2,3) = "123"; then old will become "A123EFG".
Tranwrd/translate (S, "oldxx", "newxx") command with character content
Function: tranwrd: The whole substitution of vocabulary (string) ; translate: bulk substitution of single characters
Grammar:
1. TRANWRD:
old= "St. Baker"; NEW=TRANWRD (Old, "St", "Street"); new= "Street. Baker ";
2. Translate:
Old=123456;new=translate (old, "246", "abc"), new= "1a3b5c";
SAS: Character substitution