S*****0 发帖数: 15 | 1 Overlapped data need to be combined to one.
For example:
X Y
----------
1 5
2 6
3 6
7 9
8 10
11 12
Should be converted to:
X Y
----------
1 6
7 10
11 12
[1 5],[2 6] and [3 6] should be combined to [1 6].
[7 9] and [8 10] should be combined to [7 10].
Thanks a lot! |
S*****0 发帖数: 15 | 2 My solution is:
data t1;
input x y;
cards;
1 5
2 6
3 6
7 9
8 10
11 12
13 15
14 17
;
run;
data t2(rename=(m=x n=y));
set t1 end=eof;
retain x1 y1 m n;
if _N_=1 then
do;
x1=x;
y1=y;
end;
else
do;
if y1
do;
m=x1; n=y1;
output;
x1=x; y1=y;
end;
else
do;
y1=max(y,y1);
end;
end;
if eof then
do;
m=x1;
n=y1;
output;
end;
keep m n;
run;
My method is ugly. Maybe you have better idea.
【在 S*****0 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Overlapped data need to be combined to one. : For example: : X Y : ---------- : 1 5 : 2 6 : 3 6 : 7 9 : 8 10 : 11 12
|
l****u 发帖数: 529 | 3 proc sort data=t1; by x; run;
data t2;
set t1 end=b;
z=lag(y);
if x>z or b;
proc sort; by decending x;
run;
data t3;
set t2;
if x
y=max(y,lag(z));
if y^=z;
run; |
S*****0 发帖数: 15 | 4 Nice. Thanks!
【在 l****u 的大作中提到】![](/moin_static193/solenoid/img/up.png) : proc sort data=t1; by x; run; : data t2; : set t1 end=b; : z=lag(y); : if x>z or b; : proc sort; by decending x; : run; : data t3; : set t2; : if x
|