I am working on a proc sql code; it is giving me the error below:
1. ERROR: Summary functions nested in this way are not supported.
proc sql; create table A.TAT as select Month, MailerTurnAroundTime, Sum(count(distinct(Patient_id)))as Counts from (select case when mailerdays < 4 then "Less than 4 days" when mailerdays >= 4 and mailerdays <= 7 then "4 to 7 days" when mailerdays > 7 then "Greater than 7 days" end as MailerTurnAroundTime , * from A.Mailertat) group by Month, MailerTurnAroundTime; quit;
I am sure the error is something simple that I haven't caught yet. Can anyone please help?
Hi @anucharbe,
The "nested summary functions" are Sum(...) and count(...). Within each combination of Month and MailerTurnAroundTime values you want to count the distinct Patient_id values, which is fine. But then how does the SUM function come into play? I suspect that you mean the sum of the counts across Month-MailerTurnAroundTime combinations, not within these groups, i.e., the GROUP BY clause should not apply to the SUM function. This would require another (nested) inline view, for example:
select Month, MailerTurnAroundTime, sum(npat) as Counts
from (select Month, MailerTurnAroundTime, count(distinct Patient_id) as npat
from (select case when ...)
group by Month, MailerTurnAroundTime);
Show us the actual LOG for this PROC SQL stepped, unedited, with nothing chopped out. Preserve the formatting of the LOG by copying it as text and pasting it into the window that appears when you click on the </>. Please help us, this preserves the formatting, DO NOT SKIP THIS STEP.
Since you are selecting from a sub-query and not an actual dataset you need to give the sub-query and alias name, even if the sub-query is the only thing you are selecting from. So XXX in this snippet is the alias.
from (select ....) xxx
Hi @anucharbe,
The "nested summary functions" are Sum(...) and count(...). Within each combination of Month and MailerTurnAroundTime values you want to count the distinct Patient_id values, which is fine. But then how does the SUM function come into play? I suspect that you mean the sum of the counts across Month-MailerTurnAroundTime combinations, not within these groups, i.e., the GROUP BY clause should not apply to the SUM function. This would require another (nested) inline view, for example:
select Month, MailerTurnAroundTime, sum(npat) as Counts
from (select Month, MailerTurnAroundTime, count(distinct Patient_id) as npat
from (select case when ...)
group by Month, MailerTurnAroundTime);
Thank you, that worked with my code. 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.