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

问题描述 投票:0回答:2

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

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

“

“

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

非常感谢。

sql select syntax sas
2个回答
0
投票

您可以在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;

然后您可以使用inexists列出ID:

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
              );

0
投票
  1. 计算每组的差异(DIF()
  2. 获取差异大于10的ID
  3. 过滤器主表

    data temp;
     set have;
     by id phase;
     /*Part 1*/
     difference = dif(value1);
     if first.id difference = .;
     /*Part 2*/
     if difference > 10 then output;
    run;
    
    /*Part 3*/
    proc sql;
    create table want as
    select * from have
    where ID in (select distinct ID from temp);
    quit;
    
© www.soinside.com 2019 - 2024. All rights reserved.