我有这样的事情:
Id Visit_Date Visit_code
A30 15May2004 Surgery
A30 05FEB2005 Office
B01 07DEC2002 Office
B01 21NOV2002 Surgery
我需要这个,其中有一栏表明此人是否在就诊后 6 个月内接受过手术
ID Office_Visit SX_past_6mo
A30 1 0
B01 1 1
我正在尝试这样的事情,但子查询遇到问题
proc sql;
select case when
case when
visit_type="Office" then 1 else 0 end as office_visit,
case when
visit_type="Office" and
DATEDIFF(MM, visit_date, select(visit_date where visit_type="Surgery") > 6 then 1 else 0 end as sx_past_6mo
group by Id