*Dear Miss SAS Answers,*

In PROC REPORT can I use one calculated (computed) variable in the calculation of another computed variable? In the example below, I’m trying to use the value of the Bonus column to calculate the Total column:

compute Bonus;

Bonus =sal.sum***0.05**;

endcomp;

compute Total;

total=sum(sal.sum, Bonus.sum);

endcomp;

Here are the messages I get in the SAS log:

**ERROR: The variable type of BONUS.SUM is invalid in this context.**

**NOTE: The preceding messages refer to the COMPUTE block for total.**

**NOTE: Will not run due to compilation errors.**

**NOTE: The SAS System stopped processing this step because of errors.**

What am I doing wrong?

Signed,

*Not Adding Up*

Dear Not Adding Up,

We have conditioned you well to use the * column.statistic *syntax! The problem is that when you use a computed column in a subsequent computed column in the same PROC REPORT step, you don’t need to specify the statistic, but rather just the column. So, your assignment statement for the Total compute block should read:

total=sum(sal.sum, **Bonus**);

PROC REPORT just uses whatever the calculated value for Bonus is on that row.

Here’s a great chart from page 4-71 of the current **SAS Report Writing 1:Using Procedures and ODS** class that summarizes when to use which form of reference for a column:

If the VariableBeing Used Is |
Then Refer to It by |
Compute Block Example |

Group, order, computed or display |
name | If dest=’SEA’ then City=’Seattle’; |

Analysis or display sharing a column with a statistic |
compound name variable.statistic |
Bonus=salary.sum*.035; |

Any type sharing a column with an Across variable |
Absolute column number |
_c1_ |

I hope this helps any confusion.

Happy reporting!

Miss SAS Answers