Nupur,如果你需要爲每一個診斷的序列號,然後嘗試以下方法:
proc sort data=temp;
by id diagnosis;
run;
data temp_serial_number;
set temp;
by id diagnosis;
format diagnosis_serial_number $30.;
retain diagnosis_serial_number count;
if first.id then do;
count = 0;
diagnosis_serial_number = "(";
end;
count + 1;
diagnosis_serial_number = trim(left(diagnosis_serial_number)) || trim(left(count));
if last.id then do;
diagnosis_serial_number = trim(left(diagnosis_serial_number)) || ")";
output;
end;
else do;
diagnosis_serial_number = trim(left(diagnosis_serial_number)) || ",";
end;
drop diagnosis count;
run;
data temp;
merge temp(in=in_temp) temp_serial_number(in=in_serial_nbr);
by id;
if in_temp then output;
run;
proc print data=temp;
run;
輸出將如下所示:
Obs diagnosis id diagnosis_serial_number
1 XX 1 (1,2,3,4,5)
2 XX1 1 (1,2,3,4,5)
3 XX2 1 (1,2,3,4,5)
4 XX3 1 (1,2,3,4,5)
5 XX4 1 (1,2,3,4,5)
6 XX 2 (1,2,3)
7 XX1 2 (1,2,3)
8 XX2 2 (1,2,3)
您是否想知道如何將列添加到SAS數據集? –
是的,一列有診斷序列號。例如:一些像diag_serial_number這樣的列,它具有用於根據不同ID號進行診斷的序列號。 – Nupur