Sas 隔离有2种诊断但诊断数据在不同线路上的患者
我有一个病人数据集,每个诊断都在不同的线上 这是它的一个示例:Sas 隔离有2种诊断但诊断数据在不同线路上的患者,sas,bioinformatics,Sas,Bioinformatics,我有一个病人数据集,每个诊断都在不同的线上 这是它的一个示例: patientID diabetes cancer age gender 1 1 0 65 M 1 0 1 65 M 2 1 1 23 M 2 0 0 23 M 3 0
patientID diabetes cancer age gender
1 1 0 65 M
1 0 1 65 M
2 1 1 23 M
2 0 0 23 M
3 0 0 50 F
3 0 0 50 F
我需要隔离诊断为糖尿病和癌症的患者;他们唯一的患者标识符是patientID。有时他们在同一条线上,有时他们不在。我不知道怎么做,因为信息在多行上
我该怎么做呢
这就是我到目前为止所做的:
PROC SQL;
create table want as
select patientID
, max(diabetes) as diabetes
, max(cancer) as cancer
, min(DOB) as DOB
from diab_dx
group by patientID;
quit;
data final; set want;
if diabetes GE 1 AND cancer GE 1 THEN both = 1;
else both =0;
run;
proc freq data=final;
tables both;
run;
这是否正确?如果您想了解数据步骤查找的工作原理
data pat;
input patientID diabetes cancer age gender:$1.;
cards;
1 1 0 65 M
1 0 1 65 M
2 1 1 23 M
2 0 0 23 M
3 0 0 50 F
3 0 0 50 F
;;;;
run;
data both;
do until(last.patientid);
set pat; by patientid;
_diabetes = max(diabetes,_diabetes);
_cancer = max(cancer,_cancer);
end;
both = _diabetes and _cancer;
run;
proc print;
run;
在sql查询的末尾添加having语句
PROC SQL;
create table want as
select patientID
, max(diabetes) as diabetes
, max(cancer) as cancer
, min(age) as DOB
from PAT
group by patientID
having calculated diabetes ge 1 and calculated cancer ge 1;
quit;
您可能会发现一些编码人员,特别是那些来自统计背景的编码人员,更可能使用
Proc MEANS
而不是SQL或DATA step来计算诊断标志最大值
proc means noprint data=have;
by patientID;
output out=want
max(diabetes) = diabetes
max(cancer) = cancer
min(age) = age
;
run;
或者对于所有相同聚合函数的情况
proc means noprint data=have;
by patientID;
var diabetes cancer;
output out=want max= ;
run;
或
取PATIENTID的指标变量的最大值。问题中的代码似乎产生了您想要的结果,因此它已经是正确的。你是否在问,是否有其他更主要的方法来获得相同的正确结果?
proc means noprint data=have;
by patientID;
var diabetes cancer age;
output out=want max= / autoname;
run;