SAS里INDEX, INDEXC和SCAN的区别

来源:互联网 发布:网站seo分析工具 编辑:程序博客网 时间:2024/05/14 20:24

SCAN只能用于CHAR类型的搜索。而INDEX, INDEXC不受此局限。

INDEX (S,S1)表示在S1中搜索S。

INDEXC(S,S1-1)同样是在S1中搜索S。另,INDEXC可以搜索一些在文字里的奇怪的符号,例如“-”。


help文档:
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,”()-“).
0 0