BookmarkSubscribeRSS Feed
Rsadiq
Calcite | Level 5

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, ^=, |, ||, ~=. 

3 REPLIES 3
ballardw
Super User

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

Kurt_Bremser
Super User

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;
 
LinusH
Tourmaline | Level 20
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 819 views
  • 3 likes
  • 4 in conversation