Published on :
Reporting SASHELP

Orion Sales Reports and Sorting

This code is also available in: Deutsch Español Français
The script uses the `PROC PRINT` procedure to display data listings from the `sashelp.Orsales` table. Various options are used, such as filtering with `WHERE`, summing numeric variables with `SUM`, and customizing headers. The `PROC SORT` procedure is also employed to reorder data according to different sorting criteria, ascending and descending. The script also shows how to add titles and footnotes to reports.
Data Analysis

Type : SASHELP


The data comes exclusively from the `sashelp.Orsales` table, which is a standard sample table provided with SAS.

1 Code Block
PROC PRINT
Explanation :
This block displays the variables `product_Group`, `Quantity`, and `Total_Retail_Price` from the `sashelp.Orsales` table. It also calculates and displays the total sum of `Total_Retail_Price`.
Copied!
1PROC PRINT DATA= sashelp.Orsales;
2 var product_Group Quantity Total_Retail_Price;
3 sum Total_Retail_Price;
4RUN;
2 Code Block
PROC PRINT
Explanation :
Displays the variables `product_Group`, `Quantity`, and `Profit` for observations where `Profit` is greater than 2000.
Copied!
1PROC PRINT DATA= sashelp.Orsales;
2 var product_Group Quantity Profit;
3 where Profit >2000 ;
4RUN;
3 Code Block
PROC PRINT
Explanation :
Similar to the previous block, but the `noobs` option suppresses the observation number from the output.
Copied!
1PROC PRINT DATA= sashelp.Orsales noobs;
2 var product_Group Quantity Profit;
3 where Profit >2000 ;
4RUN;
4 Code Block
PROC PRINT
Explanation :
Displays all variables for observations from the first quarter of 2000 (`2000Q1`) with a profit greater than 2000. The `where same and` statement adds an additional condition to only keep the 'Clothes' product category.
Copied!
1PROC PRINT DATA= sashelp.Orsales noobs;
2 where Quarter= '2000Q1' and Profit >2000 ;
3 where same and Product_Category = 'Clothes';
4RUN;
5 Code Block
PROC PRINT
Explanation :
Displays data for the first quarter of 2000. The `Year` variable is used as an identification (`id`) variable, which places it at the beginning of each row and fixes it during horizontal scrolling in some outputs.
Copied!
1PROC PRINT DATA= sashelp.Orsales noobs;
2 where Quarter= '2000Q1' ;
3 id Year;
4 var product_Group Quantity Profit;
5RUN;
6 Code Block
PROC SORT
Explanation :
Sorts the `sashelp.Orsales` table by the `Profit` variable in ascending order. The table is not saved; the sort is temporary for the next procedure (if any).
Copied!
1PROC SORT DATA= sashelp.Orsales;
2 BY Profit;
3RUN;
7 Code Block
PROC SORT
Explanation :
Sorts the table by `Year` (ascending) then by `Profit` (descending).
Copied!
1 
2PROC SORT
3DATA= sashelp.Orsales;
4BY Year descending Profit;
5RUN;
6 
8 Code Block
PROC SORT
Explanation :
This code block uses incorrect syntax. `PROC SORT` does not support `SUM` and `VAR` statements. The intention was likely to use another procedure like `PROC MEANS` or to perform a `DATA STEP` after sorting.
Copied!
1PROC SORT DATA= sashelp.Orsales;
2 BY Year;
3 sum Profit;
4 var Quarter Total_Retail_Price;
5RUN;
9 Code Block
PROC SORT
Explanation :
Sorts the table by `Year` (ascending) and `Profit` (descending). The `WHERE` clause is present but commented out, so it has no effect.
Copied!
1PROC SORT DATA= sashelp.Orsales;
2 BY Year descending Profit;
3 /*where Total_Retail_Sales >40000*/
4RUN;
10 Code Block
Instructions globales
Explanation :
Sets level 1 and 2 titles as well as a level 1 footnote for subsequent report outputs.
Copied!
1title1 'Orion Star Report';
2title2 'Profit Report';
3footnote1 'confidential';
4 
11 Code Block
PROC PRINT
Explanation :
Displays a selection of variables using their labels (`label`). It also redefines labels for `product_group` and `Total_Retail_Price` specifically for this output.
Copied!
1PROC PRINT DATA= sashelp.Orsales label;
2 var Year product_Group Quantity Profit Total_Retail_Price;
3 label product_group='Product'
4 Total_Retail_Price='Total Retail Price';
5RUN;
12 Code Block
Instructions globales
Explanation :
Cancels all previously defined titles and footnotes for future outputs.
Copied!
1title;
2footnote;
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.