温馨提示:本文翻译自stackoverflow.com,查看原文请点击:sql - In SAS, how can I select all the ID groups which has specific relationship between another variables
sas select sql syntax

sql - 在SAS中,如何选择所有在另一个变量之间具有特定关系的ID组

发布于 2020-04-14 17:20:15

例如,我想从数据集1获取数据集2。

从数据集1中,在数据集2中选择所有ID,这些ID的任何特定阶段的value1比ID中的上一个阶段的value2大10个点(指向箭头)。

数据集1

数据集2

我正在使用SAS EG版本,因此无法进行此类查询。

提前非常感谢您。

查看更多

提问者
Dream Sylph
被浏览
86
Gordon Linoff 2020-02-04 00:22

您可以在SQL中执行此操作。要获取与条件匹配的行:

select t.*
from t join
     t tnext
     on tnext.id = t.id and 
        tnext.phase = t.phase + 1
where tnext.value1 > t.value2 + 10;

然后,您可以使用in列出ID exists

select t.*
from t
where t.id in (select t2.id
               from t t2 join
                    t tnext
                    on tnext.id = t2.id and 
                       tnext.phase = t2.phase + 1
               where tnext.value1 > t2.value2 + 10
              );