BookmarkSubscribeRSS Feed
anjita
Fluorite | Level 6

When looking for data contained in a character string of 150 bytes, which function is the best to locate that data: scan, index, or indexc?

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thats a bit like saying, when looking for something to eat in the fruit basket what is better apple, orange or pear.

There is no context, provided samples or any information at all which would indicate one way or another which is better.

Each of the given functions have their uses as defined in the SAS documentation, refer to that in context which your actual problem.

andreas_lds
Jade | Level 19

Like @RW9  already said: your question can't be answered without knowing the context. The three functions you listed have very different use cases.

ballardw
Super User

@anjita wrote:

When looking for data contained in a character string of 150 bytes, which function is the best to locate that data: scan, index, or indexc?


And why exclude indexw, find, findw or the PRX functions? And sometimes even compress may work. It really depends on what the specific case is.

 

What type of data? Are "word" boundaries to be honored or not? Doe the desired data contain one or more word boundaries or delimiters? Do you need find more than the first occurrence of something? Do you need to use something other than a space as a word boundary?

 

Answering those questions and you may get hints towards which may be best for a specific use.

sandeep12
Fluorite | Level 6

Index function – Searches a character expression for a string of characters 

SAS StatementsResults
a=’ABC.DEF (X=Y)’;
b=’X=Y’;
x=index(a,b);
put x;
10

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
  • 4 replies
  • 1442 views
  • 0 likes
  • 5 in conversation