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!
proc format;
value $sequip
'Sports' = 'Sports Equipment';
run;
1
PROC 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!
title1 'Total profit per year';
title2 'Separated by Product Line';
proc report data=sashelp.orsales
out= yrdat nowd split='*';
column year product_line profit percent;
define year / group;
define product_line
/ group
f=$sequip.
'Product*Groups';
define profit / analysis
sum format=dollar15.2
'Annual*Profit';
define percent/ computed 'Product*Percentage'
format=percent10.2;
break after year/ summarize suppress skip;
compute before year;
total = profit.sum;
endcomp;
compute percent;
percent = profit.sum/total;
endcomp;
compute after;
line ' ';
line @code_sas_json/test_sha256.json 'Profits in US dollars';
endcomp;
run;
1
title1 'Total profit per year';
2
title2 'Separated by Product Line';
3
PROC REPORTDATA=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!
title3 'Glimpse of the Output Data Table';
proc print data=yrdat;
run;
1
title3 'Glimpse of the Output
2
Data Table';
3
PROC PRINT
4
DATA=yrdat;
5
6
RUN;
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;
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.