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!
proc print data= sashelp.Orsales;
var product_Group Quantity Total_Retail_Price;
sum Total_Retail_Price;
run;
1
PROC PRINTDATA= sashelp.Orsales;
2
var product_Group Quantity Total_Retail_Price;
3
sum Total_Retail_Price;
4
RUN;
2 Code Block
PROC PRINT
Explanation : Displays the variables `product_Group`, `Quantity`, and `Profit` for observations where `Profit` is greater than 2000.
Copied!
proc print data= sashelp.Orsales;
var product_Group Quantity Profit;
where Profit >2000 ;
run;
1
PROC PRINTDATA= sashelp.Orsales;
2
var product_Group Quantity Profit;
3
where Profit >2000 ;
4
RUN;
3 Code Block
PROC PRINT
Explanation : Similar to the previous block, but the `noobs` option suppresses the observation number from the output.
Copied!
proc print data= sashelp.Orsales noobs;
var product_Group Quantity Profit;
where Profit >2000 ;
run;
1
PROC PRINTDATA= sashelp.Orsales noobs;
2
var product_Group Quantity Profit;
3
where Profit >2000 ;
4
RUN;
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!
proc print data= sashelp.Orsales noobs;
where Quarter= '2000Q1' and Profit >2000 ;
where same and Product_Category = 'Clothes';
run;
1
PROC PRINTDATA= sashelp.Orsales noobs;
2
where Quarter= '2000Q1' and Profit >2000 ;
3
where same and Product_Category = 'Clothes';
4
RUN;
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!
proc print data= sashelp.Orsales noobs;
where Quarter= '2000Q1' ;
id Year;
var product_Group Quantity Profit;
run;
1
PROC PRINTDATA= sashelp.Orsales noobs;
2
where Quarter= '2000Q1' ;
3
id Year;
4
var product_Group Quantity Profit;
5
RUN;
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!
proc sort data= sashelp.Orsales;
by Profit;
run;
1
PROC SORTDATA= sashelp.Orsales;
2
BY Profit;
3
RUN;
7 Code Block
PROC SORT
Explanation : Sorts the table by `Year` (ascending) then by `Profit` (descending).
Copied!
proc sort data= sashelp.Orsales;
by Year descending Profit;
run;
1
2
PROC SORT
3
DATA= sashelp.Orsales;
4
BY Year descending Profit;
5
RUN;
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!
proc sort data= sashelp.Orsales;
by Year;
sum Profit;
var Quarter Total_Retail_Price;
run;
1
PROC SORTDATA= sashelp.Orsales;
2
BY Year;
3
sum Profit;
4
var Quarter Total_Retail_Price;
5
RUN;
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!
proc sort data= sashelp.Orsales;
by Year descending Profit;
/*where Total_Retail_Sales >40000*/
run;
1
PROC SORTDATA= sashelp.Orsales;
2
BY Year descending Profit;
3
/*where Total_Retail_Sales >40000*/
4
RUN;
10 Code Block
Instructions globales
Explanation : Sets level 1 and 2 titles as well as a level 1 footnote for subsequent report outputs.
Copied!
title1 'Orion Star Report';
title2 'Profit Report';
footnote1 'confidential';
1
title1 'Orion Star Report';
2
title2 'Profit Report';
3
footnote1 '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!
proc print data= sashelp.Orsales label;
var Year product_Group Quantity Profit Total_Retail_Price;
label product_group='Product'
Total_Retail_Price='Total Retail Price';
run;
1
PROC PRINTDATA= 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';
5
RUN;
12 Code Block
Instructions globales
Explanation : Cancels all previously defined titles and footnotes for future outputs.
Copied!
title;
footnote;
1
title;
2
footnote;
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.
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.