The DATA Step

Use of the DATA step and PROC PRINT is the most common way to produce reports. For example, from the data set solution shown in Figure 4.6, a table that shows the revenue of the optimal production plan and a table of the cost of material can be produced with the following program:

data product(keep= _var_ _value_ _price_ revenue)
     material(keep=_var_ _value_ _price_ cost);
   set solution;
   if _price_>0 then do; 
      revenue=_price_*_value_; output product;
   end;
   else if _price_<0 then do;
      _price_=-_price_;
      cost = _price_*_value_; output material;
   end;                       
run;
/* display the product report */

proc print data=product;
   id _var_;
   var _value_ _price_ revenue ;
   sum revenue;
   title 'Revenue Generated from Tie Sales';
run;

/* display the materials report */

proc print data=material;
   id _var_;
   var _value_ _price_ cost;
   sum cost;
   title 'Cost of Raw Materials';
run;

This DATA step reads the solution data set saved by PROC LP and segregates the records based on whether they correspond to materials or products—namely whether the contribution to profit is positive or negative. Each of these is then displayed to produce Figure 4.9.

Figure 4.9: Tie Problem: Revenues and Costs

Revenue Generated from Tie Sales

_VAR_ _VALUE_ _PRICE_ revenue
all_polyester 11.8 3.55 41.890
all_silk 7.0 6.70 46.900
cotton_poly_blend 8.5 4.81 40.885
poly_cotton_blend 15.3 4.31 65.943
      195.618


Cost of Raw Materials

_VAR_ _VALUE_ _PRICE_ cost
cotton_material 13.6 0.90 12.24
polyester_material 22.0 0.60 13.20
silk_material 7.0 0.21 1.47
      26.91