Desktop productivity for business analysts and programmers

syntax errors

Reply
Occasional Contributor
Posts: 19

syntax errors

Hello I am working on a code and keep getting this error, not sure what is causing it

 

 

Proc sql;
 Create table visit_count as
 select distinct
 a.ayb_id,
 a.VisitCnt as Visits,
 from aybdata.portal_reg as a
 and sum(VisitCnt) as sum_visits
 where calculated sum_visits >= 2
 group by a.ayb_id, a.VisitCnt
 order by a.ayb_id;
 quit;

 

 

 


388       + from aybdata.portal_reg as a and
                 _______                 ___
                 22                      76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
              CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=. 

Grand Advisor
Posts: 10,251

Re: syntax errors

Please post the entire portion of the log with the code and error messages as sometimes the cause is actually some where earlier in the code. Also post them into a code box using the forum {i} icon as the postion dependent indicators get moved when pasted into a main message window.

 

You have at least one SUM function in a place not allowed. SUM is only acceptable in SELECT or HAVING clauses

Esteemed Advisor
Posts: 6,706

Re: syntax errors

Did you want this?

proc sql;
create table visit_count as
select distinct
  a.ayb_id,
  a.VisitCnt as Visits,
  sum(VisitCnt) as sum_visits
from aybdata.portal_reg as a
where calculated sum_visits >= 2
group by a.ayb_id, a.VisitCnt
order by a.ayb_id;
quit;
 
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Posts: 5,202

Re: syntax errors

Also you shouldn't have a comma after the last entry in the select statement. Classic mistake (which I frequently do myself).
Data never sleeps
Ask a Question
Discussion stats
  • 3 replies
  • 148 views
  • 3 likes
  • 4 in conversation