SAS中文论坛

标题: 不明白 [打印本页]

作者: shiyiming    时间: 2012-3-25 15:36
标题: 不明白
data a;
infile datalines;
input x y $ z;
datalines;
1 a 27
1 a 33
1 b 45
2 a 52
2 b 69
3 b 70
4 a 82
4 c 91
;
run;
data b;
set a;
by x y;
if first.y;
run;
proc print data=b;
run;
data a;
infile datalines;
input x y $ z;
datalines;
1 a 27
1 a 33
1 b 45
2 a 52
2 b 69
3 b 70
4 a 82
4 c 91
;
run;
data b;
set a;
by x y;
if first.y;
run;
proc print data=b;
run;
b  70这个观测怎么也会有呢?
作者: shiyiming    时间: 2012-4-24 06:06
标题: Re: 不明白
俺是SAS新手,说错了免罚。
data are sorted by x y, when use first.y to output observations, all obs with y firstly appearing within sorted x group will be written to data b:

1 a 27
1 a 33
1 b 45
2 a 52
2 b 69
3 b 70 (it is first time for b to appear when x=3, this is why obs 3 b 70 is reported.)
4 a 82
4 c 91

hope this helps!
作者: shiyiming    时间: 2012-4-25 09:15
标题: Re: 不明白
您说的非常对,今天仔细一看知道了。
记得在考试的时候,我好像没看清楚前面X的的值已经改变。
其实这道题在复习的时候碰到过。真是郁闷呐。要是这道对了,我就有90%以上了,可出来的成绩不够90%。多少有点不好听,呵呵。
最后谢谢你的回答!




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2