You are on page 1of 25

Course 5: Advanced Queries

5.1 Controlling Query Output

5.2 Creating Parameterized Queries - Review

5.3 Grouping and Filtering Data in a Query

Chapter 6: Advanced Queries

5.1 Controlling Query Output

5.2 Creating Parameterized Queries - Review

5.3 Grouping and Filtering Data in a Query

Objectives

Understand the difference between a data table, data view, and report. Access the Result set format options in the Query Builder and Options windows.

Query Output Formats


There are three types of output that a SAS Enterprise Guide query can produce: Data table Data view Report

Data Table
The data table format saves the query results as a static data table against which you can run tasks. The table is not updated until you rerun the query.

Data View
The data view contains instructions on how to extract data from the source tables in the query. When the data view is displayed or used in a task, the query reprocesses the instructions and captures the data that exists in the source tables at that moment.

Report
The report format saves the query results as a report in the format that you specified as your default, either HTML, PDF, RTF, or text. The report is not updated until you rerun the query. You cannot run tasks against query results in this format.

Select Default Format of Query Results

Select the default query result format from Tools Options.


8

Override Format of Query Results

1) Access Options for This Query. 2) Choose the Result format. 3) Provide the storage name and location for the SAS data table or view.
9

Hands on - Controlling Query Output


This demonstration illustrates the differences between a SAS data table, data view, and report.

10

Course 5: Advanced Queries

5.1 Controlling Query Output

5.2 Creating Parameterized Queries - Review

5.3 Grouping and Filtering Data in a Query

11

Objectives

Create a prompt. Use the prompt to create a filter. Create and use several prompts. Combine filters.

12

Hands on Parameterized Queries


ABC company wants to create a HTML report that shows the ordered delivered in a certain time span for each order type. Specify proper title for this report. The time span and order type must be dynamic and specified by a user at the time the report is produced.

13

Hands on Combine filters


ABC company wants to create a SAS table that shows the Mail and Internet orders delivered before 15th of March.

14

Chapter 6: Advanced Queries

5.1 Controlling Query Output

5.2 Creating Parameterized Queries - Review

5.3 Grouping and Filtering Data in a Query

15

Objectives

Assign a grouping variable in a query. Select the analysis variable and the summary statistic to compute. Filter grouped data.

16

Grouping Data
The Query Builder can be used to group and summarize data.

17

Grouping Data

1) In the Select Data tab, choose a statistic for columns to be summarized.

2) Choose to limit the query result to one row for each unique value of the Group column(s).
18

Grouping by Multiple Columns

Multiple grouping columns and summary columns can be included.

19

Filtering Grouped Data

AverageSales < 70
20

Filtering Data

Filters based on individual rows

Filters based on summarized data


21

Filtering Grouped Data

...drop it in the Filter the summarized data pane.

Drag the computed column and...

22

Filtering Grouped Data


Choose a comparison operator. Type the value or expression.

Compare a column to distinct values, another column, or a defined parameter.

23

Filtered Output

24

Hands on - Summarizing and Filtering by Groups


ABC company would like to find out which products generate the most profit per order. Compute the average profit and the total items sold for orders placed on each product. Limit the query to include only products where the average profits are greater than $250.

25

You might also like