BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hi,

 

I have a field that have two names in it, separated by two-spaces. how do I get only the second person from this field?

 

examples:

 

---1st person--------  -----2nd person------

LUKASZ STASIAK  ANNA KAROWIEC

            ^1 space    ^2

 

-----------1st person---------  ------------2nd person---------

ADAM KAPEC KOWALKI  JURAND ZE SPYCHOWA

         ^1           ^1              ^2             ^1  ^1

 

 

 

this:

sender   = scan(tpp_name, 1, " ");

receiver = scan(tpp_name, 2, " ");

 

treats the "  " as <space separator><space separator> not <double space separator>. Is there any workaround for that?

 

Thanks

Lukasz

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Work around would likely involve the INDEX function which returns the start position of one string within another or zero if not found.

 

pos = index(tpp_name ,'  ');

sender = substr(tpp_name ,1,pos-1);

receiver =  substr(tpp_name ,pos+2);

 

should work but you should set the lengths of the sender and receiver varaibles before use.

View solution in original post

4 REPLIES 4
ballardw
Super User

Work around would likely involve the INDEX function which returns the start position of one string within another or zero if not found.

 

pos = index(tpp_name ,'  ');

sender = substr(tpp_name ,1,pos-1);

receiver =  substr(tpp_name ,pos+2);

 

should work but you should set the lengths of the sender and receiver varaibles before use.

Ksharp
Super User

Check modification 'M':

 

scan(tpp_name, 2, " ",'m');

LukaszStasiak
SAS Employee

doesn't work as intended - it returns the second word from the string 

Cynthia_sas
SAS Super FREQ

Hi:

  Both FIND and INDEX worked for me.

cynthia

use_substr_with_index.png

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2460 views
  • 1 like
  • 4 in conversation