SAS中的条件连接

时间:2016-02-11 19:52:14

标签: sql join sas conditional

我有两张桌子a和b。 我想在以下两个条件下加入这两个:

  1. a.time1< b.time1和b.time1< a.time2
    然后在ID
  2. 上加入a和b
  3. b.time1< a.time1和a.time1< b.time2
    然后在ID
  4. 上加入a和b

    一个。

    ID  Name    Time1                   Time2
    1   Joe 01JAN2015:07:02:28  01JAN2015:07:49:13
    2   Jenny   01JAN2015:10:06:09  01JAN2015:10:07:11
    3   Angie   01JAN2015:07:02:12  01JAN2015:08:00:35
    

    ID  Name    Time1                   Time2
    2   David   01JAN2015:08:19:27  01JAN2015:09:15:29
    3   Mike    01JAN2015:10:58:22  01JAN2015:10:59:21
    4   Emily   01JAN2015:08:31:18  01JAN2015:08:53:19
    

    任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

这应该这样做:

proc sql;
    create table joined_data as
    select * from 
    a
    INNER JOIN
    b
    on a.x=b.x
    where (a.time1 < b.time1 and b.time1 < a.time2 ) 
       or (b.time1 < a.time1 and a.time1 < b.time2 );
quit;