Help using Base SAS procedures

Calculate a column from a summary table

Reply
N/A
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.
SAS Super FREQ
Posts: 8,742

Re: Calculate a column from a summary table

Hi:
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:
http://support.sas.com/documentation/onlinedoc/v82/techreport_p258.pdf
http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf
http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/report-overview.htm

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.
cynthia
[pre]
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;
endcomp;
run;
ods html close;
[/pre]
Ask a Question
Discussion stats
  • 1 reply
  • 111 views
  • 0 likes
  • 2 in conversation