我有一个患者数据的数据集,每个诊断都在不同的行上。
这是它的样子的一个例子:
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;
这是对的吗?
答案 0 :(得分:2)
如果您想了解数据步骤,请查看其工作原理。
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;
答案 1 :(得分:1)
在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;
答案 2 :(得分:1)
您可能会发现某些编码人员,特别是那些来自统计背景的人,更有可能使用Proc MEANS
代替SQL或DATA步骤来计算诊断标志最大值。
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;
或
proc means noprint data=have;
by patientID;
var diabetes cancer age;
output out=want max= / autoname;
run;