Bill of Material Explosion (bome09)

/**************************************************************/
/*                                                            */
/*             S A S   S A M P L E   L I B R A R Y            */
/*                                                            */
/*    NAME: BOME09                                            */
/*   TITLE: Bill of Material Explosion (bome09)               */
/* PRODUCT: OR                                                */
/*  SYSTEM: ALL                                               */
/*    KEYS: OR                                                */
/*   PROCS: BOM, PRINT, SORT, SQL                             */
/*    DATA:                                                   */
/*                                                            */
/* SUPPORT:                             UPDATE:               */
/*     REF:                                                   */
/*    MISC: Example 9 from the BOM Procedure chapter of the   */
/*          BOM book.                                         */
/*                                                            */
/**************************************************************/


/**************************************************************

                     Use SlBOM2 from BOME02

**************************************************************/

/* Product Structure and Part Master data from BOME02 */

data SlBOM2;
input Parent    $8.
      Component $8.
      Desc      $24.
      Unit      $8.
      LeadTime  4.0
      QtyPer    4.0
      Gros_Req  4.0
      On_Hand   4.0
      ;
datalines;
        LA01    Lamp LA                 Each       2   .  50  20
LA01    B100    Base assembly           Each       1   1   .  50
LA01    S100    Black shade             Each       2   1   .   .
LA01    A100    Socket assembly         Each       1   1   .   .
B100    1100    Finished shaft          Each       2   1   .   .
B100    1200    6-Diameter steel plate  Each       3   1   .   .
B100    1300    Hub                     Each       2   1   .   .
B100    1400    1/4-20 Screw            Each       1   4   .   .
A100    1500    Steel holder            Each       2   1   .   .
A100    1600    One-way socket          Each       2   1   .   .
A100    1700    Wiring assembly         Each       1   1   .   .
1100    2100    3/8 Steel tubing        Inches     3  26   .   .
1500    1400    1/4-20 Screw            Each       1   2   .   .
1700    2200    16-Gauge lamp cord      Feet       2  12   .   .
1700    2300    Standard plug terminal  Each       1   1   .   .
;

/**************************************************************

                        Begin example

**************************************************************/

/* Product structure and part master data */
data SlBOM9;
set SlBOM2(drop=LeadTime);

/* Specify scrap factors for 2100 and 2200 */
if (Component="2100" and Parent="1100") then Scrap=0.2;
else if (Component="2200" and Parent="1700") then Scrap=0.1;
run;

  /* Create the indented BOM and the summarized parts list */
proc bom data=SlBOM9 out=IndBOM9 summaryout=SumBOM9;
   structure / part=Component
               parent=Parent
               component=Component
               quantity=QtyPer
               id=(Desc Unit)
               requirement=Gros_Req
               qtyonhand=On_Hand
               factor=Scrap;
run;

/* Display the indented BOM data */

proc print data=IndBOM9 noobs;
var _Level_ _Parent_ _Part_ Desc QtyPer Qty_Prod
    Unit Scrap;
title 'ABC Lamp Company';
title3 'Indented Bill of Material, Part LA01';
run;

/* Sort and display the summarized parts list */

proc sort data=SumBOM9;
by _Part_;
run;

proc print data=SumBOM9 noobs;
title 'ABC Lamp Company';
title3 'Summarized Parts List, Part LA01: Requirement=50';
run;

/* Explode the gross requirement to low-level components */
data IndBOM9a;
set IndBOM9;
array reqs[4] req1 req2 req3 req4;
retain req1 req2 req3 req4 0;
drop req1 req2 req3 req4;

/* Calculate the gross requirement */
if _Level_=0 then Req=50;
else Req=reqs[_Level_]*QtyPer*(1.0+Scrap);

/* keep the requirement of the current level */
reqs[_Level_+1]=Req;

output;
run;

  /* Calculate the total requirement for each item */
proc sql;
   create table SumReq9 as
      select _Part_, Desc, Unit,
             sum(Req) as Gros_Req
      from IndBOM9a
      group by  _Part_, Desc, Unit;
quit;

/* Display the total requirements */

proc sort data=SumReq9;
by _Part_;
run;

proc print data=SumReq9 noobs;
title 'ABC Lamp Company';
title3 'Gross Requirements Report, Part LA01: Requirement=50';
run;

  /* Calculate the total usage for each item */
proc sql;
   create table SumUse9 as
      select _Part_, Desc, Unit,
             sum(Qty_Prod * 50) as Qty_Use
      from IndBOM9
      group by  _Part_, Desc, Unit;
quit;

/* Display the total requirements */

proc sort data=SumUse9;
by _Part_;
run;

proc print data=SumUse9 noobs;
title 'ABC Lamp Company';
title3 'Summarized Bill of Material, Part LA01: Requirment=50';
run;