Calculated values in PROC REPORT Compute Blocks


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;

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

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?


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 Variable
Being Used Is
Then Refer to It by Compute Block Example
Group, order,
computed or
name If dest=’SEA’ then
Analysis or display
sharing a column
with a statistic
compound name
Any type sharing a
column with an
Across variable
Absolute column


I hope this helps any confusion.

Happy reporting!

Miss SAS Answers


About Author

Miss SAS Answers

Technical Training Specialist

Linda Jolley has been a SAS software user since 1980. She has been an instructor for SAS since 1997, and is Base and Advanced SAS Programming certified and working on the Data Integration Developer certification. She has presented papers at several SAS user group venues on various SAS programming efficiency techniques and the SAS Scalable Performance Data Server.

Related Posts

Comments are closed.

Back to Top