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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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(' '))

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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(' '))

Jesusismygrace
Obsidian | Level 7
Thank you!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 36272 views
  • 3 likes
  • 2 in conversation