SAS Functions [11-14]
The INDEXC function is similar to the INDEX function. However, it searches for the individual character instead of the whole text.
Let's take a look at the example below.
The NAME data set above contains a list of first names.
[Reminder: To see the NAME data set on SAS Studio, run the code in the yellow box above]
The first name should contain only letters. It should not contain any other symbols.
The INDEXC function can be used to find out whether any unwanted characters are found from the text.
Indc = Indexc(FirstName, "!@#$%^&*()<>?");
The INDEXC function will scan the variable for each of the characters listed in the second parameter (i.e. !@#$%^&*()<>?).
In this example, one of the name is captured as "Terry###".
This is obviously an error, as the name should not contain any "#" sign.
The INDEXC function scans the FirstName variable and find the "#" sign at the 6th position.
As a result, it returns the value of 6.
The INDEXC function is commonly used in the data cleansing process.
It allows you to check whether any incorrect characters are captured in any character variables.
Copy and run the MATHEXAM data set from the yellow box below.
Write a SAS program to extract the numeric exam result from the COMMENT variable.
Use the INDEXC function instead of the INDEX function when performing the extraction.
Create any data set or variables if necessary.
Need some help?