BookmarkSubscribeRSS Feed
sfs
Calcite | Level 5 sfs
Calcite | Level 5
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
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
sfs
Calcite | Level 5 sfs
Calcite | Level 5
Thanks a million.
advoss
Quartz | Level 8
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Good point, advoss - in that case, consider using the SCAN function.

Scott Barry
SBBWorks, Inc.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1589 views
  • 0 likes
  • 3 in conversation