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 ~.

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!

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
  • 76983 views
  • 1 like
  • 2 in conversation