Hi,
I read the previous solutions on this board on removing a character from a string, but I still do not understand it.
I have a field called Code and in this field, there are some "." that I would like to remove (J.045).
The below is what I have so far, but it does not work:
Data VSD22;
Set VSD21;
Code=tranwrd(Code,'.','');
end;
Thank you in advance
To remove characters use COMPRESS(). To end a data step use RUN statement. END is use to end a DO loop, which your code does not include.
data VSD22;
set VSD21;
Code=compress(Code,'.');
run;
TRANWRD() is for replacing strings with other strings. Example: tranwrd(string,'hello','good-bye')
Normal SAS syntax does not generate empty string, so just because you did not type the space between the quotes you still gave tranwrd a string with one space to replace the string with one period.
If you want to replace a string with nothing you will need to use TRANSTRN() function. To actually create an empty string instead of the string with one blank space you would need to use TRIMN() function. Example: transtrn(string,'remove me',trimn(' '))
To remove characters use COMPRESS(). To end a data step use RUN statement. END is use to end a DO loop, which your code does not include.
data VSD22;
set VSD21;
Code=compress(Code,'.');
run;
TRANWRD() is for replacing strings with other strings. Example: tranwrd(string,'hello','good-bye')
Normal SAS syntax does not generate empty string, so just because you did not type the space between the quotes you still gave tranwrd a string with one space to replace the string with one period.
If you want to replace a string with nothing you will need to use TRANSTRN() function. To actually create an empty string instead of the string with one blank space you would need to use TRIMN() function. Example: transtrn(string,'remove me',trimn(' '))
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.