y********0 发帖数: 638 | 1 有一组数据,如下. 以V1作为组,想把每组里V3>V3[ROW1=1]对应的records提取出来.用
SQL
能做到吗,记得见过类似的代码好像..
ROW1 V1 V2 V3
0 1 89 2011-07-05
0 1 91 2013-07-20
1 1 91 2013-07-25
0 2 81 2010-10-18
1 2 82 2011-03-22
1 3 89 2011-01-04
0 3 91 2012-06-27
0 3 91 2012-10-16
0 3 91 2012-10-20
0 4 84 2012-03-31
1 4 84 2012-04-17
1 5 73 2011-07-20
2 5 75 2012-12-27
0 5 75 2013-03-19
0 5 76 2013-10-09
3 5 76 2013-11-07
0 5 76 2013-12-18
0 5 75 2011-06-30
0 5 75 2011-07-05
最终的结果是:
ROW1 V1 V2 V3
1 1 91 2013-07-25
1 2 82 2011-03-22
1 3 89 2011-01-04
0 3 91 2012-06-27
0 3 91 2012-10-16
0 3 91 2012-10-20
1 4 84 2012-04-17
1 5 73 2011-07-20
2 5 75 2012-12-27
0 5 75 2013-03-19
0 5 76 2013-10-09
3 5 76 2013-11-07
0 5 76 2013-12-18
0 5 75 2011-06-30
0 5 75 2011-07-05
谢谢. | v***v 发帖数: 267 | 2 data a;
input
row1
v1
v2
@13 v3 yymmdd10.
;
format v3 yymmdd10.;
datalines;
0 1 89 2011-07-05
0 1 91 2013-07-20
1 1 91 2013-07-25
0 2 81 2010-10-18
1 2 82 2011-03-22
1 3 89 2011-01-04
0 3 91 2012-06-27
0 3 91 2012-10-16
0 3 91 2012-10-20
0 4 84 2012-03-31
1 4 84 2012-04-17
1 5 73 2011-07-20
2 5 75 2012-12-27
0 5 75 2013-03-19
0 5 76 2013-10-09
3 5 76 2013-11-07
0 5 76 2013-12-18
0 5 75 2011-06-30
0 5 75 2011-07-05
;
run;
proc sql;
select distinct a.* from
a, a b
where
a.v1=b.v1 and b.row1=1 and a.v3>=b.v3
order by v1
;
quit; | l****u 发帖数: 529 | 3 proc sql;
create table two as
select *
from one
group by v1
having v3>=max(ifn(row1=1,v3,.));
quit; | y********0 发帖数: 638 | 4 Thank you all very much for being so generous with your time and expertise! |
|