2017-03-06 5 views
0

내가 SAS 엔터프라이즈 가이드를 사용하여 두 개의 날짜 변수를 비교하고자하고 다음과 같이발동의 SQL에서 SAS에서 두 개의 날짜 변수를 비교 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

집계 함수를 기반으로 하위 집합을 만들려면 WHERE 대신 HAVING을 사용해야합니다. 쿼리에서 파생 된 변수를 참조하려면 CALCULATED 키워드를 사용하거나 다시 계산해야합니다.

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