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

Hi, I have a variable called "comment" that contains a string of words that are separated by '~'

 

example:

comment

text text text text ~ text text

text text text text text ~ text text text ~text text 

 

I would like to extract the text after the first ~ without losing the text behind the second or third or fourth ~ etc.

 

I tried using this code:

cm=scan(comment,1,"~");

 

But it only extracts the text after the first ~ and then stops once it reaches the second ~

 

Any help is much appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Use INDEX() to find the first tilda and then use that number in SUBSTR().
Double check the order of t

cm = substr(comment, index(comment, '~') +1);

View solution in original post

3 REPLIES 3
Reeza
Super User
Use INDEX() to find the first tilda and then use that number in SUBSTR().
Double check the order of t

cm = substr(comment, index(comment, '~') +1);
kmardinian
Quartz | Level 8

Hi Reeza,

 

Thank you for the quick response. Out of curiosity, what does the +1 signify?

 

 

Reeza
Super User
INDEX would find the ~, so if you substring from that it includes the ~, +1 gives you the position after the first ~.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 84102 views
  • 2 likes
  • 2 in conversation