The Difference Between INDEX() and INDEXC() in SAS
Today, I was teaching the Intermediate SAS course that I developed over the last 9 months and an interesting question came up. What is the difference between the INDEX() and INDEXC() functions. Well it turns out to be pretty useful.
In SAS, the INDEX() function will scan a string and return the location of a substring. So for example INDEX(“Alabama”,”bam”) would return 4, since “bam” starts at the 4th letter of the word “Alabama.”
INDEXC(“Alabama”,”bam”) returns 3… Huh?
The INDEXC() function takes the list of characters in the string after the comma and searches for the first instance of any of them, thus when it encounters the lower case “a,” at the third character, it returns that index. (If these were all uppercase, it would return a 1).
This is useful if you need to find any instances of special characters. For example, searching a variable field called “phone_number” for parentheses or dashes could be done with INDEXC(phone_number,”()-“).
-
heatheryi982 liked this
-
30daysatatime posted this