I have a Teradata query that has a group by and then uses grouping sets to sum up the groups in a total line:
SELECT mygroup, count(x), sum(y)
FROM mytable
ORDER BY GROUPING (mygroup),mygroup
GROUP BY mygroup GROUPING SETS ((mygroup),())
I am now writing the same query in SAS EG as I want to create a scheduled report to be sent by email.
SAS EG does not have grouping sets as far as I can google.
My question is how I can create this "summary line" in SAS PROC SQL
, or possibly by some other SAS EG magic?
Edit: Here is an example of the output I am looking for:
It is the total line I lack in SAS EG so far
Update:
I have now written a Proc Tabulate
and I am near my goal. The only field I cannot seem to get correct is the total percentage difference. In the table I have made a total line where I sum Number1
and 2, but for the percentage total I want a calculation of (Number1-Number2)/Number1 instead of a sum or other aggregate. Is this possible with tabulate, and how do I do it?
My current code:
PROC TABULATE
DATA=WORK.TEMP;
VAR Number1 Number2 percentageCalc ;
CLASS group / ORDER=UNFORMATTED MISSING;
CLASS date / ORDER=UNFORMATTED MISSING;
TABLE
/* ROW Statement */
group*date
all = 'Total' ,
/* COLUMN Statement */
(Number1 * Sum={LABEL="Sum"} Number2 * Sum={LABEL="Sum"} percentageCalc * Sum={LABEL="%"} ) ;
;
RUN;
Is there any way to do a manual calculation in my last total cell or can I somehow manually create the whole total line?