Help using Base SAS procedures

Calculate a column from a summary table

Not applicable
Posts: 0

Calculate a column from a summary table

How do i calculate new columns based on columns in a summary table. I.e I create a summary table which gives me exactly what i want and how i want to see the data. However i want to make a calculation based on two of the columns in the sumary table.

If i output the summary table as a data table the format of the data completly changes. The data table changes the summary table columns into rows.
Posts: 9,365

Re: Calculate a column from a summary table

Posted in reply to deleted_user
The question is: what is your procedure of choice? What are you currently using to create the summary table?

If you are using PROC FREQ or PROC TABULATE or PROC MEANS to create your summary table, then the answer is NO, you cannot make a calculation based on summary columns unless you create an output dataset and then use that dataset within a program that does the calculation.

However, PROC REPORT, using a COMPUTE block, can create calculated columns using existing report columns. As shown in the program below. For more information on PROC REPORT, you might consult these sites:

PROC REPORT can create cross-tabular reports too. The computations with ACROSS variables are do-able, but you need to use the "absolute" column names for the ACROSS vars, instead of the dataset name. That's because each report column that comes from an ACROSS usage gets a unique number of its own. The second document above shows an example of doing this.
ods html file='c:\temp\compute_examp.html' style=sasweb;
proc report data=sashelp.prdsale nowd;
column division prodtype n actual predict diff;
define division / group;
define prodtype / group;
define actual / sum;
define predict / sum;
define n / 'Count of Sales';
define diff / computed f=dollar8.;
rbreak after / summarize;
compute diff;
diff = actual.sum - predict.sum;
ods html close;
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation