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:
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:
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|
|name||If dest=’SEA’ then
|Analysis or display
sharing a column
with a statistic
|Any type sharing a
column with an
I hope this helps any confusion.
Miss SAS Answers