BookmarkSubscribeRSS Feed
Nietzsche
Lapis Lazuli | Level 10

This is how the base explain prep guide explains INDEX and FIND.

I don't know about you but to me, the author seems to rewrite the same thing but in three separate sentences for INDEX and FIND respectively.

Nietzsche_1-1668510007091.png

 

Nietzsche_2-1668510047894.png

 

Both search specific string/substring from left to right, looking for first occurrence of the string/substring, if nothing is found return 0.

 

only difference I see is

INDEX  is for string while

FIND is for subtring.

But the book never explains what the difference is between a string and a substring in this context.

 

using the example in the book

data work.datapool;
set cert.temp;
index = index(job,'word processing');
find = find(job,'word processing');
run;
proc print data=work.datapool;run;

the result is the same

Nietzsche_4-1668510694536.png

so I am guessing in context "word processing" is both a string and a substring if I go by the prep guide explanation of the FIND and INDEX?

 

 

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
2 REPLIES 2
PaigeMiller
Diamond | Level 26

There is a lot of overlap between FIND and INDEX. In many cases, they produce the same answers.

 

FIND has additional options not in INDEX. For some reason, the documentation you show doesn't mention these additional options. Here is the full documentation for FIND.

--
Paige Miller
Quentin
Super User

I don't think there is a difference between "string" and "substring" in this context.  I can see how it may be confusing to see these two functions presented side by side, and you're trying to figure out what the difference is, and the only difference you see is in that wording.  I think the difference in wording likely comes from the documentation, and is a result of FIND being introduced in a much later version than INDEX.  

 

If you look in the documentation for a function, there is often a section at the bottom which explains how a function differs from similar functions.  For FIND, it says:

The FIND function and the INDEX function both search for substrings of characters in a character string. However, the INDEX function does not have the modifier nor the start-position arguments.
The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.

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
  • 2 replies
  • 3275 views
  • 1 like
  • 3 in conversation