What Is The Difference Between SAS Character Functions INDEX And INDEXC

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;




How To Read Different Formats Of Dates In SAS (Reading Mixture Dates From Raw Data In SAS)

Today we are going to discuss about, how to read dates in SAS, which are in multiple format in raw data.

Suppose we have dates in raw data which contains multiple types of separators and formats.

We would read such type of mixed date data and make all dates in one required format. We have two master blaster functions to perform this task :INDEXC and WORDDATE

SAS Code would be as follows:

Data DSN;

Input @1 Dummy_Dates $15.;

If INDEXC (Dummy_Dates,'-/:') NE 0

Then Date=Input(Dummy_Dates,MMDDYY10.);

Else Date=Input(Dummy_Dates,Date9.);

Format Date WORDDATE.;

Drop Dummy_Dates;

Cards;

10/07/2014

10MAY1984

8-12-1999

1:09:60

;
Run;








For more on INDEXC : What Is The Difference Between SAS Character Functions INDEX And INDEXC