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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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