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
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;
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;
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;
Thank you I got it solved!
You are welcome! have a nice day
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.