Published on :
Reporting SASHELP

Profit Report by Product Line and Year

This code is also available in: Deutsch Español Français
Awaiting validation
The program begins by defining a user format `$sequip` via `PROC FORMAT` to clarify product line labels. Then, `PROC REPORT` is used to analyze the `sashelp.orsales` table. The report groups the data by year and product line, calculates the total profit (`sum`) and the percentage of profit for each line relative to the annual total (`computed`). A detailed summary is included after each year. The resulting table is saved in `yrdat`. Finally, `PROC PRINT` is used to display an overview of this `yrdat` output table.
Data Analysis

Type : SASHELP


The main input data comes from the standard SASHELP.ORSALES table. The `yrdat` table is created internally by `PROC REPORT`.

1 Code Block
PROC FORMAT
Explanation :
This block defines a user-defined format named `$sequip`. It is used to map the value 'Sports' to 'Sports Equipment', which improves the readability of the 'product_line' variable in the generated report.
Copied!
1PROC FORMAT;
2 value $sequip
3 'Sports' = 'Sports Equipment';
4 RUN;
2 Code Block
PROC REPORT Data
Explanation :
This block uses `PROC REPORT` to generate a report from `sashelp.orsales`, grouped by year and product line. It calculates the total profit (`profit`) and the percentage of profit for each line relative to the annual total (`percent`). The `yrdat` table is created as output. The `compute` statements are used to calculate the annual total profits and the percentage. The line `line @code_sas_json/test_sha256.json 'Profits in US dollars';` is a `LINE` statement that would print the character string as is in the report output; its usage to reference a JSON file is an unusual syntax in a standard SAS context, but is included as is in the analyzed code.
Copied!
1title1 'Total profit per year';
2title2 'Separated by Product Line';
3PROC REPORT DATA=sashelp.orsales
4 out= yrdat nowd split='*';
5 column year product_line profit percent;
6 define year / group;
7 define product_line
8 / group
9 f=$sequip.
10 'Product*Groups';
11 define profit / analysis
12 sum FORMAT=dollar15.2
13 'Annual*Profit';
14 define percent/ computed 'Product*Percentage'
15 FORMAT=percent10.2;
16 
17 break after year/ summarize suppress skip;
18 
19 compute before year;
20 total = profit.sum;
21 endcomp;
22 compute percent;
23 percent = profit.sum/total;
24 endcomp;
25 compute after;
26 line ' ';
27 line @code_sas_json/test_sha256.json 'Profits in US dollars';
28 endcomp;
29 RUN;
3 Code Block
PROC PRINT
Explanation :
This block uses `PROC PRINT` to display the first observations of the `yrdat` table, which was generated by the previous `PROC REPORT`. This allows for a quick overview of the structure and content of the final report data.
Copied!
1title3 'Glimpse of the Output
2Data Table';
3PROC PRINT
4DATA=yrdat;
5 
6RUN;
7 
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.
Copyright Info : * E5_3.sas * * Chapter 5 Exercise 3 * * Total profit and percentage for each Product line within year; * With annual summary and a glimpse of the Output data table;