日期间隔 - 求和

intervals of dates - summing

我有一个 table 日期:

Table1
Date_start  Date_end
01JUL1997   01JUL1998
01JUL1998   01APR1999
01APR1999   01OCT2000
01OCT2000   01JUL2001

和第二个 table 其中日期和数字:

Table2
Date_of_pay           Cash 
01DEC1999:00:00:00  7.00
01DEC1999:00:00:00  7.00
01JAN2000:00:00:00  7.00
01JAN2000:00:00:00  7.00
01JAN2000:00:00:00  7.00
01JAN2000:00:00:00  7.00

我想在表 2 中为表 1 中的每个间隔计算现金总和。 我不知道如何在数据步骤中使用 proc sql 来做到这一点。

感谢您的帮助。

请尝试以下查询:

SELECT
    table1.date_start, table1.date_end,
    SUM(table2.cash) as cash
FROM 
    table1 INNER JOIN table2
    ON  table2.date_of_pay >= table1.date_start
    AND table2.date_of_pay <= table1.date_end
GROUP BY
    table1.date_start, table1.date_end