In my previous post related to, how to read mixture dates from raw data in sas, I have used INDEXC function so it’s a good time to define INDEX and INDEXC function in SAS with difference in both.
link to previous post :How To Read Different Formats Of Dates In SAS (Reading Mixture DatesFrom Raw Data In SAS )
INDEX Function : It looks for a character expression in a character string and returns the position of string’s first character for the first position. In short, it scans the string and provides the location of sub-string.
INDEXC Function : It looks for a expression for any of the given characters and returns the position of that expression. In Short, It scans the string and provides the location of sub-string based on list of expression in sub-string.
Explanation : Suppose we have a character string “UmAShankerSaini” and we are looking for ‘ain’.
Once we are running INDEX function, then it would search for complete string like ‘ain’ and it would return the position of it, which is 12.
Once we are running INDEXC function, then it would make a list of all letters in specified string and returns the position of any character for the first instance of any of them. So when it comes to lowercase ‘a’ at the sixth character, it returns the position value which is 6. In case of uppercase ‘A’, it would return 3.
Data DSN;
Name='UmAShankerSaini';
Exp='ain';
Indx=Index(Name,Exp);
IndxC=INDEXC(Name,Exp);
Put Indx= / Indxc = ;
Run;
link to previous post :How To Read Different Formats Of Dates In SAS (Reading Mixture DatesFrom Raw Data In SAS )
INDEX Function : It looks for a character expression in a character string and returns the position of string’s first character for the first position. In short, it scans the string and provides the location of sub-string.
INDEXC Function : It looks for a expression for any of the given characters and returns the position of that expression. In Short, It scans the string and provides the location of sub-string based on list of expression in sub-string.
Explanation : Suppose we have a character string “UmAShankerSaini” and we are looking for ‘ain’.
Once we are running INDEX function, then it would search for complete string like ‘ain’ and it would return the position of it, which is 12.
Once we are running INDEXC function, then it would make a list of all letters in specified string and returns the position of any character for the first instance of any of them. So when it comes to lowercase ‘a’ at the sixth character, it returns the position value which is 6. In case of uppercase ‘A’, it would return 3.
Data DSN;
Name='UmAShankerSaini';
Exp='ain';
Indx=Index(Name,Exp);
IndxC=INDEXC(Name,Exp);
Put Indx= / Indxc = ;
Run;