[size=150:358nlcas]问题: 根据T1和T2得出T3的结果
说明:
1、T1中的1或者2不只3个有可能是40个1、38个2;
2、当T1值相等时,T2的值也会相等;
3、T1是按升充排列;
4、T3是的意思是当B在T2出现时他是对应T1出现的顺序,就像第一次的三个B1就是B刚出现时对应T1
在线求教,谢谢![/size:358nlcas]
T1 T2 T3
1 A
1 A
1 A
2 B B1
2 B B1
2 B B1
3 B B2
3 B B2
3 B B2
4 B B3
4 B B3
4 B B3
5 A
5 A
5 A
6 A
6 A
6 A
7 B B1
7 B B1
7 B B1
8 B B2
8 B B2
8 B B2
9 B B3
9 B B3
9 B B3
10 A
10 A
10 A
data b;
input T1 T2 $;
cards;
1 A
1 A
1 A
2 B
2 B
2 B
3 B
3 B
3 B
4 B
4 B
4 B
5 A
5 A
5 A
6 A
6 A
6 A
7 B
7 B
7 B
8 B
8 B
8 B
9 B
9 B
9 B
10 A
10 A
10 A
;
run;
proc sql;
create table c as select * from b where (T2='B');
quit;
data d(drop=first i);
set c;
retain T3;
if first then do;
i=1;
T3='B'||put(i,1.);
end;
if T1^=lag(T1) and (T1-lag(T1)=1) then do;
i+1;T3='B'||put(i,1.); end;
if T1^=lag(T1) and (T1-lag(T1)^=1) then do;
i=1;T3='B'||put(i,1.);end;
run;
proc sort data=b;
by T1;
run;
proc sort data=d;
by T1;
run;
data final;
merge b d;
by T1;
run;
data step may be the first choice to attack this kind of question. Jingju
[code:3vredb8b]data bb; drop n;
set b; by t1 t2 notsorted; length t3 $5;
if t2 ^='B' then n =0;
else if first. t2 then n ++1;
if n =0 then call missing(t3);
else t3 =cats(t2, n);
run;[/code:3vredb8b]