Seminar 4 SAS Tasks Creating a Listing Report Exercise 1: ABC

advertisement
Seminar 4 SAS
Tasks
1. Creating a Listing Report
Exercise 1: ABC company wants to post a list of suppliers with the following characteristics on its
intranet:
 Suppliers from the same country should be grouped together.
 Country names should only appear once at the beginning of a country grouping.
 CompanyNameLong should be labeled in the report as Company Name.
 The title Suppliers by Country should be centered at the top of the report.
Follow these steps:
1. Import Suppliers spreadsheet of the SupplyInfo MS Excel file.
2. To open the List Data task, select Describe  List Data… from the menu bar. The List Data dialog
box opens and enables you to select the columns that you want to see in the report and to
specify a role for those columns. In this dialog box, you can also change output formatting
options.
3. Drag the CompanyNameLong, Address, and City columns from the Variables pane to the List
Data Task Roles pane. Drop each column in the List variables role. The columns placed in this role
will be printed in the report in the order in which they are listed.
4. Drag Country to the Group analysis by role. Assigning a column to this role causes the table to be
sorted and grouped by the specified column.
5. Drag Country to the Identifying label role. By assigning Country to this role, the values of Country
appear only on the first row of the group of data associated with a country value.
6. To specify a label to be used in this task for the column CompanyNameLong, right-click on the
column name in the List Data Task Roles pane. Select Properties from the pop-up menu. In the
Properties dialog, type Company Name in the Label field and select OK.
7. To specify a title for the report, select Titles in the Selection pane. Deselect the Use default text
check box. In the Text field, delete the default title of Report Listing and type Suppliers by
Country.
8. Select Run to generate the report.
2. One-Way Frequencies
Exercise 2: From ABC company’s data, create two one-dimensional frequency tables to determine:

the number and percentage of orders generated by products imported from each
country;

the number and percentage of products ordered from each country.
Follow these steps:
1. Create a query that join tables products, ordersFinal and the table resulting from the import of
Suppliers spreadsheet of the SupplyInfo MS Excel file
2. Add to the Select tab the following columns: Country, CategoryName and Quantity.
3. Run the query and obtain a SAS table.
4. On the above created table, apply One-Way Frequencies ( Describe  One-Way Frequencies…)
task. Name the task DistribOrdersCountry.
5. Assign to Analysis Variables role the column Country.
6. In Statistics tab select Frequencies and Percentages option.
7. In Plots tab select one type of bar chart.
8. In Results tab scroll down until the end of this window and select at Order output data by:
Descending frequencies.
9. In Titles tab, type the following text: Distribution of Orders by Country.
1. Select Run to generate the report.
10. Similarly, starting from the same table, apply One-Way Frequencies ( Describe  One-Way
Frequencies…) task.
11. Assign to Analysis Variables role the column Country and to Frequency count role the column
Quantity.
12. In Statistics tab select Frequencies and Percentages option.
13. In Plots tab select one type of bar chart.
14. In Results tab scroll down until the end of this window and select at Order output data by:
Descending frequencies.
15. In Titles tab, type the following text: Distribution of Products Sales by Country.
16. Select Run to generate the report.
One-Way Frequencies: Task Roles
Create a
one-way frequency
table for each
specified variable.
21
Figure 1
One-Way Frequencies: Frequency Count
The value
of this variable
represents the
number of times
the row should
be counted.
22
Figure 2
3. Prompt Variables
Exercise 3:
Create a prompt variable which allows selecting at runtime a grouping variable for the one-way
frequency table in Exercise 2. The user should be able to choose between the CategoryName and
Country variables.
Follow these steps:
1. In the Prompt Manager window click Add.
2. In General tab, type for Name: Ad_var and for Displayed text: Frequency counts for
3. In Prompt Type and Values, select for Prompt type the value Variable, then click Load Values and
select the table that resulted from the query in Exercise 2. Clock Open and keep the variables
CategoryName and Country in the Value list. Click OK.
4. The macro variable Ad_var was added to the list of prompts.
5. In the Process Flow window locate the first One-way Frequency task created in Exercise 2, right click
on it and choose to modify it from the list of options that appears.
6. From the Analysis variables task role remove Country and add Ad_var.
7. Click Run and choose No in the window that will appear in order to keep the results of the original
One-way Frequency task.
8. Select a value from the list of variables and click Run.
4. User defined formats
Exercise 4: ABC wants to produce a detailed profit report based on its orders that displays the supplier's
company name, the product category and the profit obtained. Product category and profit should be
displayed as follows:
a) CategoryName should be displayed as Perishable if the product belongs to one of the categories:
Cheese, Meat, Produce, Bread and Seafood and as Non-Perishable if the product belongs to
one of the categories: Beverages, Condiments and Sweets;
b) Profit should be displayed according to the correspondence table below.
Follow these steps:
1. Create a query that join tables products, ordersFinal and the table resulting from the import of
Suppliers spreadsheet of the SupplyInfo MS Excel file
2. Add to the Select tab the following columns: Country and CategoryName.
3. Create, using the Advanced expression Editor the variable Profit, according to the formula
(SellPriceUnitCost)Quantity. The Profit variable, is of type Currency, with the output format
DOLLARw.d with width 8 and 2 decimal places.
4. Run the query and obtain a SAS table.
5. According to the indications from the course, create two user defined formats:
a. Food, of character type and with discrete values. This will be used to display the product
category.
b. Money, of numeric type and with range values. This will be used to display the profit.
6. Select Tasks  Data  Create Format… from the menu bar to open the Task dialog.
7. In Options tab specify the following values: Format name: Food, Specify format width: 14, Format
type: Character
1. In Define formats tab Select New Label and type Perishable in the Label field.
2. Select New Range and type Cheese. Maintain the value for Type as Discrete. Select New Range
again and type Meat. Continue adding new ranges for all of the remaining perishable categories:
Produce, Bread and Seafood.
3. To categorize non-perishables, select New Label, and type Non-Perishable. Select New Range and
repeat the previous process for each non-perishable category: Beverages, Condiments and Sweets.
8. Click Run.
9. Select Tasks  Data  Create Format… from the menu bar to open the Task dialog.
10. In Options tab specify the following values: Format name: Money, Specify format width: 14, Format
type: Number.
11. In Define formats tab Select New Label and type $0 to $14.99 in the Label field. Then set the range
of values according to the settings in Figure 3.
Figure 2
12. Select New Label and type $15 to $29.99 in the Label field. Then set the range of values according to
the settings in Figure 3.
13. Select New Label and type above $30 in the Label field. Then set the range of values according to
the settings in Figure 3.
14. Click Run.
15. In the Process Flow window locate the query created in this exercise, right click on it and choose to
modify it from the list of options that appears.
16. In Select Data tab, click CategoryName, then click the Property icon,
then click Change… button
near Format, in Categories select User Defined, and then select $FOOD. Click OK, then again click
OK.
17. In Select Data tab, click Profit, then click the Property icon,
then click Change… button near
Format, in Categories select User Defined, and then select MONEY. Click OK, then again click OK.
18. In the query builder window, select Options  Options for This Query and in Results tab set the
result as a Report. Click OK.
19. Click Run and then click No in the window that will appear in order to keep the initial results of the
query.
Download