楼主: dxystata
1840 12

[问答] 如何保留visit=1 x=1 和visit>1 x=2和3的id [推广有奖]

11
whymath 发表于 2019-5-28 21:55:52
dxystata 发表于 2019-5-28 21:47
换数据集了?
这个结果就不是6条了哦。
仅看条件(VISIT=1 and X = 1)就有1 2 4 三个ID,这里面就有不止6条结果呢。

12
dxystata 发表于 2019-5-28 22:08:57
这样理解吧,先挑选出visit=1 x=1 和visit>1 x=2和3的id,然后输出这个id的所有观测。

13
luekemia 发表于 2019-7-8 17:48:56
应该是要这种效果吧:

data aaa;
input id visit x;
cards;
1 1 1
1 2 1
1 3 3
1 4 4
2 1 1
2 2 3
3 1 2
;run;

proc sql noprint;
select distinct id into :id separated by ','
from aaa
where (visit=1 and x=1)
or (visit>1 and (x in (2,3) ) )
;quit;

proc sql;
create table outds as
select * from aaa
where id in (&id.)
;quit;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 08:17