Since Proc REPORT builds a report lione by line, we can no longer distingiush the values for the different drivetrains.
To get around this, you also need the horsepower and cylinders in your across defintion, so you can do the calculation.
For across columns, we can not use the varibale name, but have to use the absolute column number, including the ones that have the NOPRINT option set. See code below:
proc report data=newCars;
column type horsepower Cylinders driveTrain, (horsePower=hp2 cylinders=cyl2 compVar) _dummy;
define type / group;
define driveTrain / across;
define horsepower / analysis ;
define Cylinders / analysis;
define compVar / computed f=commax15.;
define hp2 / analysis noprint;
define cyl2 / analysis noprint;
define _dummy / computed noprint;
compute _dummy;
_c6_ = _c4_ * _c5_;
_c9_ = _c7_ * _c8_;
_c12_ = _c10_ * _c11_;
endcomp;
run;
Depending on your data, this might not be the most flexible and maintenance friendly way of doing it.
Maybe it is better to precalculate all the data, and use Proc REPORT for the display/layout part, see example below:
proc sql;
create table carsAggr as
select
type
, driveTrain
, sum(horsePower) as sumhp
, sum(cylinders) as sumcyl
, calculated sumhp * calculated sumcyl as mult_hp_cyl
from
sashelp.cars
group by
type
, driveTrain
;
quit;
proc report data=carsAggr;
column type sumhp sumcyl mult_hp_cyl, driveTrain;
define type / group;
define driveTrain / across;
define sumhp / analysis f=commax15.;
define sumcyl / analysis f=commax15.;
define mult_hp_cyl / analysis f=commax15.;
run;
... View more