Help using Base SAS procedures

proc report add total of amount in the header

Reply
Frequent Contributor
Posts: 117

proc report add total of amount in the header

hello,

 

this is a small


data have ;
input produit $ generation periode  measure $ value FLAG_REAL_PREV $ ;
datalines ;
A 2008 201710 nborder 810 R
A 2008 201710 sales 801000 R
A 2008 201709 nborder 809 R
A 2008 201709 sales 80900 R
A 2009 201710 nborder 910 R
A 2009 201710 sales 901000 R
A 2009 201709 nborder 909 R
A 2009 201709 sales 90900 R
A 2008 201710 nborder 8102 P
A 2008 201710 sales 8010002 P
A 2008 201709 nborder 8092 P
A 2008 201709 sales 809002 P
A 2009 201710 nborder 9102 P
A 2009 201710 sales 9010002 P
A 2009 201709 nborder 9092 P
A 2009 201709 sales 909002 P
;

proc report data= have ;
column produit generation measure periode , FLAG_REAL_PREV , value ;
define PRODUIT / group '' ;
	define generation / group order =  DATA ; 
	define measure / group '' style(column)={CELLWIDTH = 2.5in} style(header)={CELLWIDTH = 2.5in} format= $f_measure_label. ;
	define periode / across '' ;
	define FLAG_REAL_PREV / '' across  ;
		define value / '' ;
Run ;

dataset with dummy datas. And this is my proc report.

 

what I need is to add a total of the key figure "sales" and for columns "R" (real) and "P" (forecast).

thanks a lot in advance for your help

 

Nasser

Respected Advisor
Posts: 3,001

Re: proc report add total of amount in the header

Posted in reply to Nasser_alfea

I would run PROC SUMMARY which creates the totals and the amounts in each cell.

 

Then I would use PROC REPORT to create the table from the PROC SUMMARY output.

--
Paige Miller
Frequent Contributor
Posts: 117

Re: proc report add total of amount in the header

Posted in reply to PaigeMiller

Thanks Page,

 

I succeeded to create a new dataset that hold a column "valueTotal" (via proc summary)

but I don't know how to display it in the header of the report (via proc report)

thanks

Respected Advisor
Posts: 3,001

Re: proc report add total of amount in the header

[ Edited ]
Posted in reply to Nasser_alfea

I don't know what you mean by "in the header"

 

To me, that's just the first row of the table.

 

If you did PROC SUMMARY properly, it does the calculations, including the "header" sum, and then PROC REPORT just takes the output from PROC SUMMARY and formats into a nice readable table. 

 

Here's a simple example using SASHELP.CLASS

 

proc summary data=sashelp.class;
    class sex age;
	var height;
	output out=sums sum=sum_height;
run;

data sums;
	set sums;
	if missing(sex) then sex="A";
	if missing(age) then age=-999;
run;

proc format;
	value $sexf "A"="All";
	value agef -999="All";
run;

proc report data=sums;
	column sex age,sum_height;
	define sex/group order=internal format=$sexf.;
	define age/across order=internal format=agef.;
	define sum_height/analysis sum;
run;
--
Paige Miller
Frequent Contributor
Posts: 117

Re: proc report add total of amount in the header

Posted in reply to PaigeMiller

Ok Paige

My need was not clearly specified. please take a look at my screen shot

I would like to obtain the detail (yellow )  and the total (in red)

thanks Paige

Frequent Contributor
Posts: 117

Re: proc report add total of amount in the header

Posted in reply to Nasser_alfea

Capture.PNG

Respected Advisor
Posts: 3,001

Re: proc report add total of amount in the header

Posted in reply to Nasser_alfea

My code produces a similar report using SASHELP.CLASS, you have to modify it for your exact needs.

--
Paige Miller
Frequent Contributor
Posts: 117

Re: proc report add total of amount in the header

Posted in reply to PaigeMiller

Hello Paige,

thanks !

 

I have many products A, B and C. is it possible to have a sub total by product ?

thanks

Ask a Question
Discussion stats
  • 7 replies
  • 324 views
  • 3 likes
  • 2 in conversation