Hi,
I have a data set as follows:
DATA Medication_org;
INPUT patient_ID $ time censor;
CARDS;
1 7 1
2 11 1
3 3 0
4 10 0
RUN;
I want to transform the data set into following:
patient_ID time censor
1 3 0
1 7 1
2 3 0
2 7 0
2 10 0
2 11 1
3 3 0
4 3 0
4 7 0
4 10 0
Note: time is not a continuous variable here.
Thank you
k*******a 发帖数: 772
2
试试这个行不行,不很清楚如果原始数据两个ID的time一样的情况,你需要什么样的结果,不过可以修
改一下,如果不同的话
proc sql;
create table new as
select a.patient_ID, b.time, a.censor*(a.patient_id=b.patient_id) as
censor
from medication_org a, medication_org b
where a.time>=b.time
order by patient_id, time
;
quit;
proc print data=new;run;
data new;
set old;
time2=0;
array t {4} (3 7 10 11);
do i=1 to 4;
if t[i]
time2=t[i];
censor=0;
output;
end;
else if t[i]=time then do;
time2=time;
censor=1;
output;
end;
end;
keep patient_id time2 censor;
run;