Published on :
Reporting SASHELP

Annual Profit Report by Product Line

This code is also available in: Deutsch Español Français
The script begins by setting system options and closing default ODS outputs. It then configures ODS output to HTML to a specified file. The PROC REPORT procedure is used to aggregate data from the `sashelp.orsales` dataset. The 'year' and 'product_line' variables are defined as grouping variables, and 'profit' is summed. Breaks are defined after each year and at the end of the report to display totals. Conditional styles are applied to rows and columns to improve report readability.
Data Analysis

Type : SASHELP


The report is built from the `orsales` dataset in the SASHELP library. This dataset is a standard example provided by SAS, requiring no specific external data or internal data creation within the script.

1 Code Block
PROC REPORT / ODS
Explanation :
This block first configures the report titles and ODS options to generate a stylized HTML output. The `PROC REPORT` procedure is then invoked on the `sashelp.orsales` dataset. It defines columns, grouping variables (`year`, `product_line`), and an analysis variable (`profit`) which is summed and formatted. The `break` and `rbreak` statements add summary rows for intermediate totals by year and a grand total. The `compute` blocks apply color styles (cyan, pink, green, red) to headers and summary rows via the `call define` function, enhancing the report's visual presentation.
Copied!
1options center;
2ods listing close;
3 
4ods html style=default
5 path="&pathesults"
6 body='E8_2.html';
7 
8title1 'Total profit per year';
9title2 'Separated by Product Line';
10title3 'Profit Summaries';
11PROC REPORT DATA=sashelp.orsales nowd split='*';
12 * Call define does not offer control of the header spaces
13 * style(header)={background=white}
14 * style(column)={background=pink};
15 column year product_line profit;
16 define year / group;
17 define product_line
18 / group
19 'Product*Groups';
20 define profit / analysis
21 sum FORMAT=dollar15.2
22 'Annual*Profit';
23 break after year / summarize suppress skip;
24 rbreak after / summarize;
25 
26 compute year;
27 call define(_col_,'style','style={background=cyan}');
28 endcomp;
29 
30 compute product_line;
31 call define(_col_,'style','style={background=pink}');
32 endcomp;
33 
34 compute after year;
35 call define(_row_,'style','style={background=green}');
36 endcomp;
37 
38 compute after;
39 call define(_row_,'style','style={background=red}');
40 endcomp;
41 RUN;
42ods _all_ close;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.