sql能否实现吗?作者: Qiong 时间: 2009-4-16 16:52 标题: Re: 求助 b c d三个变量是否重复 给一个标识变量flag 用data比较好吧~~
觉着sql好像不会区别对待同样的observation~~
[code:tnevkbfh]
data have1;
set have;
no=_n_;
key=catx(',' ,of b--d);
run;
proc sort data=have1 ;
by key;
run;
data have1;
retain flag;
set have1;
by key;
if first.key=1 then flag=1;
else flag+1;
run;
proc sort data= have1 out=have(drop=no key);
by no;
run;
[/code:tnevkbfh]作者: shiyiming 时间: 2009-4-18 11:36 标题: Re: 求助 b c d三个变量是否重复 给一个标识变量flag data have;
input a b c d;
cards;
1 2 3 4
1 4 5 6
1 2 7 8
2 2 3 4
3 2 3 4
2 5 6 7
1 2 7 8
;
run;
data have_1;
set have;
n=_n_;
run;
proc sort; by a b c; run;
data have_2;
set have_1;
by a b c;
if first.a then flag=0;
flag+1;
run;
proc sort data=have_2; by n; run;*restore the previous order;
我没有软件。如果有问题可以自己调试一下。作者: shiyiming 时间: 2009-4-20 12:30 标题: Re: 求助 b c d三个变量是否重复 给一个标识变量flag to deshengsu
得到的数据集flag有误!作者: shiyiming 时间: 2009-4-20 20:55 标题: Re: 求助 b c d三个变量是否重复 给一个标识变量flag data have;
input a b c d;
cards;
1 2 3 4
1 4 5 6
1 2 7 8
2 2 3 4
3 2 3 4
2 5 6 7
1 2 7 8
;
run;
data have_1;
set have;
n=_n_;
run;
proc sort; by a b c; run;
data have_2;
set have_1;
by a b c;
if first.c then flag=0;*sorry, wrong syntax here;
flag+1;
run;
proc sort data=have_2; by n; run;*restore the previous order;作者: shiyiming 时间: 2009-4-20 21:03 标题: Re: 求助 b c d三个变量是否重复 给一个标识变量flag data have;
input a b c d;
cards;
1 2 3 4
1 4 5 6
1 2 7 8
2 2 3 4
3 2 3 4
2 5 6 7
1 2 7 8
;
run;
data have_1;
set have;
n=_n_;
run;
proc sort; by b c d; run;
data have_2;
set have_1;
by b c d;
if first.d then flag=0;
flag+1;
run;
proc sort data=have_2 out=have_1(drop=n); by n; run;*restore the previous order;
*note: I did not read your question very well.Anyway, that should work.
Sorry again.