data p1;
infile cards missover;
input ID $ Name $ Category $ Price AmountQ1 AmountQ2 AmountQ3 AmountQ4;
cards;
001 SSD Hardware 100 453 500 550 588
018 Cooling Hardware 399 918 1000 1020 1231
003 MAV Display 344 201 222 323 344
015 Boss Audio 213 989 1020 928 999
006 RTX1070 Hardware 399 472 560 832 991
014 Mouse1 Control 121 533 463 758 432
008 GTX1070 Hardware 178 371 333 212 121
009 GTX1060 Hardware 222 432 333 232 211
009 GTX1060 Hardware 222 432 333 232 211
005 RTX1060 Hardware 299 847 919 1029 2910
010 I79700k Hardware 232 141 212 323 432
005 RTX1060 Hardware 299 847 919 1029 2910
011 I79800k Hardware 245 131 121 323 432
013 Vaper Control 123 141 143 145 156
017 LED Display 144 119 100 98 87
002 IPS Display 200 193 199 201 234
012 I92000k Hardware 443 111 131 141 145
016 Logic Control 321 531 542 455 543
004 GTX1080 Hardware 399 876 763 543 312
007 RTX1080 Hardware 569 938 1039 1410 1235
019 Sony Audio 123 98 102 92 99
019 Sony Audio 123 98 102 92 99
;run;
%let aq=amountq1,amountq2,amountq3,amountq4;
I was trying to count the number of product that has a above or below average sales
My idea is to Create variable 'performance' to indicate whether the product is above or below average and use the summary function count to count their number.
Using the code below
proc sql;
select case when sum(&aq)*price ge mean(sum(&aq)*price) then 'above average'
else 'below average' end as performance,
count(calculated performance) as cont
from p1 group by calculated performance;
quit;
I get an error of : Summary functions are restricted to the SELECT and HAVING clauses only
when I change <mean(sum(&aq)*price)> to an actual number, or use subquery like below the problem is solved.
proc sql;
select case when sales ge avg then 'above average'
else 'below average' end as performance, count(calculated performance) as cont
from (select *,sum(&aq)*price as sales,mean(sum(&aq)*price) as avg from p1) group by calculated performance;
quit;
My question is: Why? I only used summary function in the select clause, why is SAS telling me this?