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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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