SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1710|回复: 5
打印 上一主题 下一主题

问一道BASE里的42题

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2012-1-27 01:56:02 | 只看该作者

问一道BASE里的42题

The following SAS program is submitted:

data WORK.ONE;
     Text='Australia, US, Denmark';
     Pos=find(Text,'US','i',5);
run;

What value will SAS assign to Pos?

     A. 0
     B. 1
     C. 2
     D. 12
我看了CRACKMAN BLOG 的解析 我还是不明白为什么是12  求大侠们告诉我这个菜鸟 从第5的位置算 怎么得的的12 谢谢了
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2012-1-27 12:52:45 | 只看该作者

Re: 问一道BASE里的42题

是从第5个位置开始找。U是在第12个位置。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2012-2-6 20:41:56 | 只看该作者

Re: 问一道BASE里的42题

5表示从第五个位置向右查找,第五个左边的us就不查找了,不是以第五个为0,还是从最左边开始数,‘,’逗号是两个字符,australia9个字符,US不就是在12吗
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2012-3-14 10:26:05 | 只看该作者

Re: 问一道BASE里的42题

[quote="layyine":wxrjobb1]5表示从第五个位置向右查找,第五个左边的us就不查找了,不是以第五个为0,还是从最左边开始数,‘,’逗号是两个字符,australia9个字符,US不就是在12吗[/quote:wxrjobb1]
麻烦这位高手解释一下find(a,b,c,d)这个函数,其中'i'代表什么,多谢!
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
5#
 楼主| 发表于 2012-3-15 07:27:58 | 只看该作者

Re: 问一道BASE里的42题

i代表ignore, 也就是不管字母大小写。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
6#
 楼主| 发表于 2012-3-25 14:27:24 | 只看该作者

Re: 问一道BASE里的42题

FIND Function

--------------------------------------------------------------------------------

Searches for a specific substring of characters within a character string. Category: Character  

--------------------------------------------------------------------------------
Syntax
Arguments
Details
Comparisons
Examples
See Also

--------------------------------------------------------------------------------

Syntax
FIND(string,substring<,modifiers><,startpos>)  
FIND(string,substring<,startpos><,modifiers>)  




Arguments

string
specifies a character constant, variable, or expression that will be searched for substrings.

Tip: Enclose a literal string of characters in quotation marks.

substring
is a character constant, variable, or expression that specifies the substring of characters to search for in string.

Tip: Enclose a literal string of characters in quotation marks.

modifiers
is a character constant, variable, or expression that specifies one or more modifiers. The following modifiers can be in uppercase or lowercase:

i ignores character case during the search. If this modifier is not specified, FIND only searches for character substrings with the same case as the characters in substring.

t trims trailing blanks from string and substring.

Note:   If you want to remove trailing blanks from only one character argument instead of both (or all) character arguments, use the TRIM function instead of the FIND function with the T modifier.  

Tip: If modifier is a constant, enclose it in quotation marks. Specify multiple constants in a single set of quotation marks. Modifier can also be expressed as a variable or an expression.

startpos
is a numeric constant, variable, or expression with an integer value that specifies the position at which the search should start and the direction of the search.


--------------------------------------------------------------------------------

Details


The FIND function searches string for the first occurrence of the specified substring, and returns the position of that substring. If the substring is not found in string, FIND returns a value of 0.

If startpos is not specified, FIND starts the search at the beginning of the string and searches the string from left to right. If startpos is specified, the absolute value of startpos determines the position at which to start the search. The sign of startpos determines the direction of the search.

Value of startpos
Action
greater than 0 starts the search at position startpos and the direction of the search is to the right. If startpos is greater than the length of string, FIND returns a value of 0.
less than 0 starts the search at position -startpos and the direction of the search is to the left. If -startpos is greater than the length of string, the search starts at the end of string.
equal to 0 returns a value of 0.



--------------------------------------------------------------------------------

Comparisons



The FIND function searches for substrings of characters in a character string, whereas the FINDC function searches for individual characters in a character string.

The FIND function and the INDEX function both search for substrings of characters in a character string; however, the INDEX function does not have the modifiers nor the startpos arguments.


--------------------------------------------------------------------------------

Examples


SAS Statements Results  
whereisshe=find('She sells seashells? Yes, she does.','she ');
put whereisshe;
27

variable1='She sells seashells? Yes, she does.';
variable2='she ';
variable3='i';
whereisshe_i=find(variable1,variable2,variable3);
put whereisshe_i;



1

expression1='She sells seashells? '||'Yes, she does.';
expression2=kscan('he or she',3)||'  ';
expression3=trim('t   ');
whereisshe_t=find(expression1,expression2,expression3);
put whereisshe_t;



14

xyz='She sells seashells? Yes, she does.';
startposvar=22;
whereisshe_22=find(xyz,'she',startposvar);
put whereisshe_22;


27

xyz='She sells seashells? Yes, she does.';
startposexp=1-23;
whereisShe_ineg22=find(xyz,'She','i',startposexp);
put whereisShe_ineg22;


14
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-6-4 19:22 , Processed in 0.089192 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表