2015-04-02 67 views
0

我被授予此代碼運行,但我仍然收到錯誤,即使我已經確定有正確數量的左/右括號。這是原始代碼,因爲我添加的括號似乎在錯誤的地方。與proc中的嵌套select語句問題sql

proc sql; 
    create table all as 
    select distinct a.id, a.count, b.date 
    from (select distinct id, count (*) as count from (select distinct id, p_id, date2 from table1) group by id) a 
(select distinct id, min(date2) as date format datetime. from table1) b 
where a.id=b.id; 
quit; 



(select distinct id, min(date2) as date format datetime. from 
        --------    - 
        22     22 
        202     76 
3520! table1) group by id) b 
ERROR 22-322: Syntax error, expecting one of the following:), ','. 

ERROR 202-322: The option or parameter is not recognized and will be ignored. 

ERROR 76-322: Syntax error, statement will be ignored. 

編輯:添加一個逗號後,然後我得到這個錯誤:

256  , (select id, min(date2) as date format datetime. from 
256! table1) group by id) b 
            - 
            22 
            76 
ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &, (, *, **, +, ',', -, 
       '.', /, <, <=, <>, =, >, >=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, EXCEPT, GE, GET, 
       GT, GTT, HAVING, IN, INTERSECT, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, 
       OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, ~=. 

ERROR 76-322: Syntax error, statement will be ignored. 

257 Where a.id=b.id; 
258 quit; 
+0

我thnk @sushil是正確的,是有缺失的逗號,但我也認爲你需要在你的格式聲明等號「FORMAT =日期時間。」 – 2015-04-02 16:51:15

回答

1

的錯誤是沒有括號的,但逗號(,)。您在第五行開頭錯過了逗號。

, (select distinct id, min(date2) as date format datetime. from table1) b 

編輯:縮進原代碼與我的逗號修復。我不知道你爲什麼會得到這個新的錯誤。我複製了你的原始代碼,並添加了逗號,並用虛擬數據測試了你的代碼,並且它工作正常。我猜想一些隱藏的垃圾字符會導致錯誤。

data table1; 
input id p_id date2 :yymmdd10.; 
datalines; 
1 1 2012-01-15 
1 1 2012-01-15 
2 1 2012-01-15 
2 2 2012-01-15 
4 1 2012-01-15 
;;;; 
run; 
proc sql; 
    create table all as 
    select distinct a.id, a.count, b.date 
     from (select distinct id, count (*) as count 
       from (select distinct id, p_id, date2 from table1) 
      group by id 
      ) a 
    , (select distinct id, min(date2) as date format datetime. 
     from table1 
    ) b 
where a.id=b.id; 
quit; 
+0

我計算了2個左括號和3個右括號,不應該總是相等嗎?我不確定,但因爲我添加了逗號,它仍然給我錯誤。 – PinkyL 2015-04-02 17:44:39

+0

@PinkyL請檢查編輯的答案。我縮進了你的原始代碼,並添加了逗號修復,並測試了你的代碼和虛擬數據,它工作的很好。 – sushil 2015-04-02 18:04:08

+0

我看到現在是什麼問題,在我的原始編號中有一個額外的組,可能導致所有問題。我拿出來並將其格式化爲您的示例,它正在工作......非常感謝。 – PinkyL 2015-04-02 18:12:32