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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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