如何在 sas proc sql 中查询多个 where 条件
how to query multi where conditions in sas proc sql
我想使用 sas sql.
显示 'where conditions' 的 proc 查询结果
什么是 patient_name 的 disease_code 的 'I48' 从 2010 年到 2021 年第一次服用“243tab”和“246tab”之类的药物?
-nm_cd="243tab" 和 "246tab"
-disease_code=I48
-年=2010 年到 2021 年之间
-count = 1(第一次服药)
使用这个示例条件,我已经进行了如下查询。
'''query code'''
option compress=yes;
libname p "/user/temp/data_source";
proc sql;
create table m_join as
select index_num, R_key, patient_name from p.m1 as t1 join p.m2 as t2
on t1.index_num=t2.index_num join p.m3 as t3 join p.m4 as t4
on t3.index_num=t4.index_num
where stubstr(t4.nm_cd) in ("243tab" and "246tab")
and count = "1"
and t1.year=between "2010" and "2021"
and disease_code = "I48"
group by index_num;
quit;
但是这段代码存在一些问题。
我不知道如何解决这个问题。
请告诉我如何解决这个问题。
- 解释表格内容'以便更容易给出完整的 SQL 查询。
- 格式化查询以便于阅读。
- 如果您需要查找患者,请按患者分组。
- 吃药情况不明。我假设我们需要找到一个最终服用了 243tab 和 246tab 之类药物的人,但他们第一次服用是在 2010 年到 2021 年之间。
- 对文字使用单引号。
- 写下所有的加入条件。
- 比较年份时不要使用字符串,因为年份是数字(我希望你将它们存储为数字)。
- In 子句需要使用逗号来列出值,而不是 'ands'。
- 每次都使用别名。同样,代码将更易于阅读。
proc sql;
create table m_join as
select patient_name
from p.m1 as t1
join p.m2 as t2
on t1.index_num = t2.index_num
join p.m3 as t3
on ???
join p.m4 as t4
on t3.index_num=t4.index_num
where disease_code = 'I48'
and t4.nm_cd in ('243tab', '246tab')
group by patient_name
having min(t4.year) between 2010 and 2021
;
quit;
我想使用 sas sql.
显示 'where conditions' 的 proc 查询结果 什么是 patient_name 的 disease_code 的 'I48' 从 2010 年到 2021 年第一次服用“243tab”和“246tab”之类的药物? -nm_cd="243tab" 和 "246tab"-disease_code=I48
-年=2010 年到 2021 年之间
-count = 1(第一次服药)
使用这个示例条件,我已经进行了如下查询。
'''query code'''
option compress=yes;
libname p "/user/temp/data_source";
proc sql;
create table m_join as
select index_num, R_key, patient_name from p.m1 as t1 join p.m2 as t2
on t1.index_num=t2.index_num join p.m3 as t3 join p.m4 as t4
on t3.index_num=t4.index_num
where stubstr(t4.nm_cd) in ("243tab" and "246tab")
and count = "1"
and t1.year=between "2010" and "2021"
and disease_code = "I48"
group by index_num;
quit;
但是这段代码存在一些问题。
我不知道如何解决这个问题。
请告诉我如何解决这个问题。
- 解释表格内容'以便更容易给出完整的 SQL 查询。
- 格式化查询以便于阅读。
- 如果您需要查找患者,请按患者分组。
- 吃药情况不明。我假设我们需要找到一个最终服用了 243tab 和 246tab 之类药物的人,但他们第一次服用是在 2010 年到 2021 年之间。
- 对文字使用单引号。
- 写下所有的加入条件。
- 比较年份时不要使用字符串,因为年份是数字(我希望你将它们存储为数字)。
- In 子句需要使用逗号来列出值,而不是 'ands'。
- 每次都使用别名。同样,代码将更易于阅读。
proc sql;
create table m_join as
select patient_name
from p.m1 as t1
join p.m2 as t2
on t1.index_num = t2.index_num
join p.m3 as t3
on ???
join p.m4 as t4
on t3.index_num=t4.index_num
where disease_code = 'I48'
and t4.nm_cd in ('243tab', '246tab')
group by patient_name
having min(t4.year) between 2010 and 2021
;
quit;