Resources

Aggregating Forecasts Using PROC BOM (bome10)

/**************************************************************/
/*                                                            */
/*             S A S   S A M P L E   L I B R A R Y            */
/*                                                            */
/*    NAME: BOME10                                            */
/*   TITLE: Aggregating Forecasts Using PROC BOM (bome10)     */
/* PRODUCT: OR                                                */
/*  SYSTEM: ALL                                               */
/*    KEYS: OR                                                */
/*   PROCS: BOM, PRINT, SORT, SQL                             */
/*    DATA:                                                   */
/*                                                            */
/* SUPPORT:                             UPDATE:               */
/*     REF:                                                   */
/*    MISC: Example 10 from the BOM Procedure chapter of the  */
/*          BOM book.                                         */
/*                                                            */
/**************************************************************/

/* The input data set */
data demand10;
format parent $14. child $14. code $2. ;
input parent & child & code $ pct nitems;
datalines;
Dist.Center 1  Warehouse 1    DC   1    .
Dist.Center 1  Warehouse 2    DC   1    .
Dist.Center 2  Warehouse 3    DC   1    .
Dist.Center 2  Warehouse 4    DC   1    .
Dist.Center 2  Warehouse 5    DC   1    .
Warehouse 1    Store 01       WH   1    .
Warehouse 1    Store 02       WH   1    .
Warehouse 1    Store 03       WH   1    .
Warehouse 2    Store 04       WH   1    .
Warehouse 2    Store 05       WH   1    .
Warehouse 3    Store 06       WH   1    .
Warehouse 3    Store 07       WH   1    .
Warehouse 3    Store 08       WH   1    .
Warehouse 4    Store 09       WH   1    .
Warehouse 4    Store 10       WH   .5   .
Warehouse 5    Store 11       WH   1    .
Warehouse 5    Store 10       WH   .5   .
Store 01       .              ST   .   10
Store 02       .              ST   .   20
Store 03       .              ST   .   10
Store 04       .              ST   .   20
Store 05       .              ST   .   10
Store 06       .              ST   .   20
Store 07       .              ST   .   10
Store 08       .              ST   .   20
Store 09       .              ST   .   10
Store 10       .              ST   .   20
Store 11       .              ST   .   10
;

  /* Create the hierarchy structure */
proc bom data=demand10 out=indbom10;
   structure / part=parent
               parent=parent
               component=child
               quantity=pct
               id=(nitems code);
run;

  /* Sort the output data set in reverse order */
proc sort data=indbom10;
   by descending part_id;
run;

  /* Aggregate forecasts through the hierarchy structure */
data accumulate10;
   set indbom10;
   array items[3] dcitems whitems stitems;
   retain dcitems whitems stitems 0;

   do i=1 to _level_;
      if nitems then items[i]=items[i] + pct * nitems;
   end;

   if nitems then items[_level_+1]=items[_level_+1] + nitems;

   output;

   do i=_level_+1 to 3;
     items[i]=0;
   end;
run;

  /* Display the forecast for each store */
proc sort data=accumulate10(where=(code="ST"))
          out=stores10
          nodupkey;
   by _part_;
run;

proc print data=stores10 noobs;
   title1 'ABC Lamp Company';
   title3 'Totals for Stores';
   var _Part_ code stitems;
run;

  /* Display the aggregated forecast for each warehouse */
proc sort data=accumulate10(where=(code="WH"))
          out=houses10
          nodupkey;
   by _part_;
run;

proc print data=houses10 noobs;
   title1 'ABC Lamp Company';
   title3 'Totals for Warehouses';
   var _Part_ code whitems;
run;

  /* Display the aggregated forecast for each distribution center */
proc sort data=accumulate10(where=(code="DC"))
          out=dcs10
          nodupkey;
   by _part_;
run;

proc print data=dcs10 noobs;
   title1 'ABC Lamp Company';
   title3 'Totals for Distribution Centers';
   format _Part_ $14. ;
   var _Part_ code dcitems;
run;