s******r 发帖数: 1524 | 1 data new;set old;by id time;
retain sort1 sort2 sort3;
if first.id then do;
sort1=max(sort1,0)+1;
sort2=1;
sort3=1;
end;
else do;
sort3=sort3+1;
if lag(time) ne time then sort2=sort2+1;
end;
run;
式: |
|
w********n 发帖数: 33 | 2 ID重复的次数是不等的,time也没有规律,现已经proc sort by ID,time成以下格式:
ID time
B 04/16
B 04/23
B 04/23
G 05/02
G 05/11
G 06/01
G 06/01
H 09/01
H 10/31
H 11/23
... ...
现在要加三列虚拟的排序变量 sort1 sort2 sort3:
ID time sort1 sort2 sort3
B 04/16 1 1 1
B 04/23 1 2 2
B 04/23 1 2 3
G 05/02 2 1 1
G 05/11 2 2 2
G 06/01 2 3 3
G 06/01 2 3 4
H 09/01 3 1 1
H ... 阅读全帖 |
|
h********o 发帖数: 103 | 3 data new;
set old;
by ID time;
if first.ID then do;
sort1 + 1;
sort2 = 1;
sort3 = 1;
end;
else do;
sort3 + 1;
if lag(time) ^= time then sort2 + 1;
end;
run; |
|
|