Hi:
Explaining more about your real intentions and data would have been useful from the beginning. However, it's water under the bridge now.
Rather than retooling an example at this point in time, I have some code that calculates cumulative sales using TAGATTR and you can alter the formula, as needed. The example uses a subset of SASHELP.PRDSALE, so it's not that different from what you posted. The key is that PROC REPORT is used instead of PROC PRINT.
With PROC REPORT, I can use a COMPUTE block to test which report row (based on the CNTROWS item) is currently being handled by PROC REPORT if it is the first report row, then the value is set to the same as ACTUAL.SUM -- you will probably have a starting balance or similar value to put here instead. Then, if CNTROWS is GT 1, the formula is attached to the cell in the CALL DEFINE statement for the second COMPUTED item (SHOW_CUM_SALES).
For my report, the value at the summary line is changed to missing (.) and then the SAS options turn missing to ' ' (instead of showing the bogus summary). You will probably put a different formula here in your TAGATTR. The test for '_RBREAK_' is what allowed me to reset the value of my cumulative column on the final summary line.
PROC REPORT is more flexible than PROC PRINT for allowing you to "hide" report items using NOPRINT -- which is how CNTROWS is treated. PROC REPORT also allows the use of "temporary" variables (whose values are automatically retained) to help you create other report items in COMPUTE block. (This is what HOLD and CUMSALES are.) _BREAK_ is an automatic variable that PROC REPORT uses to identify report rows that come from break processing, as opposed to report rows that come from the data.
The compound name, ACTUAL.SUM, is the referencing syntax that PROC REPORT requires inside a COMPUTE block, and ONLY inside a COMPUTE block. Note that in the COLUMN statement and in the DEFINE statement, the variable name of ACTUAL is used.
If you are new to PROC REPORT, you'll have to spend some time figuring out how PROC REPORT works and how it differs from PROC PRINT. The REPORT documentation and user group papers mentioned in previous postings will be very useful to you. For example, some paper links were posted here:
http://support.sas.com/forums/thread.jspa?messageID=17771䕫
http://support.sas.com/forums/thread.jspa?messageID=49404샼
cynthia
[pre]
** make some data similar to example data;
proc sort data=sashelp.prdsale out=prdsale;
by division prodtype product;
where country eq 'CANADA' and year eq 1993;
run;
title; footnote;
ods listing close;
options missing=' ';
ods tagsets.excelxp file='c:\temp\formula_cum_sales.xls' style=statistical
options(absolute_column_width='10');
proc report data=prdsale nowd split='*';
title 'Create SHOW_CUM_SALES report item entirely in PROC REPORT';
column cntrows division prodtype product actual show_cum_sales;
define cntrows / computed noprint;
define region / display;
define prodtype /display 'Product*Type';
define product / display;
define actual / sum 'Actual*Sales';
define show_cum_sales / computed f=dollar14.0 'Cum Sales';
compute cntrows;
hold + 1;
cntrows = hold;
endcomp;
compute show_cum_sales;
if _break_ ne '_RBREAK_' then do;
cumsales + actual.sum;
if cntrows = 1 then show_cum_sales=cumsales;
else if cntrows gt 1 then do;
show_cum_sales = 0;
call define(_col_,'style','style={tagattr="formula:R[-1]C+RC[-1]"}');
end;
end;
else if _break_ eq '_RBREAK_' then do;
show_cum_sales = .;
** put your formula in a call define here for the sum of the running balance;
** call define(_col_,'style','style={tagattr="formula:????"}');
end;
endcomp;
rbreak after / summarize style={font_weight=bold};
run;
ods tagsets.excelxp close;
[/pre]
corrected typo
Message was edited by: Cynthia@sas