我对 SAS 还很陌生,正在尝试处理数据集。在数据集中,如果其中一个家庭被确诊患有呼吸道疾病,就会被招募。每个成员都有自己的参与者 ID 和家庭 ID,并且同一家庭内的人是否具有相同的家庭 ID。
我试图通过说来定义索引案例,如果他们在同一个家庭中,则查看哪个参与者具有相同的发病日期,然后创建一个新变量,将该人称为索引。
我正在想这样的事情,但需要帮助使其发挥作用。
data house;
set house;
if householdID==householdID and min(onsetdate) then index=1;
else if index = 0;
run;
谢谢!!
您可以尝试这样的操作:(另外,用同名数据集覆盖数据集通常并不是最好的主意)
proc sort data=house; by householdID onsetdate; run;
data want;
set house;
by householdID onsetdate;
retain refdate;
/* Take the first onset date as reference - assumes no missing values! */
if first.householdID then refdate = onsetdate;
index = onsetdate eq refdate;
run;