BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rsadiq
Calcite | Level 5

Hello

I am not sure what is causing this error

 

ERROR: Summary functions are restricted to the SELECT and HAVING clauses only.

 

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;

 

Thanks

 

Rida

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Try:

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

               group by a.ayb_id, a.VisitCnt

               having sum_visits >= 2

               order by a.ayb_id;

               quit;

View solution in original post

4 REPLIES 4
collinelliot
Barite | Level 11

I removed the table alias since you're only using on table in the query. The subsetting you want to do is via a "having" statement that comes after your group by. 

 

Proc sql;
               Create table visit_count as
               select distinct ayb_id,
                         VisitCnt as Visits,
                        sum(VisitCnt) as sum_visits
               from aybdata.portal_reg
               group by ayb_id, VisitCnt
               having sum(VisitCnt) > 1;
               quit;
novinosrin
Tourmaline | Level 20

Try:

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

               group by a.ayb_id, a.VisitCnt

               having sum_visits >= 2

               order by a.ayb_id;

               quit;

Rsadiq
Calcite | Level 5

Thank you I got it solved!

novinosrin
Tourmaline | Level 20

You are welcome! have a nice day

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 2429 views
  • 0 likes
  • 3 in conversation