The SAS Output Delivery System and reporting techniques

Customised Group Headers

Reply
Frequent Contributor
Posts: 97

Customised Group Headers

proc report data=sashelp.shoes nowd;
title 'At Top of Page ~{thispage} of ~{lastpage}';
footnote 'At Bottom of Page';
where region in ('Asia', 'Canada', 'Pacific', 'Western Europe');
column region product sales inventory;
define region / group;
define product / group;
define sales/ noprint;
define inventory/ 'Inventory';
break after region /summarize skip;
rbreak after / summarize;
compute before _page_;
line "Before Report Table";
endcomp;
compute before region;
line "Before Region";
endcomp;
compute after region;
if region = 'Central America/Caribbean' then region = 'Cent Amer/Carib';
region = trim(region)|| ' SubTotal';
line "After Region";
endcomp;
compute after;
region = 'Grand Total';
line "After Report Table";
endcomp;
run;
ods _all_ close;


In the code shown above how do i get the output shown below

REGION = ASIA

PRODUCT SALES
Boot $170,165
Men's Casual $2,176
Men's Dress $272,634
Sandal $36,570
Slipper $485,082
Sport Shoe $16,057
---------------
Asia SubTotal $1,176,139
SAS Super FREQ
Posts: 8,743

Re: Customised Group Headers

Hi:
-- 1a) You could either do it with BY group processing in PROC REPORT with the BY group info (REGION=ASIA) in a SAS title.

-- 1b) OR you could just use "regular" BY group processing with the BY information NOT in the title

-- 2) Or, you could use COMPUTE BEFORE _PAGE_

-- 3) Or you could use COMPUTE BEFORE [breakvar-name]

Each technique has advantages and disadvantages and destinations where the technique will work better than other destinations.

Here is are code samples that shows each technique. For more help with PROC REPORT syntax, you should look at the PROC REPORT documentation, the papers listed at the end of this FAQ topic
http://support.sas.com/faq/030/FAQ03036.html
or consider contacting Tech Support for more help.

cynthia
[pre]
** 1a) by group and #byval;
ods listing;
options nobyline nodate nonumber;
ods html file='c:\temp\report1a.html' style=egdefault;
proc report data=sashelp.shoes nowd
style(summary)=Header;
by region;
title '1a) Region = #byval(region)';
where region in ('Asia', 'Canada', 'Pacific', 'Western Europe');
column region product sales;
define region / group noprint;
define product / group;
define sales/ 'Sales';

break after region /summarize skip ul ol;

compute after region;
if region = 'Central America/Caribbean' then region = 'C Amer/Carib';
else if region = 'Western Europe' then region = 'W Eur';
else if region = 'Eastern Europe' then region = 'E Eur';
product = trim(region)|| ' SubTot';
endcomp;

run;
ods _all_ close;
options byline;
title;

** 2a) Use regular BY line with BY group processing;
ods listing;
ods html file='c:\temp\report1b.html' style=egdefault;
proc report data=sashelp.shoes nowd
style(summary)=Header;
by region;
title 'The Report 1b';
where region in ('Asia', 'Canada', 'Pacific', 'Western Europe');
column region product sales;
define region / group noprint;
define product / group;
define sales/ 'Sales';

break after region /summarize skip ul ol;

compute after region;
if region = 'Central America/Caribbean' then region = 'C Amer/Carib';
else if region = 'Western Europe' then region = 'W Eur';
else if region = 'Eastern Europe' then region = 'E Eur';
product = trim(region)|| ' SubTot';
endcomp;

run;
ods _all_ close;

** 3) compute before _page_ WITHOUT BY;
ods listing;
ods html file='c:\temp\report2b.html' style=egdefault;
proc report data=sashelp.shoes nowd
style(summary)=Header;
title 'The Report 3';
where region in ('Asia', 'Canada', 'Pacific', 'Western Europe');
column region product sales;
define region / group noprint;
define product / group;
define sales/ 'Sales';

break before region / ;
break after region /summarize skip ul ol page;

compute before _page_ / style={just=l};
line 'Region = ' Region $char25. ;
endcomp;

compute after region;
if region = 'Central America/Caribbean' then region = 'C Amer/Carib';
else if region = 'Western Europe' then region = 'W Eur';
else if region = 'Eastern Europe' then region = 'E Eur';
product = trim(region)|| ' SubTot';
endcomp;

run;
ods _all_ close;

** 3) compute before region;
ods listing;
ods html file='c:\temp\report3.html' style=egdefault;
proc report data=sashelp.shoes nowd
style(summary)=Header;
title 'The Report 3';
where region in ('Asia', 'Canada', 'Pacific', 'Western Europe');
column region product sales;
define region / group noprint;
define product / group;
define sales/ 'Sales';

break before region / ;
break after region /summarize skip ul ol;

compute before region / style={just=l};
line 'Region = ' Region $char25. ;
endcomp;

compute after region;
if region = 'Central America/Caribbean' then region = 'C Amer/Carib';
else if region = 'Western Europe' then region = 'W Eur';
else if region = 'Eastern Europe' then region = 'E Eur';
product = trim(region)|| ' SubTot';
endcomp;

run;
ods _all_ close;
[/pre]
Frequent Contributor
Posts: 97

Re: Customised Group Headers

Brilliant, thanks a million
Ask a Question
Discussion stats
  • 2 replies
  • 134 views
  • 0 likes
  • 2 in conversation