Max Kim
Max Kim

Reputation: 1124

Group by week in SAS

I was writing a proc tabulate report, which would summarize data in a table by day and by week.

So far this is what I have:

PROC TABULATE
DATA=WORK.FB_REPORT
   ;
   VAR ORDERS UNITS PRICE SERVICE_CHARGE FRUIT_BOUQUET_REV REVENUE;
   CLASS SALES_TYPE /   ORDER=UNFORMATTED MISSING;
   CLASS ORDER_DATE /   ORDER=UNFORMATTED MISSING;
   TABLE 
          /* By Row*/
          ORDER_DATE *(  Sum={LABEL="Sum"}   )  
          all = 'Total'  *(  Sum={LABEL="Sum"}   )  , /*  CHANGE THIS LINE */
          /* By Column */
          SALES_TYPE *(ORDERS  UNITS  PRICE  SERVICE_CHARGE  MERHCREV  REVENUE REVENUE)
          all = 'Total'  *(MERCHREV  REVENUE REVENUE) ;
   ;

RUN;

How can I change the all = 'Total'*(Sum={LABEL="Sum"}) statement such that, to sum by grouping weeks in ORDER_DATE?

Upvotes: 2

Views: 2454

Answers (1)

Joe
Joe

Reputation: 63424

You can use a format to accomplish this. There are several week-related formats, and if there isn't one you like you can roll your own using a Picture format. Here's an example using the always-popular WEEKU format:

proc tabulate data=sashelp.citiday;
class date;
var SNYDJCM SNYSECM;
format date WEEKU11.;
tables all date,(snydjcm snysecm)*sum;
run;

Date is a variable that contains dates, one row per day, for the entire period of the dataset. (Browse sashelp.citiday for more information.)

Upvotes: 1

Related Questions