c****y 发帖数: 584 | 1 I have a dataset looks like this
x y z
a A 1
a A 2
a C 3
b C 1
b B 2
b B 3
b A 4
b D 5
c A 1
c C 2
d D 1
d A 2
e A 1
e D 2
....
I want it to look like this
x y z
a A 2
a C 3
b A 4
b D 5
c A 1
c C 2
e A 1
e D 2
....
Basically for each value in column x, I want the last record of A in column
y and the following record of each value in column x. If there is no non_A
value followed, delete all records of that value in column x.
Dont know if I make myself clearly enough but any help will be appreciated. |
D******n 发帖数: 2836 | 2 data a1;
input x $ y $ z;
datalines;
a A 1
a A 2
a C 3
b C 1
b B 2
b B 3
b A 4
b D 5
c A 1
c C 2
d D 1
d A 2
e A 1
e D 2
;
run;
proc print;run;
data a2;
set a1;
by x;
if first.x then cum_A = 0;
cum_a + (y="A");
num = _n_;
run;
proc sql;
select * from a2
group by x
having cum_a>=max(cum_a) and sum(cum_a)>1
order by x,num;
quit;
【在 c****y 的大作中提到】 : I have a dataset looks like this : x y z : a A 1 : a A 2 : a C 3 : b C 1 : b B 2 : b B 3 : b A 4 : b D 5
|
c****y 发帖数: 584 | 3 Thanks very much for your code. but it didnt give me the result I want.
More help needed!!! |
c****y 发帖数: 584 | 4 Thanks very much for your code. but it didnt give me the result I want.
More help needed!!! |
c****y 发帖数: 584 | 5 Thanks very much for your code. but it didnt give me the result I want.
More help needed!!! |
t******g 发帖数: 27 | 6 I think you should use the template and spend sometime google some key words
(e.g., first., last., by group) to find specific solution you are looking
for.
No one knows exactly what you want and no one here is paid to debug the code
for you.
【在 c****y 的大作中提到】 : Thanks very much for your code. but it didnt give me the result I want. : More help needed!!!
|