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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 72426 views
  • 0 likes
  • 2 in conversation