Help using Base SAS procedures

Remove Character

Reply
New Contributor sfs
New Contributor
Posts: 2

Remove Character

I am trying to remove characters after a space in a string variable.
i.e. Change "Johns,Robert James" to "Johns,Robert".

In excel, the function is =LEFT(B2,FIND(" ",B2,1)-1) But my file is too big that I cannot change the variable in Excel.

How can I write the code to convert the variable?

Thanks
Super Contributor
Super Contributor
Posts: 3,174

Re: Remove Character

Using a DATA step, have a SAS assignment statement use SUBSTR function and also the FIND function (to locate the first blank from the end) using a negative value for argument #3 to start from the end of the variable.

Scott Barry
SBBWorks, Inc.
New Contributor sfs
New Contributor
Posts: 2

Re: Remove Character

Thanks a million.
Frequent Contributor
Posts: 91

Re: Remove Character

Using a negative finds the first blank from the right side of the variable. From your example, I think that you want to find the first blank from the left side. So, don't use -1, use 1, if that is truly the case.
Super Contributor
Super Contributor
Posts: 3,174

Re: Remove Character

Good point, advoss - in that case, consider using the SCAN function.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 4 replies
  • 235 views
  • 0 likes
  • 3 in conversation