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

tags: miss sas answers, PROC REPORT, programming

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>