2017-03-06 104 views
0

我使用SAS Enterprise Guide中,想比较两个日期变量:比较在SAS两个日期变量在PROC SQL WHERE子句

我的代码如下:

proc sql; 
    CREATE TABLE observations_last_month AS 
    SELECT del_flag_1, 
      gross_exposure_fx, 
      reporting_date format=date7., 
      max(reporting_date) AS max_date format=date7. 
    FROM &dataIn. 
    WHERE reporting_date = max_date; 
quit; 

如果我跑我的没有WHERE声明,我得到了以下数据代码:

enter image description here

然而,当我运行上面的代码我得到的以下错误消息:

ERROR: Expression using (=) has components that are of different data types. 
ERROR: The following tables were not found in the contributing tables: max_date. 

我在做什么错在这里?前面的帮助

回答

3

如果你想子集基于聚合函数谢谢,那么你需要使用具有替代的位置。如果你想引用您在查询已经导出的变量,那么你需要使用计算的关键字(或者只是重新计算的话)。

proc sql; 
    CREATE TABLE observations_last_month AS 
    SELECT del_flag_1 
     , gross_exposure_fx 
     , reporting_date format=date7. 
     , max(reporting_date) AS max_date format=date7. 
    FROM &dataIn. 
    HAVING reporting_date = CALCULATED max_date 
    ; 
quit; 
+0

非常感谢!这工作像一个魅力。 – MRR