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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1134 views
  • 0 likes
  • 3 in conversation