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
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
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

Query Output Formats There are three types of output that a SAS Enterprise Guide query can

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 Table The data table format saves the query results as a static data table against

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.

Data View The data view contains instructions on how to extract data from the source tables

6

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.

7
7

Select Default Format of Query Results

Select the default query result format from Tools  Options….
Select the default
query result format
from Tools 
Options….

Override Format of Query Results

1) Access Options for This
1) Access
Options for This

9

Query.
Query.
Override Format of Query Results 1) Access Options for This 9 Query. 2) Choose the Result

2) Choose the Result format.

Override Format of Query Results 1) Access Options for This 9 Query. 2) Choose the Result

3) Provide the

storage name

and location

for the SAS data

table or view.

Hands on - Controlling Query Output This demonstration illustrates the differences between a SAS data table,

Hands on - Controlling Query Output

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

Course 5: Advanced Queries

5.1 Controlling Query Output 5.2 Creating Parameterized Queries - Review 5.3 Grouping and Filtering Data in
5.1
Controlling Query Output
5.2
Creating Parameterized Queries - Review
5.3
Grouping and Filtering Data in a Query

Objectives

  • Create a prompt.

  • Use the prompt to create a filter.

  • Create and use several prompts.

  • Combine filters.

Hands on Parameterized Queries

Hands on – Parameterized Queries ABC company wants to create a HTML report that shows the

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.

Hands on Combine filters

Hands on – Combine filters ABC company wants to create a SAS table that shows the

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

Chapter 6: Advanced Queries

5.1 Controlling Query Output 5.2 Creating Parameterized Queries - Review 5.3 Grouping and Filtering Data in
5.1
Controlling Query Output
5.2
Creating Parameterized Queries - Review
5.3
Grouping and Filtering Data in a Query

Objectives

  • Assign a grouping variable in a query.

  • Select the analysis variable and the summary statistic to compute.

  • Filter grouped data.

Grouping Data

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

The Query Builder can be used to group

and summarize data.

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.
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
Grouping by Multiple Columns
Multiple
grouping
columns and
summary
columns can
be included.
19

Filtering Grouped Data

Filtering Grouped Data AverageSales < 70 20
Filtering Grouped Data AverageSales < 70 20
AverageSales < 70
AverageSales < 70

Filtering Data

Filters based on individual rows Filters based on summarized data
Filters based on
individual rows
Filters based on
summarized data
Filtering Grouped Data ... drop it in the Filter the summarized data pane. Drag the computed
Filtering Grouped Data
...
drop
it in the
Filter the
summarized
data pane.
Drag the
computed
column and ...

Filtering Grouped Data

Choose a comparison operator.

Type the value or

expression.

Filtering Grouped Data Choose a comparison operator. Type the value or expression. Compare a column to

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

Filtered Output

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

25

product. Limit the query to include only products where

the average profits are greater than $250.

Hands on - Summarizing and Filtering by Groups ABC company would like to find out which
Hands on - Summarizing and Filtering by Groups ABC company would like to find out which