R*****d 发帖数: 420 | 1 做76题,run了程序,但就是得不出答案的200。题目如下:
data work.test;
author='Agatha Christie';
first=substr(scan(author,1,','),1,1);
run;
题目上问first的长度,我run了一下,给出的是1,但答案是200,本来这个题目确实有
些问题,author里的分隔符是space,但scan里的分隔符是逗号,如果像75题那样
author里的分隔符和scan里的分隔符一样,那么scan先取得agatha,substr再取得a,
那么length就是1.现在author里的分隔符和scan里的分隔符不一样,按理确实要run出
别的结果,但我run了,却还是1,那答案的200又是怎么得来的?哪位大拿指教一下。 | a*****9 发帖数: 1315 | 2 这个我之前考过, 然后我上advanced SAS 课的时候, 老师特意提到这一点了 :
scan substr 这些function 针对的 $variable (如果没有特别的length function ,
而且 length还必须得在data step 之后 )
default length 是200 。 | d******9 发帖数: 404 | 3 If you run the below codes:
data work.test;
author='Agatha Christie';
first=substr(scan(author,1,','),1,1);
L=length(first);
LC=lengthC(first);
run;
You will find: L=1, LC=200.
Therefore, first is a char variable with a length of $200, its real
internalvalue is: A+ 199 ##########.
# stands for blank spaces. | d******9 发帖数: 404 | 4 However, if you run the below modified codes, what will you get?
data work.test;
author='Agatha Christie';
first=substr(scan(author,1,','),1,1);
L=length(substr(scan(author,1,','),1,1));
LC=lengthC(substr(scan(author,1,','),1,1));
run;
You will get: L=1, LC=1.
Surprising? Enjoy thinking over the tricky SAS. | P****D 发帖数: 11146 | 5 母牛啊!还让不让人活了!
【在 d******9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : However, if you run the below modified codes, what will you get? : data work.test; : author='Agatha Christie'; : first=substr(scan(author,1,','),1,1); : L=length(substr(scan(author,1,','),1,1)); : LC=lengthC(substr(scan(author,1,','),1,1)); : run; : You will get: L=1, LC=1. : Surprising? Enjoy thinking over the tricky SAS.
| d******9 发帖数: 404 | 6 pat pat..... no pain, no gain.
Work hard and keep on growing. |
|