D******n 发帖数: 2836 | 1 A I L R
a 0 1 2
a 0 3 4
a 1 5 6
a 1 2 3
a 0 4 5
a 0 5 9
b .....
b .....
b ....
...
||
\/
A I L R
a 0 1 4
a 1 5 6
a 1 2 3
a 0 4 9
b .....
b .....
b ....
...
basically within each A group(such as a,b,c,...), there are 0s and 1s for
the I attribute, i want to merge the each consecutive 0 subgroup(for example
the first 2 obs) into one entry keeping the L from first obs and R from
last obs. |
s*r 发帖数: 2757 | |
D******n 发帖数: 2836 | 3 well, im in the middle of a SAS code, better do it in sas, but if the whole
thing is redone in perl, would be much easier.....
【在 s*r 的大作中提到】 : perl?
|
p********a 发帖数: 5352 | 4 data a;
input A I L R;
datalines;
a 0 1 2
a 0 3 4
a 1 5 6
a 1 2 3
a 0 4 5
a 0 5 9
run;
data b(drop=I1 L1 R1);
set a;
retain I1 L1 R1;
if _N_=1 then do; I1=I;L1=L;R1=R;end;
else do; if I=I1 then do;L=L1;output;end;
else do;I1=I;L1=L;R1=R;end;
end;
run; |
A*******s 发帖数: 3942 | 5 data a;
input A $ I L R;
cards;
a 0 1 2
a 0 3 4
a 1 5 6
a 1 2 3
a 0 4 5
a 0 5 9
;
run;
data b;
retain L1;
set a;
by i notsorted;
if i=0 and first.i=1 then do;
L1=L; delete;
end;
else if i=0 and last.i=1 then L=L1;
drop L1;
run; |
p********a 发帖数: 5352 | 6 by i notsorted ?
Fancy.. |
D******n 发帖数: 2836 | 7 great i was using the same stragtegy but didnt know the notsorted keyword
and wish there was such function and it turned out it does....tnnd sas.
【在 A*******s 的大作中提到】 : data a; : input A $ I L R; : cards; : a 0 1 2 : a 0 3 4 : a 1 5 6 : a 1 2 3 : a 0 4 5 : a 0 5 9 : ;
|
s*r 发帖数: 2757 | 8 居然有这个了,是哪个版本开始的?
【在 p********a 的大作中提到】 : by i notsorted ? : Fancy..
|
p********a 发帖数: 5352 | 9 不知道啊,现在新东西真多,俺们不学习的话等5年就成老古董了 |
A*******s 发帖数: 3942 | 10 以前版本没有么?我是考adv for sas 9学到的,看来是从9开始的。 |
D******n 发帖数: 2836 | 11 这就是sas的毛病,要实现一个新功能就发明一个新key word。
用R或者其他programming language现编就行了。
【在 p********a 的大作中提到】 : 不知道啊,现在新东西真多,俺们不学习的话等5年就成老古董了
|
l***a 发帖数: 12410 | 12 100101110100111
【在 D******n 的大作中提到】 : 这就是sas的毛病,要实现一个新功能就发明一个新key word。 : 用R或者其他programming language现编就行了。
|
P****D 发帖数: 11146 | 13 Co-tnnd SAS. This trick could have saved me a lot of time if I had known it
earlier...
【在 D******n 的大作中提到】 : great i was using the same stragtegy but didnt know the notsorted keyword : and wish there was such function and it turned out it does....tnnd sas.
|