野亡灵 发表于 2015-11-4 17:02
72题:首先,substr(First,1,7)的功能是对于First字符串,从第1个字符开始,截取7个字符。注意substr()函数 ...
这里我很疑惑,为什么substr()返回值长度要跟原字符first一样长?
文档里是这么定义的:
SYNTAX
The SUBSTR function has three arguments:
SUBSTR(SOURCE, POSITION, N)
The function
returns N characters, beginning at character number
POSITION from the string SOURCE.
♦ SOURCE—This is the larger or reference string. It can be a
variable or a string of characters.
♦ POSITION—This value is a positive integer and references the
starting point to begin reading the internal group of characters.
♦ N—This value is a positive integer and references the number
of characters to read from the starting point POSITION in the
field SOURCE.
所以,substr返回的长度应该就是N(如果N被指定的话)。具体到这个例子里,City的长度就该是7啊。
另一个例子可见于little sas book上83页3.3章表里给出的范例:
SUBSTR
a='(916)734-6281';
x=SUBSTR(a,2,3);
预测结果是:
x='916'
这里得到返回的x值也只有三位,而不是916后面一路把空格全补齐到原长打止啊。
求大佬解惑!