我得到了这段代码,但即使我确定左/右括号的数量合适,我仍然会遇到错误。这是原始代码,因为我添加的括号似乎位于错误的位置。
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 :(得分:1)
错误不是括号,而是逗号(,)。您在第5行开始时错过了逗号。
, (select distinct id, min(date2) as date format datetime. from table1) b
编辑:使用逗号修复功能缩进原始代码。我不知道你为什么会收到这个新错误。我复制了你的原始代码w /逗号,并用虚拟数据测试你的代码,它工作正常。我猜一些隐藏的垃圾字符导致错误。
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;