Sie sind auf Seite 1von 374

SAS Enterprise Guide 1:

Querying and Reporting

Course Notes
SAS Enterprise Guide 1: Querying and Reporting Course Notes was developed by Stacey Syphus.
Additional contributions were made by Richard Bell and Davetta Dunlap. Editing and production support
was provided by the Curriculum Development and Support Department.
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. Other brand and product
names are trademarks of their respective companies.
SAS Enterprise Guide 1: Querying and Reporting Course Notes
Copyright 2016 SAS Institute Inc. Cary, NC, USA. All rights reserved. Printed in the United States of
America. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written
permission of the publisher, SAS Institute Inc.
Book code E70539, course code LWEG171/EG171, prepared date 05Apr2016. LWEG171_002

ISBN 978-1-62960-127-4
For Your Infor mation iii

Table of Contents
Course Description ..................................................................................................... vii

Prerequisites ............................................................................................................. viii

Chapter 1 Getting Started .................................................................................. 1-1

1.1 Introducing SAS Enterprise Guide ...................................................................... 1-3

1.2 Course Scenarios ............................................................................................. 1-11


Demonstration: Navigating the SAS Enterprise Guide Workspace.....................1-17
Exercises ..................................................................................................1-24

1.3 Solutions ........................................................................................................1-27


Solutions to Exercises.................................................................................1-27

Chapter 2 Working with Data in a Project ......................................................... 2-1

2.1 Understanding SAS Data Structure...................................................................... 2-3

2.2 Accessing SAS and DBMS Data........................................................................2-10


Demonstration: Assigning a SAS Library ......................................................2-19
Exercises ..................................................................................................2-21

2.3 Importing Data Files ........................................................................................2-23


Demonstration: Using the Import Data Task...................................................2-26
Demonstration: Using the Import Data Task (continued)..................................2-29
Exercises ..................................................................................................2-32

2.4 Solutions ........................................................................................................2-36


Solutions to Exercises.................................................................................2-36

Chapter 3 Getting Started with Tasks................................................................ 3-1

3.1 Introduction to Tasks and Wizards ....................................................................... 3-3

3.2 Creating a Frequency Report ............................................................................. 3-11


Demonstration: Generating a One-Way Frequency Report ...............................3-16
Exercises ..................................................................................................3-18

3.3 Generating HTML, PDF, and RTF Output ...........................................................3-21


Demonstration: Modifying Output Format.....................................................3-26
iv For Your Information

3.4 Creating a Listing Report..................................................................................3-28


Demonstration: Using the List Data Task to Create a Report.............................3-30

3.5 Filtering Data in a Task.....................................................................................3-33


Demonstration: Filtering Data in a Task ........................................................3-36
Exercises ..................................................................................................3-39

3.6 Creating a Graph .............................................................................................3-42


Demonstration: Creating a Bar Chart ............................................................3-46
Exercises ..................................................................................................3-52

3.7 Solutions ........................................................................................................3-56


Solutions to Exercises.................................................................................3-56

Chapter 4 Creating Simple Queries................................................................... 4-1

4.1 Filtering and Sorting Data.................................................................................. 4-3


Demonstration: Selecting Columns and Filtering Rows .................................... 4-9
Exercises ..................................................................................................4-20

4.2 Creating New Columns with an Expression .........................................................4-24


Demonstration: Creating a Column with an Expression ...................................4-28
Exercises ..................................................................................................4-31

4.3 Grouping and Summarizing Data in a Query ........................................................4-34


Demonstration: Summarizing and Filtering by Groups ....................................4-38
Exercises ..................................................................................................4-40

4.4 Joining Tables .................................................................................................4-43


Demonstration: Joining Tables .....................................................................4-48
Exercises ..................................................................................................4-51

4.5 Solutions ........................................................................................................4-54


Solutions to Exercises.................................................................................4-54

Chapter 5 Creating Summarized Output ........................................................... 5-1

5.1 Generating Summary Statistics ........................................................................... 5-3


Demonstration: Generating Summary Statistics ............................................... 5-5
Exercises ................................................................................................... 5-8

5.2 Creating a Summary Report with the Summary Tables Task ...................................5-12
For Your Infor mation v

Demonstration: Creating a Tabular Summary Report.......................................5-14


Exercises ..................................................................................................5-18

5.3 Solutions ........................................................................................................5-21


Solutions to Exercises.................................................................................5-21

Chapter 6 Using Prompts in Tasks and Queries ............................................... 6-1

6.1 Prompting in Projects ........................................................................................ 6-3

6.2 Creating and Using Prompts in Tasks................................................................... 6-6


Demonstration: Prompting in Tasks ..............................................................6-10
Exercises ..................................................................................................6-13

6.3 Creating and Using Prompts in Queries...............................................................6-15


Demonstration: Prompting in Queries ...........................................................6-18
Exercises ..................................................................................................6-21

6.4 Solutions ........................................................................................................6-25


Solutions to Exercises.................................................................................6-25

Chapter 7 Customizing and Organizing Project Results .................................. 7-1

7.1 Combining Results ........................................................................................... 7-3


Demonstration: Combining Results ............................................................... 7-6
Exercises ................................................................................................... 7-9

7.2 Updating and Organizing Projects ...................................................................... 7-11


Demonstration: Updating Results .................................................................7-17
Exercises ..................................................................................................7-20

7.3 Solutions ........................................................................................................7-22


Solutions to Exercises.................................................................................7-22

Chapter 8 Learning More ................................................................................... 8-1

8.1 SAS Resources................................................................................................. 8-3

Appendix A Writing and Submitting SAS Programs ..........................................A-1

A.1 Writing and Submitting SAS Programs ................................................................ A-3


Demonstration: Adding a SAS Program to a Project....................................... A-13
Exercises ................................................................................................. A-21
vi For Your Information

A.2 Solutions ....................................................................................................... A-24


Solutions to Exercises................................................................................ A-24
For Your Infor mation vii

Course Description
This course is for users who do not have SAS programming experience but need to access, manage, and
summarize data from different sources, and present results in reports and graphs. This course focuses on
using the menu-driven tasks in SAS Enterprise Guide, the point-and-click interface to SAS, to create
queries and reports. It does not address writing SAS code or statistical concepts. This course serves as a
prerequisite for the SAS Enterprise Guide 2: Advanced Tasks and Querying course and for the Creating
Reports and Graphs with SAS Enterprise Guide course. It also serves as a prerequisite for the SAS
Enterprise Guide: ANOVA, Regression, and Logistic Regression course, which teaches statistical
concepts using SAS Enterprise Guide.

To learn more

For information about other courses in the curriculum, contact the SAS
Education Division at 1-800-333-7660, or send e-mail to training@sas.com.
You can also find this information on the web at http://support.sas.com/training/
as well as in the Training Course Catalog.

For a list of other SAS books that relate to the topics covered in this
course notes, USA customers can contact the SAS Publishing Department
at 1-800-727-3228 or send e-mail to sasbook@sas.com. Customers outside
the USA, please contact your local SAS office.
Also, see the SAS Bookstore on the web at http://support.sas.com/publishing/
for a complete list of books and a convenient order form.
viii For Your Information

Prerequisites
This course is designed for users with no programming experience or SAS knowledge. Before attending
this course, you should be familiar with Windows and other software, such as Microsoft Office or
spreadsheet programs.
Chapter 1 Getting Started

1.1 Introducing SAS Enterprise Guide............................................................................ 1-3

1.2 Course Scenarios .................................................................................................... 1-11


Demonstration: Navigating the SAS Enterprise Guide Workspace................................ 1-17
Exercises............................................................................................................. 1-24

1.3 Solutions ................................................................................................................. 1-27


Solutions to Exercises ........................................................................................... 1-27
1-2 Chapter 1 Getting Started

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1 Introducing SAS Enterpr ise Guide 1-3

1.1 Introducing SAS Enterprise Guide

Objectives
State the capabilities and major features
of SAS Enterprise Guide software.
Describe configuration options.

What Is SAS?
SAS is a suite of business solutions and technologies
to help organizations solve business problems.
Statistical Process Control Categorical Data Analysis
Analysis of Variance

R Integration High-Performance Analytics


Statistical Analysis Process Capability Analysis Social Network Analysis
Reliability Analysis Scheduling
Design of Experiments
Cluster Analysis Linear Programming
Nonlinear Programming Vector Autoregressive Models Network Flow Models
Predictive Modeling

Business Solutions
Mixed-Integer Programming
Time Series Analysis Sample Size Computations
X11 & X12 Models ARIMA Models
Nonparametric Analysis D-Optimal

Scoring Acceleration Bayesian


Business Intelligence Survival Analysis
Ensemble Models

Neural Networks
Decision Trees High-Performance Forecasting
Information Theory
Descriptive Modeling Psychometric Analysis Mixed Models Multivariate Analysis

Multinomial Discrete Choice

Predictive Analytics Analysis of Means


Information Management
Interior-Point Models
Random Forests
Survey Data Analysis

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-4 Chapter 1 Getting Started

What Is SAS Enterprise Guide?

This course is written for SAS Enterprise Guide 7.1. To determine which version
of Enterprise Guide you are using, select Help About SAS Enterprise Guide.

What Is SAS Enterprise Guide?


visual interface to SAS

6 ...

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1 Introducing SAS Enterpr ise Guide 1-5

What Is SAS Enterprise Guide?


visual interface to SAS

transparent data access

7 ...

What Is SAS Enterprise Guide?


visual interface to SAS

transparent data access

interactive task windows

8 ...

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-6 Chapter 1 Getting Started

What Is SAS Enterprise Guide?


visual interface to SAS

transparent data access

interactive task windows

export capabilities

9 ...

What Is SAS Enterprise Guide?


visual interface to SAS

transparent data access

interactive task windows

export capabilities

programming interface

10 ...

If you are a SAS programmer, you can use the Enterprise Guide Program Editor to create new code
or to modify existing SAS programs. The Program Editor offers several features to help you reduce your
programming time, including autocompletion for hundreds of SAS statements, procedures, and options.
The Program Editor also provides built-in syntax and function Help, and automatic code formatting.

See Appendix A for details about writing and submitting SAS programs in Enterprise Guide.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1 Introducing SAS Enterpr ise Guide 1-7

What Is SAS Enterprise Guide?


visual interface to SAS

transparent data access

interactive task windows

export capabilities

programming interface

Help and tutorial

11

1.01 Multiple Choice Poll


Describe your experience with SAS Enterprise Guide.
a. I had not heard of it until I was told to take this class.
b. I saw other people use it.
c. I have used it a little.
d. I have used it extensively.

12

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-8 Chapter 1 Getting Started

Discussion

What are your reasons for learning


about SAS Enterprise Guide?

13

Behind the Scenes


Enterprise Guide prepares SAS code, either generated
through point-and-click tasks or written by the user,
and submits the code to SAS.

14 ...

You can modify the programming code to customize the result and to access SAS features that are not
available in the point-and-click interface.
You can save code and execute it in a batch environment.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1 Introducing SAS Enterpr ise Guide 1-9

Behind the Scenes


SAS then executes the code and delivers the results
to Enterprise Guide.

15

Configuration
Enterprise Guide can be configured to work with
SAS either on a local PC or on a remote server.

Local Client/Server

16

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-10 Chapter 1 Getting Started

Configuration
Enterprise Guide can also be used as part of the platform
for SAS Business Analytics. Enterprise Guide includes
additional features that are related specifically
to the SAS platform.

17

Look for to identify features that are specific to the platform for SAS Business Analytics.

1.02 Multiple Answer Poll


Describe your Enterprise Guide configuration.
a. SAS is installed on my PC.
b. SAS is installed on a remote server.
c. My company has the platform for
SAS Business Analytics.
d. other
e. not sure

18

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-11

1.2 Course Scenarios

Objectives
Define the business scenario for class demonstrations
and exercises.
Describe the steps to build an Enterprise Guide
project.
List the topics that are discussed in this course.
Compare the three levels of exercises that are used
in the course.
List additional online resources.
Access the extended learning page for this course.

20

Orion Star Sports & Outdoors


Orion Star Sports & Outdoors is a fictitious global sports
and outdoors retailer. For demonstrations and exercises,
you use data about Orions customers, products, orders,
and employees.

21

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-12 Chapter 1 Getting Started

Orion Star Project


Throughout the course, you use Enterprise Guide
to access various types of data sources, query the data
to filter and join tables, and produce several summary
reports and graphs.

22

Enterprise Guide Interface: The Project


A project is a single
file that serves as
a collection of
data sources
SAS programs
and logs
tasks and queries
results
informational
Project
notes for
documentation.
You can control the contents, sequencing, and updating
of a project.
e101d01.egp
23

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-13

Building an Enterprise Guide Project


To begin work with Enterprise Guide, you
1. create a new project
2. add data to the project
3. run tasks against the data.

In addition, you can


4. customize, update, and share results
5. automate the process.

24

About This Course

Chapter 2
Working with Data in a Project
25

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-14 Chapter 1 Getting Started

About This Course

Chapter 3
Getting Started with Tasks
26

About This Course

Chapter 4
Creating Simple Queries
27

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-15

About This Course

Chapter 5
Creating Summarized Output
28

About This Course

Chapter 6
Using Prompts in Tasks and Queries
29

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-16 Chapter 1 Getting Started

About This Course

Chapter 7
Customizing and Organizing Project Results
30

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-17

Navigating the SAS Enterprise Guide Workspace

Start Enterprise Guide and begin to build a project.


1. Open Enterprise Guide.
When you enter Enterprise Guide, the Welcome to SAS Enterprise Guide dialog box appears
automatically to enable you to create a new project or open an existing project. Any projects listed
under the Open a project heading have a .egp file extension.

2. Select New Project.

If the Welcome window is not open, you can create a new project by selecting File New
Project. You can also open an existing project by selecting File Open Project.
3. Enterprise Guide displays three main windows by default. Notice the windows, which are labeled as
follows:
Project Tree
Process Flow
Resources Pane (The server list is active.)

4. By default, the Project Tree window and Resources Pane are docked on the left side. Click to
dock the window on the left side or to auto-hide it. Auto-hide hides the window, but displays the
window name on the border of the Enterprise Guide window. Place the cursor over the window name
to make the window visible.

The Project Tree, Process Flow, and other helpful windows can be opened from the View
menu. To reset all windows to their original positions, select Tools Options from the menu
bar. Select Restore Window Layout OK.
5. Insert an existing SAS data set by selecting File Open Data.

You can also use the icon on the toolbar to open projects, data, and other files.

6. To navigate to data stored on your personal computer, select My Computer. Navigate to the location
indicated by your instructor and select customers Open to add the SAS data set to the project.

A shortcut to the customers data set is added to the project tree and the process flow. By default,
a snapshot of a few rows of the data appears in the data grid in the workspace.

7. After a data source is added to the project, you can use it for analysis and reporting. With
the customers data set open in the data grid, select Describe Characterize Data.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-18 Chapter 1 Getting Started

8. The Characterize Data task is in a wizard format that enables you to go through each of the three steps
and modify any options. Step 1 enables you to verify the data source that you want to analyze. Select
Next.
9. If you want more information about a particular task, access the Enterprise Guide Help facility
through the Task dialog box. To learn more about the Characterize Data task, click the Help button
in the Task dialog box. View the contents of the Help facility relating to the Characterize Data task
and report options. Close the Help window by clicking .

10. In Step 2 of the task, you can customize the report options, including producing a summary report,
graph, or output data set. To change the name of the data set that includes frequency counts for any
character columns, select Browse in the Frequency Data pane.

11. Enter CustomerCounts in the File name field and select Save Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-19

12. In Step 3, limit the number of unique categorical values to be reported per variable by typing 15.

13. Select Finish to run the task and view the results.

To observe the status of the task as it runs, select Details in the lower left corner
of Enterprise Guide. The Task Status window appears, and indicates the processing task,
status, and server.

The output includes frequency counts for character columns, summary statistics for numeric columns,
and basic graphs to characterize each.

Partial Output

14. To view the contents of the current project, you can click on the toolbar, double-click
Process Flow in the project tree, or press the F4 key. The Characterize Data task was added
in the project tree and process flow, and linked to the customers data set.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-20 Chapter 1 Getting Started

15. Return to the task results by double-clicking (the Characterize Data icon) in either the project tree
or process flow. To view the task code, click the Code tab.

The SAS code can be saved and edited to customize the task results or to use features
of SAS that are not available in the Enterprise Guide point-and-click environment.

16. The Log window and summary display messages from SAS for each task that you execute. To view
the log, click the Log tab.

17. This task produces two data sets. The first data set that was created is displayed automatically.
Click the Output Data (2) tab to view the data set that contains frequency counts.

The other data set containing summary statistics can be accessed either from the drop-down
list on the Output Data tab, or from the process flow.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-21

18. The output data can be exported easily to a wide variety of other software formats, including
Microsoft Excel. To open the data in Excel automatically, select Send To Microsoft Excel.
Close Excel and do not save the changes.

19. To save the collection of tasks, code, and results generated so far, you must save the project.
Select File Save Project As from the menu bar and click the My Computer icon. Navigate
to the appropriate file location and type Chapter1 for the filename. Select Save.

Projects can be saved on a Windows machine or on a remote server where SAS is running.

20. (Optional) Multiple process flows can be created and renamed to organize items in a project. Right-
click Process Flow in the project tree and select Rename. Enter Demos.
21. A separate process flow can be created for exercises. Select File New Process Flow. Another
way to rename a process flow is to select the Properties button and enter Exercises in the Label
field.

New data sources are added to the active process flow. Before adding a new data source,
be sure to verify that the correct process flow is selected in the project tree.

You can copy and paste items from one process flow to another in the project tree.

22. Click (the Save Project icon) on the toolbar.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-22 Chapter 1 Getting Started

Three Levels of Exercises


Level 1 Step-by-step instructions

Level 2 Less information and guidance

Challenge Description of task


Might require SAS programming knowledge
or use of the Help facility

The course is designed to have you complete only


one level of exercises, based on your skill level.

32
32

Detailed solutions are available at the end of each chapter.

Some exercise sections do not include all three levels of exercises.

Extending Your Learning


An extended learning page is available for this course.
It includes the following:
the course files
a PDF of the course notes
instructor-tip videos
papers and presentations

33

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-23

SAS Help Facility


The SAS Enterprise Guide Help facility and SAS
on the Web give additional directions about
Enterprise Guide and the SAS programming language.

34

Additional Resources
SAS Enterprise Guide communities:
https://communities.sas.com/
SAS Enterprise Guide blog: http://blogs.sas.com/sasdummy/
SAS OnlineDoc: http://support.sas.com/documentation

35

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-24 Chapter 1 Getting Started

Exercises

Level 1

1. Creating a Project and Running the Characterize Data Task


a. In the Chapter1 project, add the employee_organization data set.

If you created an Exercises process flow in the previous demonstration, be sure to select
Exercises in the project tree before you add the data set.

If you do not have the Chapter1 project, you can create a new project by selecting
New Project in the Welcome to SAS Enterprise Guide window. If Enterprise Guide
is open, select File New Project.
1) Select File Open Data from the menu bar.
2) Select My Computer on the left side of the Open Data window.
3) Navigate to the location of the course data.
4) Select the employee_organization data set and select Open.

b. Use the Characterize Data task to investigate the distribution of each of the columns
in the employee_organization data set.
1) Select Describe Characterize Data in the data grid to open the Task Wizard.
2) Limit the number of unique categorical values to be reported per variable to 15.

3) Run the task and examine the results.


Partial Results

c. Save the project as Chapter1 in the location that is specified by your instructor.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-25

Level 2

2. Running the Data Set Attributes Task


The Data Set Attributes task enables you to create a report with information about a particular data
set, including creation date, location, and number of observations, as well as the variable names,
labels, types, and formats.

a. In the Chapter1 project, open the employee_organization data set in the data grid and open
the Data Set Attributes task.

If you created an Exercises process flow in the previous demonstration, be sure to select
Exercises in the project tree before you add the data set.

If you did not save the Chapter1 project from the Level 1 exercise, create a new project
and add the employee_organization data set.

b. In Step 2 of the task, make sure that Default Report is the only other output that is selected.
c. Run the task and examine the results.
Partial Results

d. Save the project as Chapter1 in the location that is specified by your instructor.

Challenge

3. Submitting a SAS Program with a Coding Error


In addition to using the point-and-click tasks, you can create a new SAS program or include existing
SAS programs in your project. Enterprise Guide provides a color-coded, syntax-checking SAS
language editor for editing new or existing SAS programs in your project.

a. Add the program e101e03.sas to the Chapter1 project.

If you created an Exercises process flow in the previous demonstration, be sure to select
Exercises in the project tree before you add the data set.
b. Run the program, review the log summary, and identify the error.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-26 Chapter 1 Getting Started

You can click on the error message in the log summary to go to the corresponding line
in the log.

c. Correct the error in the Program window, resubmit the corrected program, and review the results.

You can right-click on the error message in the log summary to go to the corresponding
line in the program.

Partial Results

d. Save the project as Chapter1 in the location that is specified by your instructor. Select Yes when
you are prompted to save the changes that you made to the e101e03 program.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.3 Solutions 1-27

1.3 Solutions
Solutions to Exercises
1. Creating a Project and Running the Characterize Data Task
a. In the Chapter1 project, add the employee_organization data set.

If you created an Exercises process flow in the previous demonstration, be sure to select
Exercises in the project tree before you add the data set.

If you do not have the Chapter1 project, you can create a new project by selecting
New Project in the Welcome to SAS Enterprise Guide window. If Enterprise Guide
is open, select File New Project.

1) Select File Open Data from the menu bar.


2) Select My Computer on the left side of the Open Data window.
3) Navigate to the location of the course data.
4) Select the employee_organization data set and select Open.
b. Use the Characterize Data task to investigate the distribution of each of the columns
in the employee_organization data set.

1) Select Describe Characterize Data in the data grid to open the Task Wizard.
2) Limit the number of unique categorical values to be reported per variable to 15.
a) Select Next twice to advance to Step 3 of the Characterize Data Wizard.
b) Enter 15 in the Limit the number of unique categorical values to be reported
per variable field.

3) Run the task and examine the results.


Select Finish.
Partial Results

c. Save the project as Chapter1 in the location that is specified by your instructor.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-28 Chapter 1 Getting Started

If you saved the project, you can select File Save Chapter1 only.

1) Select File Save Project As from the menu bar.


2) Select My Computer and navigate to the location that is indicated by your instructor.
3) Enter Chapter1 in the File name field and select Save to close the Save As dialog box.
2. Running the Data Set Attributes Task
a. In the Chapter1 project, open the employee_organization data set in the data grid and open
the Data Set Attributes task.

If you created an Exercises process flow in the previous demonstration, be sure to select
Exercises in the project tree before you add the data set.

If you did not save the Chapter1 project from the Level 1 exercise, create a new project
and add the employee_organization data set.
1) Double-click employee_organization in the project tree or process flow to open
the table in the data grid.
2) Select Data Data Set Attributes.
b. In Step 2 of the task, make sure that Default Report is the only other output that is selected.
1) Select Next to advance to Step 2 of the Data Set Attributes Wizard.
2) Under Other Outputs, clear the Enhanced Report check box.
c. Run the task and examine the results.
Select Finish.
Partial Results

d. Save the project as Chapter1 in the location that is specified by your instructor.

If you completed a previous exercise, you can select File Save Chapter1 only.

1) Select File Save Project As from the menu bar.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.3 Solutions 1-29

2) Select My Computer and navigate to the location that is indicated by your instructor.
3) Enter Chapter1 in the File name field and select Save to close the Save As dialog box.
3. Submitting a SAS Program with a Coding Error
In addition to using the point-and-click tasks, you can create a new SAS program or include existing
SAS programs in your project. Enterprise Guide provides a color-coded, syntax-checking SAS
language editor for editing new or existing SAS programs in your project. (See Appendix A for details
about writing and submitting SAS code in Enterprise Guide.)
a. Add the program e101e03.sas to the Chapter1 project.

If you created an Exercises process flow in the previous demonstration, be sure to select
Exercises in the project tree before adding the data set.

1) Select File Open Program from the menu bar.


2) Select My Computer on the left side of the Open Data window.
3) Navigate to the location of the course data.
4) Select the e101e03.sas program and select Open.
b. Run the program, review the log summary, and identify the error.

You can click on the error message in the log summary to go to the corresponding line
in the log.

1) Select Run on the menu bar.


2) Because the program has an error, the SAS log appears automatically in the workspace.
Review the log to identify the error.

The SAS keyword var was misspelled as vat.


c. Correct the error in the Program window, resubmit the corrected program, and review the results.

You can right-click on the error message in the log summary to go to the corresponding
line in the program.

1) Right-click on the error in the log summary and select Go To Program Source.
2) Change the spelling of the SAS keyword to var.
3) Select Run from the menu bar. Select Yes when you are prompted to replace the results.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-30 Chapter 1 Getting Started

Partial Results

d. Save the project as Chapter1 in the location that is specified by your instructor. Select Yes when
you are prompted to save the changes that you made to the e101e03 program.

If you completed the Level 1 or Level 2 exercise, you can select File Save Chapter1
only.

1) Select File Save Project As from the menu bar.


2) Select My Computer and navigate to the location that is indicated by your instructor.
3) Enter Chapter1 in the File name field and select Save to close the Save As dialog box.
4) Click Yes when you are prompted to save the e101e03 program.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 2 Working with Data in a
Project

2.1 Understanding SAS Data Structure .......................................................................... 2-3

2.2 Accessing SAS and DBMS Data ............................................................................. 2-10


Demonstration: Assigning a SAS Library .................................................................. 2-19

Exercises............................................................................................................. 2-21

2.3 Importing Data Files ................................................................................................ 2-23


Demonstration: Using the Import Data Task .............................................................. 2-26

Demonstration: Using the Import Data Task (continued).............................................. 2-29


Exercises............................................................................................................. 2-32

2.4 Solutions ................................................................................................................. 2-36


Solutions to Exercises ........................................................................................... 2-36

Solutions to Student Activities (Polls/Quizzes) ........................................................... 2-44


2-2 Chapter 2 Working w ith Data in a Project

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.1 Understanding SAS Data Structur e 2-3

2.1 Understanding SAS Data Structure

Objectives
State the definition of a SAS data set.
State how data is stored in a SAS data set.

Business Scenario
Orion maintains data in a variety of different formats
and locations. Business analysts want to access
the data sources in SAS Enterprise Guide.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-4 Chapter 2 Working w ith Data in a Project

Common Data Formats


SAS Enterprise Guide can read and use data from
a variety of different formats and locations.

SAS Enterprise Guide can also read SAS Information Maps. An information map is a business
metadata layer that is applied on top of the data sources in your data warehouse. Metadata is
information about the structure and content of data. An information map does not contain any
physical data. Information maps provide business users with a user-friendly way to query data
and obtain results for themselves.

2.01 Multiple Answer Poll


Which types of data do you work with?
a. Microsoft Excel
b. Microsoft Access
c. DBMS tables (such as Oracle or DB2)
d. SAS data sets
e. text files (delimited files)
f. other

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.1 Understanding SAS Data Structur e 2-5

SAS Data Set


A SAS data set (or table) is a rectangular table of rows
and columns.

Rows
(observations)

Columns
(variables)

Column Names
Column names can be up to 32 characters long.
It is recommended that column names also
start with a letter or underscore
include only letters, underscores, and numbers.

Enterprise Guide allows spaces and special symbols in variable names because it invokes the
VALIDVARNAME=ANY option when SAS initializes. Not all SAS environments invoke this option.
You should follow SAS standard naming conventions for column names if you anticipate running code
generated by Enterprise Guide in other SAS applications. Standard naming rules are that columns must
start with a letter or underscore, and that the remaining characters are letters, underscores, or numbers.

An option in Enterprise Guide 6.1 and later enables you to set variable naming rules. To force
Enterprise Guide to follow standard SAS naming conventions, select Tools Options
Data General and in the Naming Options pane, change Valid variable names to
Basic variable names (V7).

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-6 Chapter 2 Working w ith Data in a Project

2.02 Multiple Answer Poll


Which names follow the standard SAS naming rules?
a. data5mon
b. 5monthsdata
c. data#5
d. five months data
e. five_months_data
f. FiveMonthsData

Column Labels
For display purposes, columns can also have a
corresponding label. Labels can be up to 256 characters
and include spaces and special symbols.

11

Variable names appear by default in the data grid and in tasks. To display labels rather than variable
names, select Tools Options Data General and select Use labels for column names.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.1 Understanding SAS Data Structur e 2-7

Column Type
A columns type is either character (string) or numeric.

Numeric values can be


Character numbers
values are currency
1 to 32,767 date (days from 01JAN1960)
characters long. time (seconds from midnight).
12

As well as name and type, another required column attribute is length. Length refers to the number
of bytes that are used to store each of the variables values in a SAS data set. Character values are stored
with a length of 1 to 32,767 bytes. One byte equals one character. Numeric values are stored as floating
point numbers in 8 bytes of storage by default. Eight bytes of floating point storage provide space for
16 or 17 significant digits.

Formats
A format is used to control how values are displayed.
Formats do not affect how values are stored.

Format: DATE Format: DOLLAR


Width: 9 Width: 10
Stored value: 18324 Decimal Places: 2
Stored value: 19.25

13

A format (display format) is an instruction that you apply to a column. The format tells Enterprise Guide
how data values should be displayed. Use formats to control the appearance of data values or to group
data values for analysis.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-8 Chapter 2 Working w ith Data in a Project

An informat (read-in format) is an instruction that Enterprise Guide uses to read data values into
a variable. For example, the following value contains a dollar sign and commas:
$1,000,000
To remove the dollar sign ($) and commas (,) before storing the numeric value 1000000 in a variable,
read this value with the DOLLAR10. informat.

Formats

14

SAS Data Set Properties


Viewing a data sets properties enables you to examine
the data set and column attributes.

15

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.1 Understanding SAS Data Structur e 2-9

Attributes of a SAS data set are stored in the properties and include the following:
the data set name
the storage location
the date last modified
all column attributes (such as name, type, and length)
the number of rows and columns
the server on which the data resides

To view the properties of a data source, click in the data grid or right-click the item
in the project tree or process flow. Select Properties from the menu.

In the SAS documentation, a data sets properties are referred to as the descriptor portion.

2.03 Multiple Choice Poll


Open the employee_info data set. Click the Properties
button on the toolbar and select Columns. What is the
type and length of the variable Postal_Code?
a. character, length 5
b. character, length 8
c. numeric, length 5
d. numeric, length 8

16

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-10 Chapter 2 Working w ith Data in a Project

Missing Values
If a data value is not present for a column in a particular
row, it is considered missing.
A missing character value is displayed as a blank.
A missing numeric value is displayed as a period or dot.

18

Many tasks in Enterprise Guide provide options for how to handle missing values in the report
or analysis.

2.2 Accessing SAS and DBMS Data

Objectives
Identify methods for accessing data.
Define SAS libraries.
Add data to a project via a library definition.
Explore data interactively.

20

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-11

Business Scenario
Orion Star wants to use SAS Enterprise Guide to access
SAS and DBMS tables that include information about
customers and orders.

21

DBMS is the acronym for database management system.

Methods for Adding Data to a Project


The Open Data window provides multiple options for
accessing existing data sources.

22

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-12 Chapter 2 Working w ith Data in a Project

Methods for Adding Data to a Project


Data can be accessed via the local Windows directory
structure, including network drives.

23

Methods for Adding Data to a Project


Servers provide access to locations where SAS is installed
and configured to work with SAS Enterprise Guide.

24

Your SAS Enterprise Guide administrator must define remote servers.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-13

Methods for Adding Data to a Project


SAS Folders provide quick access to data that is defined
in the SAS platform for a particular user or group.

25

Accessing Data via SAS Servers or Folders


The Resources pane provides another method to view
and access all of your available files and data sources.

26

If you have sufficient permission, you can perform various server and file management tasks, such
as deleting, copying, or renaming files, by right-clicking items in the window (servers, folders, libraries,
data sets, and files).

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-14 Chapter 2 Working w ith Data in a Project

2.04 Quiz
1. Select File New Project.
2. Select View Servers or click the Servers icon
in the Resources pane below the project tree.

3. Expand Servers your server name Files.


4. Navigate to the location of the course data.
What two things happen when you double-click
customers.sas7bdat?

27

SAS Libraries
Another way to access SAS or DBMS data is via
a SAS library. A SAS library is a collection of files that
are defined, recognized, and accessible by SAS.

SAS library

29

SAS libraries are typically created and maintained by SAS administrators or users of other
SAS applications.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-15

SAS Libraries
An engine is used with a library to specify the data type
and how it should be read.

SAS library

SAS/ACCESS
engine

30

SAS Library
A library named orion can be defined with the Base SAS
engine to reference all SAS data sets in s:\workshop.

31

On Windows and UNIX operating systems, a SAS library is a directory. For z/OS, a SAS library
is an operating system file. SAS libraries are accessed by a library reference name, such as Sasuser
or orion_db2.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-16 Chapter 2 Working w ith Data in a Project

Microsoft Access Library


A library that is named Orionacs can be defined with
the SAS/ACCESS Interface to PC Files engine to read
all of the tables in a Microsoft Access database.

32

Library names must start with a letter or underscore, and include only letters, underscores, or numbers.
Library names can have up to eight characters.

DBMS Library
A library that is named Oriondb can be defined with
the SAS/ACCESS Interface to Teradata engine to read
all of the tables in a Teradata database.

33

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-17

2.05 Quiz
1. Select View Servers or click the Servers icon
in the Resources pane below the project tree.
2. Expand Servers your server name Libraries.
What libraries are listed?

34

Available Libraries
Some libraries can be defined automatically by SAS.

Work temporary library

Sasuser permanent library for


an individual user ID

Sashelp, Maps libraries including


sample or descriptive tables

36

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-18 Chapter 2 Working w ith Data in a Project

Custom Libraries
Custom SAS libraries are typically set up by your SAS
administrator. However, the Assign Project Library Wizard
can be used to define libraries to SAS or DBMS data
sources for which you have Read permission.

37

A library that is created using the Assign Project Library Wizard remains assigned for the duration
of the SAS session or until it is manually unassigned. When you start a new Enterprise Guide session,
the Assign Project Library task must be rerun to reassign the library.

Adding Data to a Project


After a library is assigned,
double-click or drag a data
source from the Server List
pane to the Project Tree
or Process Flow window.
This enables you to add
a shortcut to the data
n the project.

38

When a data source is added to a project, it automatically opens in the data grid. To change this, select
Tools Options Data General and clear Automatically open data when added to the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-19

Assigning a SAS Library

This demonstration illustrates how to assign a library and add a data set to the project from that library.
1. Select File New Project.
2. To create a library, begin by selecting Tools Assign Project Library.
Your SAS administrator is typically responsible for setting up libraries for you to access
on the SAS server. However, if you want to define a library to SAS within your project or
to DBMS tables to which you have Read access, you can use the Assign Project Library task.

3. In Step 1 of the Assign Project Library Wizard, enter ORION in the Name field. Select the server
on which the course data resides and click Next.

4. In Step 2, the engine is defined and necessary information is provided to connect to the data.
The File System engine type and the BASE engine read the latest version of SAS data sets. Provide
the path of the course data and click Next.
To connect to a DBMS source, change Engine type to Database System and select
the appropriate SAS/ACCESS engine from the Engine drop-down list.

5. In Step 3, enter access in the Name field and readonly in the Value field. This ensures that even
if you are granted Write access to the data at the operating system or database level, SAS does not
enable you to make changes to the data sources in the library. Click Next.
The name-value pairs correspond with keywords and values used in the LIBNAME statement.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-20 Chapter 2 Working w ith Data in a Project

6. In Step 4, verify the settings and select Test Library. You should see OK appear. Click Finish
to define the library in your project.
7. To access the data sources in the orion library, select View Servers or click in the Resources
pane. Expand Servers <your server name> Libraries ORION. Double-click ORDERS
to add a shortcut to the project.

You need to refresh the server view to see the current contents of the orion library. You can
do this by highlighting the server name and clicking the Refresh button.

8. Save the project as Chapter2.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-21

Exercises

Level 1

1. Assigning a Project Library


Create the orion library to access the Orion customer and employee SAS data sets.
a. In the Chapter2 project, use the Assign Project Library task to create the orion library and point
to the location of the course data.

If you do not have the Chapter2 project, you can create a new project.

b. Include the access=readonly option in Step 3 of the task. Then test and assign the library.
c. View the orion library in the Server window. If you do not see the library or the data sets, select
your server and click Refresh.

d. Save the Chapter2 project.

Level 2

2. Using the Servers Window for File Operations


Use the Server window to copy, paste, and delete data sets.
a. The Server window can be used to create a copy of a data set. To create a temporary copy, right-
click the travel_expenses table in the orion library and select Copy. Then right-click the Work
library and select Paste.
b. Double-click the travel_expenses table in the Work library to add it to the project.
c. Right-click travel_expenses in the project tree or process flow and select Delete.
Is the table deleted from the library?

d. Right-click travel_expenses in the Work library in the Server window and select Delete.
Are you able to delete the table?

e. Right-click travel_expenses in the orion library in the Server window and select Delete.
Are you able to delete the table?

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-22 Chapter 2 Working w ith Data in a Project

Challenge

3. Browsing a Data Set in the Data Grid


When you view an existing data source in Enterprise Guide, you use the data grid. You can search the
data grid for a specific value or variable name. Then you can hold, hide, or move columns while you
browse the data.

a. In the Chapter2 project, add the employee_master SAS data set.


b. Use the Find option in the Edit menu to search for Warehouse Manager in the Job_Title column.
c. Hold the Employee_ID variable at the left side of the window so that it remains visible when
you scroll to the right.

Right-click on specific variables to view the options.

d. Hide the Salary and Birth_Date variables.


e. Free (or remove the hold for) the Employee_ID variable and show the previously hidden
variables.

f. Move the Manager_ID variable so that it appears to the right of Employee_Name.

Moving the variable does not change the variable order in the data set; only the display
order in the data grid is changed.
g. Close the data grid.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-23

2.3 Importing Data Files

Objectives
Import a Microsoft Excel spreadsheet and create
a SAS data set.
Import a fixed-width text file and create
a SAS data set.

44

Business Scenario
Orion maintains a Microsoft Excel file named products
and a text file named orders. To use these data sources
in SAS Enterprise Guide, they must be imported into
SAS data sets.

Import Data

45

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-24 Chapter 2 Working w ith Data in a Project

2.06 Quiz
Select File Open Data and navigate to the location
of the course data if necessary.
What happens when you open the Excel products file?

46

Import Data Task


The Import Data task can be used to read text
or PC-based data files (including Microsoft Excel
and Microsoft Access) and to create SAS data sets.

48

The Import Data task can read the following:


Microsoft Access 1.x, 2.0, Access 95, Access 97, Access 2000, Access 2002 (XP), Access 2003,
Access 2007
In the 64-bit version of Enterprise Guide, you cannot open Microsoft Access data. If you need
this feature, it is suggested that you install the 32-bit version of Enterprise Guide.
Microsoft Excel 4-7, Excel 97, Excel 2000, Excel 2002 (XP), Excel 2003, Excel 2007, Excel 2010,
Excel 2013
HTML

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-25

text (delimited or fixed column)


all versions of Stata (*.DTA) under Microsoft Windows
all versions of SPSS (*.SAV) under Microsoft Windows
JMP

Discussion

Why is the Import Data task a necessary step when you read Excel or text files?
What information must you provide so that the data can be interpreted correctly?

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-26 Chapter 2 Working w ith Data in a Project

Using the Import Data Task

Part 1: Importing a Microsoft Excel Spreadsheet Named Products

1. In the Chapter2 project, select File Open Data from the menu bar. Navigate to the location
of the course data and select the Excel products file. Select Open.
2. The Import Data task is automatically launched. Verify that the Excel products spreadsheet
is the source data file and that the output SAS data set is products. Click Next.

The storage location of the resulting SAS data set can be changed by selecting a different
library. To determine the default library, Enterprise Guide searches for the first writable
library in this order: egtask, gridwork, Work, Sasuser. You can modify the default library
by selecting Tools Options Output Library.
3. In Step 2, verify that the ProductList worksheet is highlighted. Select the check boxes for First row
of range contains field names and Rename columns to comply with SAS naming conventions.
Click Next.

The Rename columns to comply with SAS naming conventions option truncates names
to 32 characters and replaces spaces and special symbols with an underscore.

4. In Step 3, change the name in the first row to Product_ID and the label to Product ID.
5. Also, in Step 3, change the type for Supplier_ID to String. You are prompted to choose a method for
determining the length of the character variable. Verify that Scan all values in the column is selected
and click OK Next.

The length of a character column corresponds to the maximum number of characters that c an
be stored in a single data value.

6. In Step 4, accept the default setting for Advanced Options. (Nothing is selected.) Click Finish
to complete the import process.

For more information about the advanced options, click the Help button.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-27

7. Verify the results on the Output Data tab. To view generated DATA step code, click the Code tab.
Partial Results (7 of 481 rows)

8. The task and the new SAS data set are accessible by double-clicking the Import Data icon
in the project. You can rename the Import Data task to emphasize the name of the SAS data set that
is created in the import process. Right-click the Import Data icon in the project tree or process flow
and select Rename. Enter Import Products.

9. Save the Chapter2 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-28 Chapter 2 Working w ith Data in a Project

Setup for the Quiz (Live Web Only)


Import the Products Excel file and create a SAS data set.
1. Create a new project.
2. Add the Products Excel file. (Select File Open
Data.)
3. In Step 1, verify that the output SAS data set
is Products.
4. In Step 2, verify that the ProductList worksheet
is highlighted and that First row of range contains
field names is selected.
5. Accept the default settings in Steps 3 and 4.
6. Select Finish to create the new SAS data set.

51

2.07 Quiz
What do you select to make a change in the Import Data
task, such as altering the name of the first variable?

52

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-29

Using the Import Data Task (continued)

Part 2: Importing a Fixed-Width Text File Named Orders

1. In the Chapter2 project, select File Open Data from the menu bar. Navigate to the location
of the course data and open orders.txt. The file is added to the project. Because it is not a structured
data set, it cannot be used for reporting or querying.

2. To use the Import Data task to create a customized SAS data set from the text file, right-click
orders.txt in the project tree or process flow. Select Import Data.

You can also select File Import Data.

3. In Step 1 of the Import Data task, verify that the output data set is named orders. Accept the default
library and click Next.

4. In Step 2, select Fixed columns. Select the File contains field names on record number check box
and verify that the value is 1. Select the Rename columns to comply with SAS Naming
conventions check box.

5. Click on the start of each field to define the column breaks. Click Next.

You do not need to place a column break before the first field.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-30 Chapter 2 Working w ith Data in a Project

6. In Step 3, modify the properties of the variables as described below.


a. Exclude the Employee_ID variable by clearing the Inc check box.
b. Format Discount with a percent sign by clicking twice in the Output Format box and clicking
. In the Numeric format category, scroll to select the PERCENTw.d format. Change
the overall width to 5 and select OK.
c. Format Profit as a currency value by changing the drop-down list in the Type column
to Currency. Click Next.

7. In Step 4, do not make any changes. Click Finish to create the imported SAS data set.
The Import Data task and orders data set are added to the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-31

Partial Results (7 of 617 rows)

8. Save the Chapter2 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-32 Chapter 2 Working w ith Data in a Project

Exercises

Level 1

4. Creating a New SAS Data Set from an Excel Spreadsheet


Add the Addresses spreadsheet from the Excel employee_info workbook.
a. In the Chapter2 project, use the Import Data task to open the Excel employee_info workbook.
Create a new SAS data set named employee_addresses.

If you do not have the Chapter2 project, you can create a new project.

You can save the data set in the default SAS library, which can be Sasuser, Work,
or EGTASK.

b. Read the data from the Addresses worksheet. Indicate that the first row contains variable names.
c. Change the type of the Postal_Code variable to String.

Scan all values in the column to determine a proper length.

d. Modify each of the labels to replace underscores with spaces.


e. Finish the Import Data task and view the data set.

The variable names appear in the data grid, but labels are displayed in the reports.

Partial Results (7 of 424 rows)

f. Rename the Import Data task as Import Employee Addresses.


g. Save the Chapter2 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-33

Level 2

5. Importing a Delimited Text File into a New SAS Data Set


The employee_payroll.csv file is a comma-delimited text file. The first row in the text file contains
appropriate names for the variables in the new SAS data set. The first few rows of the text file are
shown below.

Enclosing quotation marks are automatically removed when the file is imported.

a. In the Chapter2 project, import the data in the employee_payroll.csv file to create a new
SAS data set.
b. Name the new SAS data set employee_payroll and indicate that the file is comma delimited.
c. Do not include the columns for Marital_Status or Dependents.

d. Change the type for Employee_ID to Number.


e. Change the type for Salary to Currency.
f. Change the output format for Birth_Date to a Day-Month-Year format (for example, 16-12-2008)
with a display of a four-digit year. For Salary, use a currency format that displays no decimal places.
Hint: For the Birth_Date column, use the DDMMYYDw.d format with an overall width of 10.
g. Change the label of Employee_Term_Date to Employee Termination Date.
h. Finish the Import Data task and view the data in the new data set.
Partial Results (8 of 424 rows)

i. Rename the Import Data task as Import Employee Payroll.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-34 Chapter 2 Working w ith Data in a Project

j. Save the Chapter2 project.

Challenge

6. Modifying Generated DATA Step Code to Subset Data


Modify the code generated by the Import Data task to subset the data set to include only current
employees who do not have a termination date.

a. Complete Exercise 5.
b. On the Code tab, find the INFILE statement. Notice the program references a temporary text file
Enterprise Guide created as part of the import process. Modify the task to set an advanced option
to generalize the import step to run outside of Enterprise Guide. Rerun the task and examine
the Code tab. How did the INFILE statement change?

c. Right-click the Import Employee Payroll icon in the project tree or process flow and select
Add as a Code Template.
d. Modify the SAS program so that the name of the data set is Employee_Payroll_Active.

e. Add a subsetting IF statement to the code to include only those employees with a missing value
for Employee_Term_Date.

If you enter the keyword IF and place your mouse pointer over the text, a syntax tooltip
appears. The tooltip includes links . For additional help, you can click on any of the links
to access documentation, samples, or papers

f. Modify the code so that the Employee_Term_Date variable is not included in the output data set.
g. Submit the code for execution and view the data in the new data set.
Partial Results (8 of 308 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-35

h. Save the Chapter2 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-36 Chapter 2 Working w ith Data in a Project

2.4 Solutions
Solutions to Exercises
1. Assigning a Project Library
Create the orion library to access the Orion customer and employee SAS data sets.
a. In the Chapter2 project, use the Assign Project Library task to create the orion library and point
to the location of the course data.

If you do not have the Chapter2 project, you can create a new project.

1) Select Tools Assign Project Library.


2) In Step 1, enter orion in the Name field and click Next.
3) In Step 2, verify that the engine is BASE. Navigate to or enter the location of the course data.
Click Next.
b. Include the access=readonly option in Step 3 of the task. Then test and assign the library.
1) Enter access in the Name field.
2) Enter readonly in the Value field and click Next.
3) Select Test Library and verify that OK is displayed.

4) Click Finish.
c. View the orion library in the Server window. If you do not see the library or the data sets, select
your server and click Refresh.
d. Save the Chapter2 project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location specified by your instructor.
Enter Chapter2 in the File name field and select Save.

2. Using the Server Window for File Operations


Use the Server window to copy, paste, and delete data sets.
a. The Server window can be used to create a copy of a data set. To create a temporary copy, right-
click the travel_expenses table in the orion library and select Copy. Then right-click the Work
library and select Paste.

b. Double-click the travel_expenses table in the Work library to add it to the project.
c. Right-click travel_expenses in the project tree or process flow and select Delete.
Is the table deleted from the library?
No, only the shortcut is removed from the project, but the table remains in the library.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-37

d. Right-click travel_expenses in the Work library in the Server window and select Delete.
Are you able to delete the table?
Yes. If you have Write access to a library and the data sets within, you can move, copy,
and delete files in the Server window. These actions cannot be undone, so be careful!
e. Right-click travel_expenses in the orion library in the Server window and select Delete.
Are you able to delete the table?
No. Because you used the ACCESS=READONLY option when you defined the orion
library, you cannot make changes to the contents.
3. Browsing a Data Set in the Data Grid
When you view an existing data source in Enterprise Guide, you use the data grid. You can search
the data grid for a specific value or variable name. Then you can hold, hide, or move columns while
you browse the data.
a. In the Chapter2 project, add the employee_master SAS data set.
1) Select File Open Data.
2) Navigate to the location of the course data. Select employee_master and select Open.
b. Use the Find option in the Edit menu to search for Warehouse Manager in the Job_Title column.
1) Select Job_Title to highlight the column.
2) Select Edit Find from the menu bar.
3) Enter Warehouse Manager in the Find What field.
4) Select Find Next and examine the search results.

5) Select Close.
c. Hold the Employee_ID variable at the left side of the window so that it remains visible when
you scroll to the right.
Right-click specific columns to view the options.

1) Scroll to the left of the table. Right-click the column heading for the Employee_ID variable
and select Hold from the pop-up menu.

2) Use the scroll bar at the bottom of the data grid to scroll through the other variables. Notice
that the Employee_ID variable remains in view at the left of the window.

d. Hide the Salary and Birth_Date variables.


1) Hold down the Ctrl key and select the Salary and Birth_Date variables.
2) Right-click on the heading for one of the selected variables and select Hide from the pop-up menu.
e. Free (or remove the hold for) the Employee_ID variable and show the previously hidden variables.
1) Right-click on the heading for any variable and select Free.
2) Right-click again and select Show.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-38 Chapter 2 Working w ith Data in a Project

f. Move the Manager_ID variable so that it appears to the right of Employee_Name.


Moving the variable does not change the variable order in the data set; only the display
order in the data grid is changed.

1) Highlight the variable Manager_ID by clicking on the column heading.


2) Click again on the column heading and drag it to the right of Employee_Name while you hold
down the left mouse button.
g. Close the data grid.

4. Creating a New SAS Data Set from an Excel Spreadsheet


Add the Addresses spreadsheet from the Excel employee_info workbook.
a. In the Chapter2 project, use the Import Data task to open the Excel employee_info workbook.
Create a new SAS data set named employee_addresses.

If you do not have the Chapter2 project, you can create a new project.

You can save the data set in the default SAS library, which might be Sasuser, Work,
or EGTASK.
1) Select File Open Data.
2) Navigate to the course data and select the Excel file employee_info. Select Open.
3) In Step 1, select Browse and change the name of the data set to employee_addresses.
4) Select Save Next.
b. Read the data from the Addresses worksheet. Indicate that the first row contains variable names.

1) In Step 2, select the Addresses worksheet.


2) Verify that the First row of range contains field names check box is selected.
3) Click Next.
c. Change the type of the Postal_Code variable to String.
1) In Step 3, click in the Type column for the Postal_Code row.
2) Click on the down arrow and select String.
3) Select OK to scan all values in the column to determine a proper length.
d. Modify each of the labels to replace underscores with spaces.
In the Label column, double-click to change the labels to Employee ID, Employee Name,
Street ID, Street Number, Street Name, and Postal Code.

e. Finish the Import Data task and view the data set.

The variable names appear in the data grid, but labels are displayed in the reports.

Click Finish.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-39

Partial Results (7 of 424 rows)

f. Rename the Import Data task as Import Employee Addresses.

1) Right-click Import Data (employee_info.xls [Addresses]) in the project tree or process flow
and select Rename.
2) Enter Import Employee Addresses.
g. Save the Chapter2 project.

1) Select on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter2 in the File name field and select Save.

5. Importing a Delimited Text File into a New SAS Data Set


The employee_payroll.csv file is a comma-delimited text file. The first row in the text file contains
appropriate names for the variables in the new SAS data set. The first few rows of the text file are
shown below.

Enclosing quotation marks are automatically removed when the file is imported.

a. In the Chapter2 project, import the data in the employee_payroll.csv file to create a new
SAS data set.
1) Select File Import Data.
2) Navigate to the location of the course data and select employee_payroll.csv Open.
b. Name the new SAS data set employee_payroll and indicate that the file is comma delimited.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-40 Chapter 2 Working w ith Data in a Project

1) In Step 1 of the Import Data task, verify that the name of the new SAS data set is
employee_payroll.
2) Click Next.
3) In Step 2, verify that a comma is the delimiter and that field names are read from the first
record. Click Next.
c. Do not include the columns for Marital_Status or Dependents.

In Step 3 of the Import Data task, clear the check boxes for Marital_Status and Dependents.
d. Change the type for Employee_ID to Number.
Click in the Type column for the Employee_ID variable. Click on the down arrow
and select Number.
e. Change the type for Salary to Currency.
Click in the Type column for the Salary variable. Click on the down arrow and select Currency.
f. Change the output format for Birth_Date to a Day-Month-Year format (for example, 16-12-2008)
with a display of a four-digit year. For Salary, use a currency format that displays no decimal
places.
Hint: Use the DDMMYYDw.d format with an overall width of 10.
1) Double-click in the Output Format column for the Birth_Date row and click .

2) Select the Date category in the Output Data Set Format window.
3) Select the DDMMYYDw.d format and change the Overall width field to 10. Select OK.

4) Double-click in the Output Format column for the Salary row and click .

5) Change the value of decimal places to 0. Select OK.


g. Change the label of Employee_Term_Date to Employee Termination Date.
In the Label column, double-click to change the label to Employee Termination Date.
h. Finish the Import Data task and view the data in the new data set.
Click Finish.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-41

Partial Results (8 of 424 rows)

i. Rename the Import Data task as Import Employee Payroll.

1) Right-click Import Data (employee_payroll.csv) in the project tree or process flow.


Select Rename.
2) Enter Import Employee Payroll.
j. Save the Chapter2 project.

1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter2 in the File name field and select Save.

6. Modifying Generated DATA Step Code to Subset Data


Modify the code generated by the Import Data task to subset the data set to include only current
employees who do not have a termination date.
a. Complete Exercise 5. (See the solutions above to complete this exercise.)

b. On the Code tab, find the INFILE statement. Notice the program references a temporary text file
Enterprise Guide created as part of the import process. Modify the task to set an advanced option
to generalize the import step to run outside of Enterprise Guide. Rerun the task and examine
the Code tab. How did the INFILE statement change?
1) Double-click the Import Employee Payroll task in the project and select the Code tab.
2) Scroll down to find the INFILE statement.
3) Select Modify Task. Click Next three times to advance the step 4. Select the Generalize
import step to run outside SAS Enterprise Guide check box.

4) Click Finish Yes when prompted to replace the results.


5) Select the Code tab and scroll to find the INFILE statement.
The INFILE statement now references the original text file in the location of the course
data.

c. Right-click the Import Employee Payroll icon in the project tree or process flow and select
Add as Code Template.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-42 Chapter 2 Working w ith Data in a Project

d. Modify the SAS program so that the name of the data set is Employee_Payroll_Active.
In the DATA statement, change the name of the output data set to Employee_Payroll_Active.
e. Add a subsetting IF statement to the code to include only those employees with a missing value
for Employee_Term_Date.
Following the INPUT statement, insert the following statement:
if Employee_Term_Date=.;

If you enter the keyword IF and place your mouse pointer over the text, a syntax tooltip
appears. For additional help, you can click on any of the links to access documentation,
samples, or papers.

f. Modify the code so that the Employee_Term_Date variable is not included in the output data set.
1) Find the DROP statement in the DATA step.
2) Add Employee_Term_Date to this statement so that it appears as follows:
drop Marital_Status Dependents Employee_Term_Date;

Spacing and case might be different when the above is compared to the generated code.

g. Submit the code for execution and view the data in the new data set.
Partial Results (8 of 308 rows)

Select Run to submit the code.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-43

h. Save the Chapter2 project.


1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter2 in the File name field and select Save.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-44 Chapter 2 Working w ith Data in a Project

Solutions to Student Activities (Polls/Quizzes)

2.02 Multiple Answer Poll Correct Answers


Which names follow the standard SAS naming rules?
a. data5mon
b. 5monthsdata
c. data#5
d. five months data
e. five_months_data
f. FiveMonthsData

10

2.03 Multiple Choice Poll Correct Answer


Open the employee_info data set. Click the Properties
button on the toolbar and select Columns. What is the
type and length of the variable Postal_Code?
a. character, length 5
b. character, length 8
c. numeric, length 5
d. numeric, length 8

17

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-45

2.04 Quiz Correct Answer


What two things happen when you double-click
customers.sas7bdat?
1. The data is opened in the data grid.
2. A shortcut to the customers SAS data set
is added to the project.

28

2.05 Quiz Correct Answer


1. Select View Servers or click the Servers icon
in the Resources pane below the project tree.
2. Expand Servers your server name Libraries.
What libraries are listed?
Possible answers:
MAPS, Work, Sashelp,
Sasuser, EGTASK

35

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-46 Chapter 2 Working w ith Data in a Project

2.06 Quiz Correct Answer


Select File Open Data and navigate to the location
of the course data if necessary.
What happens when you open the Excel products file?
The Import Data task automatically opens.

47

2.07 Quiz Correct Answer


What do you select to make a change in the Import Data
task, such as altering the name of the first variable?
Modify Task

53

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 3 Getting Started with
Tasks

3.1 Introduction to Tasks and Wizards ........................................................................... 3-3

3.2 Creating a Frequency Report .................................................................................. 3-11


Demonstration: Generating a One-Way Frequency Report.......................................... 3-16

Exercises............................................................................................................. 3-18

3.3 Generating HTML, PDF, and RTF Output ................................................................ 3-21


Demonstration: Modifying Output Format ................................................................. 3-26

3.4 Creating a Listing Report ........................................................................................ 3-28


Demonstration: Using the List Data Task to Create a Report ....................................... 3-30

3.5 Filtering Data in a Task ............................................................................................ 3-33


Demonstration: Filtering Data in a Task .................................................................... 3-36
Exercises............................................................................................................. 3-39

3.6 Creating a Graph ..................................................................................................... 3-42


Demonstration: Creating a Bar Chart ....................................................................... 3-46

Exercises............................................................................................................. 3-52

3.7 Solutions ................................................................................................................. 3-56


Solutions to Exercises ........................................................................................... 3-56

Solutions to Student Activities (Quizzes/Polls) ........................................................... 3-72


3-2 Chapter 3 Getting Started w ith Tasks

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.1 Introduction to Tasks and Wizards 3-3

3.1 Introduction to Tasks and Wizards

Objectives
Define a SAS Enterprise Guide task.
Describe methods for accessing tasks
in SAS Enterprise Guide.
State the functions of common features
in the task dialog boxes.

What Is a Task?
A task is a specific type of analysis, report, or data
manipulation that you can perform against data
in a project.

Tasks

SAS Enterprise Guide tasks generate SAS code and formatted results. Tasks include SAS procedures that
range from simple data listings to more complex analytical procedures.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-4 Chapter 3 Getting Started w ith Tasks

3.01 Quiz
Select Tasks Browse in your SAS Enterprise Guide
session. Which tasks might be the most helpful when
you work with your data?

Tasks can also be accessed via the Tasks window in the Resources pane. You can open the window
by selecting View Tasks.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.1 Introduction to Tasks and Wizards 3-5

Task Favorites
Position your mouse pointer over any task and select
the star to add it to your Favorites list.

Accessing Favorites List


The Favorites list can be accessed from the Favorites
menu or in the Tasks section of the Resources pane.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-6 Chapter 3 Getting Started w ith Tasks

Select Favorites Manage Favorites to customize your Favorites list. You can create folders to group
tasks to organize them.

Associating a Task with Data


Tasks are usually associated with a particular data source
in the project.

2. Select
a task.

1. Highlight the data


in the project tree.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.1 Introduction to Tasks and Wizards 3-7

Selecting a Task
Tasks can also be selected from the menu in the data grid.

Tasks: Selection Pane


Each task dialog box follows a similar format that includes
a Selection pane that lists the options available for that task.

Selection
pane

10

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-8 Chapter 3 Getting Started w ith Tasks

Tasks: Data
Select Data to define how columns are used to generate
the task result.

Help is displayed
when a Task role
is selected.

11

3.02 Quiz
1. Select File New Project.
2. Select File Open Data and navigate
to the location of the course data.
3. Select Orion_Profit Open.
4. In the data grid, select
Describe Distribution Analysis.
5. Drag Customer_Age to the Analysis variables role.
6. Right-click Customer_Age and select Properties.
Which column attributes
can you modify?

12

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.1 Introduction to Tasks and Wizards 3-9

Tasks: Titles and Footnotes


Select Titles to add descriptive titles and footnotes.

Enter custom
titles or
footnotes.

14

Tasks: Properties
Task properties can be modified to rename the task,
examine task attributes, and modify the output format.

15

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-10 Chapter 3 Getting Started w ith Tasks

Wizard View
Selected tasks have a wizard view that can be used
to set up the task results quickly.

16

The Summary Statistics, Summary Tables, Bar Chart, Pie Chart, and Line Plot tasks have an optional
wizard. The wizards and traditional tasks are listed separately in the task menus.

Working with Tasks


Task code, log, output data, and results are available for
viewing and further analysis through tabs and menus.

17

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-11

Working with Tasks


Tasks can be refreshed or modified from the Project Tree
or Process Flow window, or the Results tab.

18

3.2 Creating a Frequency Report

Objectives
Access the One-Way Frequencies task.
Generate a one-way frequency report and bar chart.

21

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-12 Chapter 3 Getting Started w ith Tasks

Business Scenario
Orion management wants a report that counts the number
of products offered for each category.

22

One-Way Frequencies Task


The One-Way Frequencies task can be used to generate
frequency counts, percentages, graphs, and statistical
tests to analyze the distribution of your data.

23

A one-way frequency report shows the distribution of a variables values.


To access the One-Way Frequencies task, select Tasks Describe One-Way Frequencies
from the menu bar. You can also select Describe One-Way Frequencies from the data grid.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-13

3.03 Multiple Choice Poll


Highlight any data source in the project and select
Tasks Describe One-Way Frequencies.
Which task role requires a variable assignment?
a. Analysis variables
b. Frequency count
c. Group analysis by

24

One-Way Frequencies: Task Roles


The One-Way Frequencies task produces a one-way
frequency report for each variable included in the
Analysis variables role.

26

To generate crosstabulation tables, also known as contingency tables, use the Table Analysis task.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-14 Chapter 3 Getting Started w ith Tasks

One-Way Frequencies: Task Roles


The Group analysis role can be used to produce separate
frequency reports for each unique value of a variable.

27

Setup for the Poll


Open the One-Way Frequencies task again by selecting
Tasks Describe One-Way Frequencies. In the
Tasks Roles window, select Help and read the description
for the Frequency count role.

28

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-15

3.04 Multiple Choice Poll


What would be the frequency value for Children Sports if
Units_in_Stock is assigned to the Frequency count role?
a. 3
b. 25
c. 50
d. 70
Units_in
Product_Name Product_Category
_Stock
Childrens Mitten Children Sports 25

Sunf it Swimming Trunks Children Sports 15


Product_
Frequency
Osprey Ny lon Shorts Children Sports 10 Category
Liga Football Boot Shoes 5 Children
??
Sports
Py tossage Bathing Sandal Shoes 15
Shoes ??

29

One-Way Frequencies: Additional Options


Use additional options to customize the report or create
a data set with frequencies and percentages.

31

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-16 Chapter 3 Getting Started w ith Tasks

Generating a One-Way Frequency Report

Orion management wants a report that summarizes the number of products offered for each category.
Use the One-Way Frequencies task to generate the report.
1. Create a new project and add the products SAS data set from the course data.
2. To open the One-Way Frequencies task, select Describe One-Way Frequencies.
You can also select Tasks Describe One-Way Frequencies from the menu bar.
3. Drag Product_Category from the Variables to assign pane and drop it onto the Analysis variables
role in the Task roles pane.

4. Select Statistics in the Selection pane. To include only the frequency and percent statistics, select
Frequencies and percentages in the Frequency table options pane.

5. Select Results in the Selection pane. To create a data set including the frequency counts and
percentages, select the Create data set with frequencies and percentages check box. Click Browse
and enter ProductCounts in the File name field. Click Save.

6. Select Titles in the Selection pane. To modify the title, clear the Use default text check box.
In the Text field, delete the default title of One-Way Frequencies Results and type Number
of Products per Category.
In the Titles window, when Analysis is selected in the Section pane, the Text area displays
only your title text. To display the footnote text, select Footnotes in the Section pane.
7. To give the One-Way Frequencies task icon a more descriptive name in the project, select Properties
in the Selection pane and click Edit. Enter Products per Category in the Label field. Click OK.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-17

8. Click Run to generate the report and examine the results. View the report on the Results tab.
Click the Output Data tab to view the data set.
Partial Output

9. To remove the title, The FREQ Procedure, that is added to the output automatically, select Tools
Options. Select Tasks General from the Selection pane. Clear the Include SAS procedure titles
in results check box. Click OK to close the Options window.
The Tasks General pane also includes an option that enables you to change or delete
the default footnote.

10. To rerun the task, select Refresh on the Results tab.

11. Save the project as Chapter3.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-18 Chapter 3 Getting Started w ith Tasks

Exercises

Level 1

1. Using the One-Way Frequencies Task to Generate Frequency Counts and Percentages
a. In the Chapter3 project, add the employee_organization data set.

If you do not have the Chapter3 project, you can create a new project.

b. Use the One-Way Frequencies task to generate a report that analyzes the Department column.
c. Include a horizontal bar chart as part of the report.
d. Add the title Employee Counts by Department and delete the footnote.
e. Modify the task properties to change the task label to Dept Freq Report.
f. Generate the report and examine the results.
g. Modify the One-Way Frequencies task to display only frequencies and percentages.
Rerun the report and replace the results.
h. Save the Chapter3 project.
Partial Results (graph not shown)

Final results assume that the Include SAS procedure titles in results option is turned off.
You can modify this option by selecting Tools Options Tasks General.

Level 2

2. Using the One-Way Frequencies Task to Produce a Grouped Report

a. In the Chapter3 project, add the employee_organization data set if it is not already included.
b. Use the One-Way Frequencies task to analyze Job_Title, grouped by Department. Include only
frequencies and percentages.
c. Order the output report by descending frequencies.

Scroll down in the Results window to find the Order output data by option.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-19

d. Add the title Employees Job Title and delete the footnote.
e. Change the task label to Jobs by Dept Freq Report and run the task.
f. Save the Chapter3 project.
Partial Results

Challenge

3. Producing a Grouped Frequency Report with Group Values in the Titles


a. Complete the Level 2 exercise and continue with the next steps.
b. Modify the Jobs by Dept Freq Report task. Change the title to Employees by Job Title in
#byval(department) Department. This syntax places the name of each distinct group in the title.

Documentation about the #BYVAL(variable) syntax can be found by selecting Help


SAS on the Web SAS Product Documentation. Search for #BYVAL.
c. Access the code in the One-Way Frequencies task by selecting Preview Code. Select the
Show custom insertion points check box.
d. To remove the secondary BYLINE title, add the following statement at the earliest point of
insertion in the task code:
options nobyline;

Documentation about the BYLINE and NOBYLINE system options can be found
by selecting Help SAS Syntax Help. On the Index tab, enter byline.
e. To reinstate the secondary BYLINE title for future tasks, add the following statement at the end
of the task code:
options byline;

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-20 Chapter 3 Getting Started w ith Tasks

f. Create the modified report and replace the results.


g. Save the Chapter3 project.
Partial Results

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.3 Generating HTML, PDF, and RTF Output 3-21

3.3 Generating HTML, PDF, and RTF


Output

Objectives
List output format options.
Compare the advantages of each output format.

37

Business Scenario
Orion management wants to publish a product
categories frequency report in HTML format
on the intranet.

38

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-22 Chapter 3 Getting Started w ith Tasks

Task Output Formats


By default, SAS Enterprise Guide produces task results
in SAS Report format. However, you can also choose
to generate HTML, PDF, RTF, or text output.

39

SAS Report Format


The SAS Report format enables you to combine multiple
task results into a single report. This report can be viewed
in SAS applications or exported as HTML, XML, or PDF
files.
Banner image

Bar Chart task

Summary
One-Way Statistics task
Frequencies task

40

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.3 Generating HTML, PDF, and RTF Output 3-23

3.05 Multiple Answer Poll


Which output formats would you like to use in your work?
a. SAS Report
b. HTML
c. PDF
d. RTF
e. text

41

3.06 Quiz
What are some advantages of each format?

42

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-24 Chapter 3 Getting Started w ith Tasks

Summary of Output Formats


SAS HTML RTF PDF Text
Report
Software required Other SAS Any Any word Adobe Any text
for viewing applications browser processor Reader viewer
outside of SAS (Internet (Microsoft (Notepad)
Enterprise Guide Explorer) Word)
Ability to combine Yes (File Yes No No No
results into a New (Tools (only with (only with (only with
single document Report) HTML code) code) code)
Document)
Ability to edit Yes No Yes No Yes
results in viewing
software
Results formatted Yes No Yes Yes Yes
for printing
44

Default Output Format


The default output format can be set by selecting
Tools Options Results General. Custom options
can also be set for each of the output formats.

45

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.3 Generating HTML, PDF, and RTF Output 3-25

Overriding the Default Output Format


The properties of individual tasks can be modified
to override the default format and produce other
types of results.

46

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-26 Chapter 3 Getting Started w ith Tasks

Modifying Output Format

This demonstration illustrates modifying the properties of a task to produce HTML, PDF, RTF, or text output.
1. In the Chapter3 project, double-click the Products per Category icon in the project tree or process
flow to view the Results tab. Select Modify Task.

2. Select Properties in the Selection pane and click Edit.


3. Select Results in the Selection pane. Select Customize result formats, styles, and behavior.
Select HTML, PDF, RTF, and Text to view all output possibilities. Change the drop-down menu
next to HTML to BarrettsBlue and click OK.

4. Click Run to generate the report in all output formats. Click Yes when you are prompted to replace
the results. Click the various Results tabs to view each report.

The SAS Report, HTML, and text results can all be viewed directly on the Results tabs.
Clicking the PDF or RTF tab opens the results outside of Enterprise Guide.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.3 Generating HTML, PDF, and RTF Output 3-27

Partial Results (Notice the SAS Report, HTML, PDF, RTF, and Listing tabs.)

5. Save the Chapter3 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-28 Chapter 3 Getting Started w ith Tasks

3.07 Quiz (Live Web Only)


1. Double-click on any One-Way Frequencies task in
the project. On the Results tab, select Modify Task.
2. Select Properties Edit Results.
3. Select Customize results formats, styles, and
behaviors. Select the HTML style.
4. In the drop-down list, change the style to EGDefault.
5. Select OK Run. Select Yes when you are prompted
to replace the results.

49

3.4 Creating a Listing Report

Objectives
Access the List Data task.
Set report options.
Group the report.

52

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.4 Creating a Listing Report 3-29

Business Scenario
The Marketing Department at Orion Star wants to create
a customer list that includes ID, name, and age group.
A separate report should be generated for each country.

53

List Data Task


The List Data task displays
rows of data in a data set,
including options to group Group
or sum columns. rows.
Display
each row.

Sum
columns.
54

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-30 Chapter 3 Getting Started w ith Tasks

Using the List Data Task to Create a Report

Use the List Data task to print a list of customers including ID, name, and age group.
A separate report should be generated for each country.

1. In the Chapter3 project, add the customers data set in the project tree or process flow.

If you do not have the Chapter3 project, you can create a new one.

2. To open the List Data task, select Describe List Data from the data grid. The List Data dialog box
appears and enables you to select columns and assign them to specific roles to generate a report.

3. Drag Customer_ID, Customer_Name, and Customer_Age_Group from the Variables to assign


pane to the List variables role. The columns placed in this role are printed in the report in the order
in which they are listed. Also drag and drop Customer_Country to the Group analysis by role.
A separate report is produced for each country.
The button can also be used to assign variables to roles.

4. To specify a title for the report, select Titles in the Selection pane. Clear the Use default text check
box. In the Text field, delete the default title and enter Orion Star Customer List.
5. Click Run to generate the report.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.4 Creating a Listing Report 3-31

Partial Results

6. To modify the task to change the column labels and remove the row numbers, select Modify Task
on the Results tab.
7. The Identifying label role can be used to replace the Row number column with a column from
the data. Drag Customer_ID from the List variables role to the Identifying label role.

To remove the row number without assigning a column to the Identifying label role,
select Options in the Selection pane and deselect Print the row number.

8. To specify a label to be used in this task for the Customer_Name column, right-click the column
name in the Task roles pane. Select Properties from the menu.

9. In the Properties dialog box, enter Name in the Label field and click OK.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-32 Chapter 3 Getting Started w ith Tasks

10. Repeat Step 8 to change the label for Customer_Age_Group to Age Group.

By default, variable names still appear in the task dialog box. To view labels, right-click
on a variable and select Show Labels.

11. By default, the task icon in the project is labeled List Data. Give the task a more descriptive label
so that it is easily identified in the project. Select Properties Edit and enter Customer List
by Country in the Label field. Click OK.
12. Click Run to generate the report. Click Yes when you are prompted to replace the results.

Partial Results

13. Click on the menu bar to save the Chapter3 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-33

3.5 Filtering Data in a Task

Objectives
Filter data directly in a task.
Using various operators, build multiple filter criteria.

58

Business Scenario
The Marketing Department at Orion Star wants to run
a special promotion targeted at high-activity Orion Club
members who were born in 1970 or later.

59

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-34 Chapter 3 Getting Started w ith Tasks

Filtering Input Data


The Edit button enables you to apply filters on the input
data to select which rows should be included in the task
or wizard.

60

Edit Data and Filter Window


The Edit Data and Filter window enables you to build
multiple filters using operators and data values.

61

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-35

Filters can be built only with the available operators in the Edit Data and Filter window. More complex
filters using functions or advanced comparisons can be used in the Filter and Sort task or the Query
Builder.
Available operators are as follows:
Equal to/Not equal to
In a list/Not in a list
Less than/Less than or equal to
Greater than/Greater than or equal to
Between/Not between
Contains/Does not contain
Is missing/Is not missing

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-36 Chapter 3 Getting Started w ith Tasks

Filtering Data in a Task

The Marketing Department at Orion Star wants to run a special promotion targeted at high-activity
Orion Club members who were born in 1970 or later. Modify the List Data task to add an appropriate
filter.

1. In the Chapter3 project, double-click the customers data set in the project tree or process flow.
2. In the data grid, select Describe List Data.
3. To include only high-activity customers born in 1970 or later, begin by selecting Edit.
4. Select Customer_Type from the first drop-down list and In a list from the second drop-down list.

5. Next to the third box, click to retrieve specific values from the data. Select Add Values
Get Values to see the distinct data values in the Customer_Type column. You might need to resize
the window to see the full values. Hold down the Ctrl key and select the second and fourth values that
indicate high activity. Click OK.

6. Verify that the following values were selected and click OK:

7. To add another filter, select the drop-down box next to the data values and select AND. The AND
operator requires that both filter conditions be true for a row to be included in the report.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-37

8. Select Customer_BirthDate in the first box and Greater than or equal to in the second box. Click
to view the data values. Notice that the values are SAS dates, which are stored as the number
of days since 01JAN1960.
9. To filter based on a specific date, you can use the SAS date constant. Click Cancel to return
to the third box and enter "01JAN1970"d. SAS converts the date within quotation marks to the SAS
date equivalent before filtering the data. Click OK.
You must use the form "ddMONyyyy"d (for example, "18APR1987"d) to reference
a SAS date constant in the expressions.

10. In the Data window, add Customer_Name and Customer_Type to the List variables role
and Customer_ID to the Identifying label role.

11. Modify the title to reflect the filtered data. Select Titles in the Selection pane. Delete the default title
and enter Orion Star Customer List on the first line and High Activity Customers Born
1970 or Later on the second line.
12. Rename the task to indicate the filter that was applied. Select Properties Edit. Enter
High Act/1970+ in the Label field. Click OK.

13. Click Run and examine the final report.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-38 Chapter 3 Getting Started w ith Tasks

14. To more fully document the project to indicate the filter applied in the task, you can use notes.
Highlight the High Act/1970+ task in the project tree or process flow, click , and select Note.

15. The note can include any text to explain or document items within the project. Enter This report
includes customers in high activity groups born in 1970 or later.
16. To rename the Note icon in the project, click the Properties button and enter Filter Detail
in the Label field. Click OK.

17. Save the Chapter3 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-39

Exercises

Level 1

4. Using the List Data Task to Display San Diego Employees

a. In the Chapter3 project, add the employee_addresses data set.


If you do not have the Chapter3 project, you can create a new project.

b. Create a report with the List Data task and show the Employee_Name, Street_Number,
Street_Name, City, and Postal_Code columns. Identify each row with the Employee_ID column.

c. Modify the properties for the columns so that the report displays the following labels:
Employee ID, Name, Street Number, Street Name, City, and Postal Code.

d. Create the report.


e. Modify the List Data task so that only the employees from San Diego are included in the report.
f. Delete the City column from the report.
g. Change the title to Employee List for San Diego and delete the footnote.
h. Modify the task properties to change the task label to San Diego List.
i. Run the task and replace the results.

j. Save the Chapter3 project.


Partial Results

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-40 Chapter 3 Getting Started w ith Tasks

Level 2

5. Creating a Grouped List Report for All Employees from Australia


a. In the Chapter3 project, add the employee_addresses data set if it is not already included.
b. Create a report with the List Data task and show the Employee_ID, Employee_Name,
Street_Number, Street_Name, and Postal_Code columns.
c. Modify the properties for the columns so that the report displays the following labels:
Employee ID, Name, Street Number, Street Name, and Postal Code.
d. Generate the report.
e. Modify the List Data task so that only the employees from Australia are included in the report.

Include all variations of AU.

f. Group and identify the report by City.


g. Provide an appropriate title for the report.
h. Change the task label to AU List.
i. Rerun the report and replace the results.
j. Save the Chapter3 project.
Partial Results

Challenge

6. Creating a List Report Including a Complex Filter


The ability to filter data in tasks using the point-and-click Edit Data and Filter window is limited
to the operators provided in the drop-down lists. To create filters that include SAS functions, you can
modify the code to add a custom WHERE statement in the SAS program generated by the task.

a. In the Chapter3 project, add the employee_master SAS data set.


b. Use the List Data task to display the Employee_ID and Birth_Date columns. Format Birth_Date
and use the DATE9. format.

c. Modify the task code to insert a WHERE statement in the PROC PRINT step of the SAS program.
The WHERE statement should select only those employees with an October birthday.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-41

Hint: Use the MONTH function. Documentation about the MONTH function can be accessed
by selecting Help SAS Syntax Help. On the Index tab, enter MONTH Function.
d. Do not print the row numbers.
e. Add the title Employees with October Birthdays.
f. Change the task label to Oct Birthday List and run the task.

g. Save the Chapter3 project.


Partial Results

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-42 Chapter 3 Getting Started w ith Tasks

3.6 Creating a Graph

Objectives
Name the types of graphs that are supported
in SAS Enterprise Guide.
State the differences among the output formats
that are supported in SAS Enterprise Guide.
Create a bar chart.

67

Business Scenario
Management wants to see a comparison of average
customer age by country.

68

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-43

Graphs Using SAS Enterprise Guide

69

For more details about the graph output formats, select Help SAS Enterprise Guide Help.
Enter setting results and graph options on the Search tab and select the third returned entry.

3.08 Multiple Answer Poll


Select Tasks Graph to see the available graphs.
Which types of graphs would you like to use to display
your data?
a. bar chart
b. pie chart
c. line plot
d. scatter plot
e. surface plot
f. map
g. other

70

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-44 Chapter 3 Getting Started w ith Tasks

Bar Chart Wizard


The Bar Chart Wizard enables you to do the following:
1. select and filter the data
2. assign variables to roles
3. customize appearance
4. set titles and footnotes

71

Bar Chart: Advanced View


To make further enhancements to the graph, you might
need to open the task in Advanced View. This action
gives you access to additional options that are not
available in the wizard.
After you run a task in Advanced View, you cannot return
to the wizard.

72

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-45

Bar Chart Task: Advanced View


The Advanced View of the Bar Chart task includes
additional options, such as changing the bar shape,
formatting data values, and modifying reference lines.

73

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-46 Chapter 3 Getting Started w ith Tasks

Creating a Bar Chart

To better understand the demographics of the Orion Star customers, management wants to see
a comparison of average customer age by country. Use the Bar Chart Wizard and task to create the result.

1. In the Chapter3 project, highlight the customers data set in the project tree or process flow.
Select Tasks Graph Bar Chart Wizard.

2. In Step 1, verify that customers is the active data set. Click Next.
3. In Step 2, select the Horizontal bar chart check box. To create a separate bar for each country,
select Customer_Country in the Bars drop-down list.

4. To order the bars in descending height or length, click . In the Properties window,
select Descending bar height OK.

5. To set the length of the bars based on average age, select Customer_Age from the Bar length
drop-down list.

6. Click , change the statistic to Average, and click OK. Click Next.

7. In Step 3, make the following changes:


a. Select the 3D chart check box.
b. In the Color bars by drop-down list, select Bar category.
c. Select the Data labels check box and select Average from the drop-down list.
d. Select the Use reference lines check box.
e. Click Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-47

8. In Step 4, change the title to Average Customer Age by Country and click Finish.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-48 Chapter 3 Getting Started w ith Tasks

9. To make additional modifications not allowed in the Bar Chart Wizard, open the task in Advanced
View. Right-click the Bar Chart icon in the project tree or process flow. Select Open
Open in Advanced View.

10. In Advanced View, you can apply formats to variables to modify the appearance. Select Data
in the Selection pane. To format Customer_Age so that the data labels are rounded to one decimal
place, right-click Customer_Age and select Properties.

11. Select Change to apply a format. In the Formats window, select Numeric from the Categories pane
and w.d from the Formats pane. Change the overall width to 4 and the decimal places to 1.
Click OK OK to return to the task dialog box.
12. Select Layout in the Selection pane. Change the shape to Cylinder.
13. Select Horizontal Axis in the Selection pane. Enter Average Customer Age in the Label box
and change the font size to 12.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-49

14. Select Reference Lines in the Selection pane. Click the Specify values for lines check box, enter 20,
and then select Add. Repeat for 40 and 60. Change the style to Dashed and the color to light gray.

15. Select Vertical Axis in the Selection pane. Enter Country in the Label box.
16. Select Properties in the Selection pane and select Edit. In the General pane, change the task label
to Avg Age/Country.

17. The default graph format is ActiveX. To be able to interact with the graph after the task runs, it must
be in HTML format. In the Results pane, select Customize result formats, styles, and behavior
and select HTML. Click OK.
18. Click Run to generate the graph and select Yes when you are prompted to replace the results.
Click the Results - HTML tab. To access the ActiveX functionality that enables further exploration
and modification of the graph, right-click on the graph and select Graph Properties.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-50 Chapter 3 Getting Started w ith Tasks

19. On the Graph tab, change the style to Curve and a new color scheme is applied.
20. Click the Bar tab and select Font. Increase the data label font size to 10. Click OK OK
to return to the graph and apply the changes.
21. Another change that can be made is to switch the chart type. Right-click on the graph and select
Chart Type Vertical Bar.

22. A toolbar is also available to resize, rotate, and subset the graph. Right-click on the graph and select
Graph Toolbar. Click and use the mouse to drag the cursor across the top three bars. The chart
is redrawn to include only the outlined portion. Click to reset the graph.

23. To save the graph, you can save the image as a JPEG file (saves any interactive changes that you
made as a static image) or you can export the graph as an HTML file. (Interactivity is preserved
but changes that you made interactively are lost.) To export the HTML result, select Export
Export HTML - Avg Age/Country. Navigate to the desired location and select Save.

Graphs can also be copied and pasted into Microsoft Word, Excel, and PowerPoint.
Right-click on the graph in Enterprise Guide, and select Copy. Then right-click
in Word, Excel, or PowerPoint, and select Paste.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-51

To maintain ActiveX interactivity in these applications, consider the following:


Microsoft Excel: The graph automatically retains the ActiveX functionality.
Microsoft Word: After the graph is pasted into a document, you must exit Design Mode.
This can be done in Office 2007 or later by selecting Developer Design Mode.
Microsoft PowerPoint: To be able to interact with the ActiveX graph while in View mode
in PowerPoint, you must first change a graph property before copying and pasting the
graph. Right-click on the graph in Enterprise Guide and selecting Graph Properties.
On the Graph tab, select Advanced. In the Advanced Settings window, click the Display
interactive graphs check box. After you modify the graph properties, copy and paste
the graph into PowerPoint.
24. Save the Chapter3 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-52 Chapter 3 Getting Started w ith Tasks

Exercises

Level 1

7. Creating a Three-Dimensional Vertical Bar Chart for Salary by City


a. In the Chapter3 project, add the employee_detail SAS data set.

If you do not have the Chapter3 project, you can start a new project.

b. Open the employee_detail table in the data grid and open the Bar Chart Wizard. In Step 2
of the Bar Chart Wizard, create a vertical bar chart that shows the sum of Salary for each city.
Arrange the bars in descending height.

c. In Step 3 of the Bar Chart Wizard, change the following attributes:


Create a three-dimensional chart.
Color each bar differently.
Print data labels at the top of each bar with the sum of Salary.
Label the bar height (vertical) axis as Total Salary.
Turn on reference lines.

d. In Step 4 of the Bar Chart Wizard, name the graph Total Salary for Each City.
e. Create the graph.
f. Right-click the Bar Chart task in the project tree or process flow. Select Open
Open in Advanced View. Make the following modifications:
Modify the format applied to Salary so that you round values to the nearest dollar.
Change the bar shape to a prism.
Change the reference lines to dashed and light gray.
g. Modify the properties of the Bar Chart task to create an HTML report along with the default
SAS Report format.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-53

h. Run the task and replace the results. Save the project as Chapter3.

Level 2

8. Using the Pie Chart Wizard to Analyze Salary by Department


a. In the Chapter3 project, add the employee_detail SAS data set if necessary.
b. Use the Pie Chart Wizard to generate a graph where the slices represent the sum of Salary
for each department.
c. Show the department name and salary total outside each slice, and the percentage of total salary
on the inside of each slice. Make the chart three-dimensional. Generate the graph.
d. Change the title to Total Salary by Department and run the task.
e. Open the task in Advanced View to apply an appropriate format that rounds the display of Salary
to the nearest dollar. Create the graph in HTML as well as in SAS Report format.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-54 Chapter 3 Getting Started w ith Tasks

f. Run the task and save the Chapter3 project.

You might see an exclamation point on the task icon. This indicates that there is a
warning in the log. Examine the log to determine whether the warning affects the output.

Challenge
9. Modifying the Pie Chart Task Code to Isolate a Slice
a. Complete the Level 2 exercise to generate a pie chart that illustrates total salary by department.
b. Modify the Pie Chart task to slightly separate the Sales slice from the remainder of the pie.
This can be done by inserting the explode="Sales" option at the end of the PIE3D statement.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-55

c. Run the task and replace the results. Save the Chapter3 project.

You might see an exclamation point on the task icon. This indicates that there is a
warning in the log. Examine the log to determine whether the warning affects the output.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-56 Chapter 3 Getting Started w ith Tasks

3.7 Solutions
Solutions to Exercises
1. Using the One-Way Frequencies Task to Generate Frequency Counts and Percentages
a. In the Chapter3 project, add the employee_organization data set.
If you do not have Chapter3 project, you can create a new project.

1) Select File Open Data and navigate to the location of the course data.
2) Select employee_organization Open.
b. Use the One-Way Frequencies task to generate a report that analyzes the Department column.
1) If necessary, double-click the employee_organization icon in the project tree or process flow
to open it in the data grid.

2) To open the One-Way Frequencies task, select Describe One-Way Frequencies


from the task menu bar.

3) In the Data selection pane of the One-Way Frequencies task dialog box, drag and drop
Department to the Analysis variables role.

c. Include a horizontal bar chart as part of the report.


1) Select Plots in the Selection pane.
2) Select Horizontal.
d. Add the title Employee Counts by Department and delete the footnote.
1) Select Titles in the Selection pane.
2) Select Analysis and clear the Use default text check box.
3) Delete the current text and enter Employee Count by Department.
4) Select Footnote in the Selection pane and clear the Use default text check box.
Delete the default text.

e. Modify the task properties to change the task label to Dept Freq Report.
1) Select Properties in the Selection pane.
2) Select Edit.
3) Delete the text in the Label field and enter Dept Freq Report.
4) Click OK.
f. Generate the report and examine the results.
1) Click Run.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-57

2) If necessary, click the Results tab to view the report.


g. Modify the One-Way Frequencies task to display only frequencies and percentages.
Rerun the report and replace the results.
1) Select Modify task from the Results tab to reopen the One-Way Frequencies task.
2) Select Statistics in the Selection pane and select the Frequencies and Percentages
radio button in the Frequency Table options pane.
3) Click Run.
4) Click Yes when you are prompted to replace the results.
h. Save the Chapter3 project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.

Partial Results (graph not shown)

Final results assume that the Include SAS procedure titles in results option is turned
off. You can modify this option by selecting Tools Options Tasks General.
2. Using the One-Way Frequencies Task to Produce a Grouped Report
a. In the Chapter3 project, add the employee_organization data set if it is not already included.
1) Select File Open Data and navigate to the location of the course data.
2) Select employee_organization Open.

b. Use the One-Way Frequencies task to analyze Job_Title, grouped by Department. Include only
frequencies and percentages.
1) If necessary, double-click the employee_organization icon in the project tree or process flow
to open it in the data grid.
2) To open the One-Way Frequencies task, select Describe One-Way Frequencies from
the data grid.
3) In the Data window, assign Job_Title to the Analysis variables role and Department
to the Group analysis by role.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-58 Chapter 3 Getting Started w ith Tasks

4) Select Statistics in the Selection pane and select the Frequencies and Percentages
radio button in the Frequency Table options pane.
c. Order the output report by descending frequencies.
Scroll down in the Results window to find the Order output data by option.

1) Select Results in the Selection pane.


2) Scroll to the bottom and change the Order output data by option to Descending frequencies.
d. Add the title Employees by Job Title and delete the footnote.

1) Select Titles in the Selection pane.


2) Select Analysis and clear the Use default text check box.
3) Delete the default text and enter Employees by Job Title as the title.
4) Select Footnote in the Selection pane. Clear the Use default text check box.
Delete the default text.

e. Change the task label to Jobs by Dept Freq Report and run the task.
1) Select Properties in the Selection pane.
2) Select Edit.
3) Delete the text in the Label field and enter Jobs by Dept Freq Report.
4) Click OK.
5) Click Run to generate the report.
f. Save the Chapter3 project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-59

Partial Results

3. Producing a Grouped Frequency Report with Group Values in the Titles


a. Complete the Level 2 exercise and continue with the next steps.
b. Modify the Jobs by Dept Freq Report task. Change the title to Employees by Job Title in
#byval(department) Department. This syntax places the name of each distinct group in the title.
Documentation about the #BYVAL(variable) syntax can be found by selecting Help
SAS on the Web SAS Product Documentation. Search for #BYVAL.
1) On the Results tab of the One-Way Frequencies task created in the Level 2 exercise,
select Modify Task.
2) Select Titles in the Selection pane.
3) Change the title to Employees by Job Title in #byval(department) Department.
c. Access the code in the One-Way Frequencies task by selecting Preview Code. Select the
Show custom insertion points check box.

1) In the lower left part of the task dialog box, click the Preview code button to open the
Code Preview for Task window.

2) In the upper left part of this window, select the Show custom insertion points check box.
d. To remove the secondary BYLINE title, add the following statement at the earliest point
of insertion in the task code:
options nobyline;

Documentation about the BYLINE and NOBYLINE system options can be found
by selecting Help SAS Syntax Help. On the Index tab, enter byline.
1) Click on the first line that indicates <insert custom code here>.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-60 Chapter 3 Getting Started w ith Tasks

2) Enter the following SAS OPTIONS statement:


options nobyline;
e. To reinstate the secondary BYLINE title for future tasks, add the following statement at the end
of the task code:
options byline;
1) Click on the last line that indicates <insert custom code here>.

2) Enter the following SAS OPTIONS statement:


options byline;

3) Close the Code Preview for Task window by clicking in the upper right corner.

f. Create the modified report and replace the results.


Click Run Yes when you are prompted to replace the results.
g. Save the Chapter3 project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.

Partial Results

4. Using the List Data Task to Display San Diego Employees


a. In the Chapter3 project, add the employee_addresses data set.
If you do not have the Chapter3 project, you can create a new project.

1) Select File Open Data and navigate to the location of the course data.
2) Select employee_addresses Open.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-61

b. Create a report with the List Data task and show the Employee_Name, Street_Number,
Street_Name, City, and Postal_Code columns. Identify each row with the Employee_ID column.
1) If necessary, double-click the employee_addresses data set in the project tree or process flow
to open it in the data grid.
2) In the data grid, select Describe List Data.
3) In the Data window, hold down the Ctrl key and select Employee_Name, Street_Number,
Street_Name, City, and Postal_Code. Move them to the List variables role.
4) Drag Employee_ID to the Identifying label role.
c. Modify the properties for the columns so that the report displays the following labels:
Employee ID, Name, Street Number, Street Name, City, and Postal Code.
1) Right-click on each of the variable names and select Properties.
2) In the Properties window, enter the appropriate text in the Label field.
3) In the Task roles pane, right-click and select Show Labels to display the labels.
d. Create the report.
Select Run and view the report.
e. Modify the List Data task so that only the employees from San Diego are included in the report.
1) In the data grid, select Modify Task to reopen the List Data task.

2) Select Edit to open the Edit Data and Filter window.


3) Using the first drop-down box in the Task filter, select City.
4) In the second drop-down box, select Equal to as the operator.
5) In the third box, click . Select San Diego OK.

6) Click OK to close the Edit Data and Filter window.


f. Delete the City column from the report.
In the Task roles pane, select City and drag it back to the Variables to assign pane.
g. Change the title to Employee List for San Diego and delete the footnote.
1) Select Titles in the Selection pane.
2) Clear the Use default text check box and delete the default text.
3) Enter Employee List for San Diego.
4) Select Footnote and clear the Use default text check box. Delete the default text.

h. Modify the task properties to change the task label to San Diego List.
1) Select Properties in the Selection pane.
2) Select Edit and enter San Diego List in the Label field.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-62 Chapter 3 Getting Started w ith Tasks

3) Click OK.

i. Run the task and replace the results.


Select Run Yes when you are prompted to replace the results.
j. Save the Chapter3 project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.
Partial Results

5. Creating a Grouped List Report for All Employees from Australia


a. In the Chapter3 project, add the employee_addresses data set if it is not already included.
1) Select File Open Data and navigate to the location of the course data.
2) Select employee_addresses Open.
b. Create a report with the List Data task and show the Employee_ID, Employee_Name,
Street_Number, Street_Name, and Postal_Code columns.
1) If necessary, double-click the employee_addresses data set in the project tree or process flow
to open it in the data grid.

2) In the Data menu bar, select Describe List Data.


3) In the Data selection pane, select Employee_ID, Employee_Name, Street_Number,
Street_Name, and Postal_Code. Move them to the List variables role.

c. Modify the properties for the columns so that the report displays the following labels:
Employee ID, Name, Street Number, Street Name, and Postal Code.

1) Right-click on each of the variable names and select Properties.


2) In the Properties window, enter the appropriate text in the Label field.
3) In the Task roles pane, right-click and select Show Labels to display the labels.
d. Generate the report.
Click Run.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-63

e. Modify the List Data task so that only the employees from Australia are included in the report.

Include all variations of AU.

1) On the Results tab, select Modify Task to reopen the List Data task.
2) Select Edit to open the Edit Data and Filter window.
3) Using the first drop-down box in the Task filter, select Country.
4) In the second drop-down box, select In a list as the operator.
5) In the third box, click . Then select Add Values Get Values. Select au on the
Values tab, and click OK. Select AddValues a second time. Select AU OK.
6) Click OK to close the window.
7) Click OK to close the Edit Data and Filter window.

f. Group and identify the report by City.


1) Assign City to the Group analysis by role.
2) Also assign City to the Identifying label role.
g. Provide an appropriate title for the report.
1) Select Titles in the Selection pane.
2) Clear the Use default text check box, delete the default text, and enter
Employee List for Australia.

h. Change the task label to AU List.


1) Select Properties in the Selection pane.
2) Select Edit and enter AU List in the Label field.
3) Click OK to close the Properties window.
i. Rerun the report and replace the results.
Click Run Yes.
j. Save the Chapter3 project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-64 Chapter 3 Getting Started w ith Tasks

Partial Results

6. Creating a List Report Including a Complex Filter


The ability to filter data in tasks using the point-and-click Edit Data and Filter window is limited
to the operators provided in the drop-down lists. To create filters that include SAS functions, you can
modify the code to add a custom WHERE statement in the SAS program generated by the task.

a. In the Chapter3 project, add the employee_master SAS data set.


1) Select File Open Data and navigate to the location of the course data.
2) Select employee_master Open.
b. Use the List Data task to display the Employee_ID and Birth_Date columns. Format Birth_Date
and use the DATE9. format.

1) If necessary, double-click the employee_master data set in the project tree or process flow to
open it in the data grid.
2) In the data grid, select Describe List Data to open the List Data task dialog box.
3) In the Data selection pane, select Employee_ID and Birth_Date and assign them to the
List variables task role.

4) Right-click the Birth_Date column and select Properties.


5) In the Properties window, select Change.
6) In the Format window, change the overall width to 9.
7) Click OK OK to return to the task dialog box.
c. Modify the task code to insert a WHERE statement in the PROC PRINT step of the SAS program.
The WHERE statement should select only those employees with an October birthday.

Hint: Use the MONTH function. Documentation about the MONTH function can be accessed
by selecting Help SAS Syntax Help. On the Index tab, enter MONTH Function.

1) In the List Data task dialog box, click the Preview Code button to open the Code Preview
for Task window.

2) Select the Show custom code insertion points check box.


3) Click in the insertion point immediately below the FORMAT statement
and above the RUN statement for PROC PRINT.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-65

4) In the Enter User code window, enter the following SAS statement:

where month(Birth_Date) = 10;

5) Click to close the Code Preview for Task window.

d. Do not print the row numbers.


1) Select Options in the Selection pane.
2) Clear the Print the row number check box.
e. Add the title Employees with October Birthdays.

1) Select Titles in the Selection pane.


2) Clear the Use default text check box and delete the default text.
3) Enter Employees with October Birthdays.
f. Change the task label to Oct Birthday List and run the task.
1) Select Properties in the Selection pane.
2) Click Edit and enter Oct Birthday List in the Label field.
3) Click OK to close the Properties window.
4) Click Run and view the report.
g. Save the Chapter3 project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.

Partial Results

7. Creating a Three-Dimensional Vertical Bar Chart for Salary by City


a. In the Chapter3 project, add the employee_detail SAS data set.

If you do not have the Chapter3 project, you can start a new project.

1) Select File Open Data and navigate to the location of the course data.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-66 Chapter 3 Getting Started w ith Tasks

2) Select employee_detail Open.


b. Open the employee_detail table in the data grid and open the Bar Chart Wizard. In Step 2 of the
Bar Chart Wizard, create a vertical bar chart that shows the sum of Salary for each city. Arrange
the bars in descending height.
1) If necessary, double-click the employee_detail data set in the project tree or process flow to
open it in the data grid.
2) In the data grid, select Graph Bar Chart Wizard.
3) In Step 1, confirm that the data set is employee_detail and click Next.
4) In Step 2, change the Bars drop-down list value to City.
5) Click and select Descending bar height OK.

6) Change the Bar height drop-down list value to Salary.


7) Click Next.
c. In Step 3 of the Bar Chart Wizard, change the following attributes:
Create a three-dimensional chart.
Color each bar differently.
Print data labels at the top of each bar with the sum of Salary.
Label the bar height (vertical) axis as Total Salary.
Turn on reference lines.

1) In Step 3 of the wizard, select the 3D chart check box.


2) Change the Color bars by field to Bar category.
3) Select the Data labels check box and select Sum in the drop-down menu.
4) Click the Axis Labels button and enter Total Salary in the Bar height field. Click OK
to close the Axis labels window.

5) Select the Use reference lines check box.


6) Click Next.
d. In Step 4 of the Bar Chart Wizard, name the graph Total Salary for Each City.
In the Graph field, enter Total Salary for Each City.
e. Create the graph.
Click Finish.
f. Right-click the Bar Chart task in the project tree or process flow. Select Open
Open in Advanced View. Make the following modifications:
Modify the format applied to Salary so that you round the values to the nearest dollar.
Change the bar shape to a prism.
Change the reference lines to dashed and light gray.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-67

1) Right-click the Bar Chart task icon, and select Open Open in Advanced View
to open the Bar Chart task dialog box.
2) Select Data in the Selection pane.
3) Right-click Salary and select Properties Change.
4) Verify that the format is DOLLARw.d and change the decimal places to 0. Click OK OK
to return to the task dialog box.
5) Select Layout in the Selection pane.
6) Change the shape to Prism.
7) Select Reference Lines in the Selection pane.
8) Change the style to Dashed and the color to light gray.
g. Modify the properties of the Bar Chart task to create an HTML report along with the default
SAS Report format.
1) Select Properties in the Selection pane and select Edit.

2) Select Results in the Selection pane.


3) Select the Customize result formats, styles, and behavior radio button.
4) Click the HTML check box and click OK.
h. Run the task and replace the results. Save the project as Chapter3.
1) Click Run Yes when you are prompted to replace the results.
2) Click on the toolbar.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-68 Chapter 3 Getting Started w ith Tasks

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.

8. Using the Pie Chart Wizard to Analyze Salary by Department


a. In the Chapter3 project, add the employee_detail SAS data set to the project if necessary.
1) Select File Open Data and navigate to the location of the course data.
2) Select employee_detail Open.
b. Use the Pie Chart Wizard to generate a graph where the slices represent the sum of Salary
for each department.

1) If necessary, double-click the employee_detail data set in the project tree or process flow
to open it in the data grid.

2) In the data grid, select Graph Pie Chart Wizard.


3) In Step 1, verify that the data set is employee_detail and click Next.
4) In Step 2, select Department as the slice value and Salary as the slice size value.
5) Click and verify that the selected statistic is Sum.

6) Click Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-69

c. Show the department name and salary total outside each slice, and the percentage of total salary
on the inside of each slice. Make the chart three-dimensional. Generate the graph.
1) In Step 3, select the 3D chart check box.
2) Select the Percentage check box and change the drop-down list value to Inside.
3) Click Next.

d. Change the title to Total Salary by Department and run the task.
1) In Step 4, enter Total Salary by Department in the Graph field.
2) Click Finish.
e. Open the task in Advanced View to apply an appropriate format that rounds the display of Salary
to the nearest dollar. Create the graph in HTML as well as in SAS Report format.

1) In the project tree or process flow, right-click the Pie Chart task and select
Open Open in Advanced View.
2) Select Data in the Selection pane.

3) Right-click Salary and select Properties Change.


4) Verify that the format is DOLLARw.d and change the decimal places to 0. Click OK OK
to return to the task dialog box.
5) Select Properties in the Selection pane and select Edit.

6) Select Results in the Selection pane.


7) Select the Customize result formats, styles, and behavior radio button.
8) Select the HTML check box and click OK.
f. Run the task and save the Chapter3 project.

You might see an exclamation point on the task icon. This indicates that there is a
warning in the log. Examine the log to determine whether the warning affects the output.
1) Click Run Yes when you are prompted to replace the results.
2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.
4) To view the log, click the Log tab. Scroll down to find the following message:
WARNING: Text boundaries for the pie/donut slices overlap.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-70 Chapter 3 Getting Started w ith Tasks

9. Modifying the Pie Chart Task Code to Isolate a Slice


a. Complete the Level 2 exercise to generate a pie chart that illustrates total salary by department.
See the solutions to the previous exercise.
b. Modify the Pie Chart task to slightly separate the Sales slice from the remainder of the pie.
This can be done by inserting the explode="Sales" option at the end of the PIE3D statement.
1) On the Results tab of the Pie Chart task, select Modify Task.
2) Click Preview Code and select the Show custom code insertion points check box.
3) Click to insert code before the semicolon that closes the PIE3D statement. This location is
immediately after the NOHEADING option and before the FORMAT statement.
4) Enter the following option:
explode="Sales"

Sales is case sensitive.

5) Close the Code Preview for Task window.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-71

c. Run the task and replace the results. Save the Chapter3 project.

You might see an exclamation point on the task icon. This indicates that there is a
warning in the log. Examine the log to determine whether the warning affects the output.

1) Click Run Yes when you are prompted to replace the results.
2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter3 in the File name field and select Save.
4) To view the log, click the Log tab. Scroll down to find the following message:
WARNING: Text boundaries for the pie/donut slices overlap.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-72 Chapter 3 Getting Started w ith Tasks

Solutions to Student Activities (Quizzes/Polls)

3.02 Quiz Correct Answer


Which column attributes can you modify?

Label and Format

13

3.03 Multiple Choice Poll Correct Answer


Highlight any data source in the project and select
Tasks Describe One-Way Frequencies.
Which task role requires a variable assignment?
a. Analysis variables
b. Frequency count
c. Group analysis by

25

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-73

3.04 Multiple Choice Poll Correct Answer


What would be the frequency value for Children Sports if
Units_in_Stock is assigned to the Frequency count role?
a. 3
b. 25
c. 50
d. 70
Units_in
Product_Name Product_Category
_Stock
Childrens Mitten Children Sports 25

Sunf it Swimming Trunks Children Sports 15


Product_
Frequency
Osprey Ny lon Shorts Children Sports 10 Category
Liga Football Boot Shoes 5 Children
50
Sports
Py tossage Bathing Sandal Shoes 15
Shoes 20

30

3.06 Quiz Correct Answer


What are some advantages of each format?
SAS Report format is useful when you combine
task results or create reports to be viewed
in other SAS applications.
HTML can be easily viewed by anyone who has
a browser.
RTF can be included and edited in common
word processors.
PDF is a good choice for printing and sharing
static copies of the report.
Text is simple and familiar if you use
the SAS windowing environment.

43

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-74 Chapter 3 Getting Started w ith Tasks

3.07 Quiz Correct Answer


Confirm the results. Results might be different if you used
the One-Way Frequencies task results from the Level 2
or Level 3 exercise.

50

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 4 Creating Simple Queries

4.1 Filtering and Sorting Data ......................................................................................... 4-3


Demonstration: Selecting Columns and Filtering Rows ................................................. 4-9
Exercises............................................................................................................. 4-20

4.2 Creating New Columns with an Expression ........................................................... 4-24


Demonstration: Creating a Column with an Expression .............................................. 4-28

Exercises............................................................................................................. 4-31

4.3 Grouping and Summarizing Data in a Query .......................................................... 4-34


Demonstration: Summarizing and Filtering by Groups ................................................ 4-38

Exercises............................................................................................................. 4-40

4.4 Joining Tables ......................................................................................................... 4-43


Demonstration: Joining Tables ................................................................................ 4-48
Exercises............................................................................................................. 4-51

4.5 Solutions ................................................................................................................. 4-54


Solutions to Exercises ........................................................................................... 4-54
Solutions to Student Activities (Polls/Quizzes) ........................................................... 4-76
4-2 Chapter 4 Creating Simple Queries

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-3

4.1 Filtering and Sorting Data

Objectives
State the functions of the Filter and Sort task,
the Query Builder, and the Data Explorer.
Compare the functionality that is available in each
task.
Apply a filter in a query.
Exclude columns in a query.
Reorder rows in a query.

Manipulating Data
Often, you need to manipulate your data before you use
it in a task. For example, you might want to analyze a
subset of the rows or columns, compute a new column,
or combine the data found in two or more tables.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-4 Chapter 4 Creating Simple Queries

Querying Data
Three tools are available in Enterprise Guide to
manipulate or query your data and create a new data
source.
Query Builder
Filter and Sort task
Data Explorer

A query is a collection of specifications that enables you to focus on a particular set of data.
The Filter and Sort task and the Query Builder can be used to build these query specifications .

Behind the scenes, the Filter and Sort task and the Query Builder generate Structured Query Language
(SQL) code.

The Data Explorer can also be used to create a query in Enterprise Guide.

4.01 Multiple Answer Poll


Double-click on any data source in your project.
Select Filter and Sort and explore the available tabs.
What functionality do you think is supported by this task?
a. subsetting rows
b. selecting columns
c. calculating new columns
d. controlling the sort order of the rows
e. summarizing data
f. creating a SAS data set

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-5

Filter and Sort Task


The Filter and Sort task enables you to create a new SAS
table by selecting rows, columns, and a sort sequence.

4.02 Quiz
Close the Filter and Sort task and return to the data grid.
Select Query Builder. What options appear to be
available that are not present in the Filter and Sort task?

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-6 Chapter 4 Creating Simple Queries

Query Builder
The Query Builder provides similar tabs for selecting
columns, filtering rows, and sorting data. Additional
functionality is available, including the following:
modifying column
properties
grouping and
summarizing data
applying formats
selecting distinct
rows
joining tables

11

The Query Builder also enables you to create SAS views and reports. For more details, select
Help SAS Enterprise Guide Help. Then enter query output on the Search tab. Select
the second topic that is returned in the list, that is, Setting Options for the Current Query.

Business Scenario
Orion Star wants to analyze Internet sales since 2013.
To prepare the data for input to the various analytic tasks,
the company must generate a new data source from
the orders table.
Orders
Internet sales
since 2013

12

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-7

Business Scenario
Preparing the new data set requires only filtering
and sorting, so any of the query tools can be used.

13

The Filter tab builds an SQL WHERE clause that looks at every row of data and returns only those rows
that satisfy the filter conditions.

When you create more than one filter on your data, you can specify whether the relationship between
the filters is AND or OR.
AND returns rows of data only when all the expressions connected by an AND are true. OR returns data
rows when at least one of the expressions connected by an OR is true. Whether you use AND or OR,
if none of the expressions is true, no rows of data are returned.

If you enter data values in the third field, remember that character values are case sensitive
(for example, "CA" "Ca").

Clicking in the third field returns a maximum of 250 unique data values from the column in the first
field. If you want Enterprise Guide to return the next 250 unique data values, select More Values. Each
time you select More Values, the next set of distinct values for the variable is displayed in addition
to the initial values. The number of values that are retrieved each time is specified by the number of
distinct column values that you have for each request option that is found in Tools Options.

Comparison operators that are available in the Edit Filter Condition dialog box include the standard
comparison operators, as well as the following operators:
Is equal to an item in the list.
IN (a list of values)
Example: category in ("BREAD","MEAT")
Evaluates an inclusive range.
BETWEEN
Example: income between 60000 and 80000
IS MISSING Performs a test for missing values.
Contains a string.
CONTAINS Example: country contains "US"
matches "USA", "RUSSIA"

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-8 Chapter 4 Creating Simple Queries

In the Advanced Filter Builder, you can build your expression using constant values, columns,
mathematical operators, and functions. You can use the Advanced Filter Builder to add these elements,
or you can enter them into the Expression box at the top of the Advanced Expression Editor.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-9

Selecting Columns and Filtering Rows

Orion Star would like to analyze Internet sales that occurred since the beginning of 2013. To prepare
the data for input to the various analytic tasks, the company must generate a new subset from the orders
table. This query can be created with either the Filter and Sort task or the Query Builder.
1. Create a new project and add the orders SAS data set.
2. To create the new data set that includes Internet orders placed on or after 01JAN2013, begin
by clicking the Filter and Sort tab on the data grid.

You can also right-click orders in the project tree or process flow, and select Filter and Sort.
3. On the Variables tab, click to add all columns. All Internet orders have the Employee_ID
column equal to 99999999, so it can be removed from the result. Highlight Employee_ID in the
Selected pane and click .

4. Click the Filter tab. Define the two filters shown in the display below.

Order_Type is a coded column where 1 represents retail sales, 2 represents catalog sales,
and 3 represents Internet sales.
SAS dates are stored as the number of days since 01JAN1960. To build a filter based
on a specific date, you can either select a particular date from the data by clicking
or you can enter a SAS date constant. A SAS date constant must be entered in this form:
"DDMONYYYY"d. For example, January 1, 2013 would be entered as "01JAN2013"d.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-10 Chapter 4 Creating Simple Queries

5. Click the Sort tab. Select Order_Date as the sort variable and change the sort sequence
to Descending.
6. Click the Results tab. Enter Internet Orders 2013+ in the Task name field. Click Change
and enter internetorders2013 in the File name field. Select Save.

7. Click OK and verify the results. This data source is a SAS table that can be exported or used as input
for other tasks.

Partial Results (8 of 55 rows, 5 of 12 columns)

8. The Query Builder can also be used to produce a similar result. To compare the two tasks,
double-click the orders table in the project. Select Query Builder from the data grid.

You can also right-click orders in the project and select Query Builder.

9. The Query Builder enables you to name the query icon and the name and storage location
of the SAS table that you created. Enter Internet Orders 2013+ Query in the Query name field.
Click Change next to the Output name field. Enter internet2013query in the File name field
and select Save.

The table is saved to the default SAS library. However, a different library can be selected
if it is available.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-11

10. To select all columns, select t1 (orders) in the Selection pane and drag and drop it onto the Select
Data tab. All columns are added to the query. Remove the Employee_ID column by highlighting
it on the Select Data tab and clicking .
Columns can be added individually either by double-clicking or by dragging and dropping.
Multiple columns can be selected by holding down the Ctrl key. You can use the Shift key
to select a range of columns.

11. Column properties can also be viewed or modified on the Select Data tab. Highlight Order_Date
and click to view the Properties window.

You can also double-click on a column to access the Properties window.

12. To apply a format to this column, select Change. In the Formats window, select Date from
the Categories pane and MMDDYYw.d from the Formats pane. Change the overall width
to 10. Click OK OK to return to the Query Builder.

13. To include only Internet orders placed on or after 01JAN2013, click the Filter Data tab.
Drag and drop Order_Type to the Filter Data tab to start the Basic Filter Wizard.
You can also click and select Basic Filter.

14. In Step 1, change the operator to Equal to and enter 3 in the Value field.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-12 Chapter 4 Creating Simple Queries

15. Click Next to verify the filter and click Finish.


16. Drag Order_Date to the Filter Data tab. In Step 1, change the operator to Greater than or equal
to and enter "01JAN2013"d in the Value field.

17. Click Next to verify the filter and click Finish.


The two filters are automatically connected by an AND operator.

18. Click the Sort Data tab. Drag and drop Order_Date onto the Sort Data tab and change the sort
direction to Descending.

19. Click Run to execute the query and view the resulting SAS table.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-13

Partial Results (8 of 55 rows, 6 of 12 columns)

20. Save the project as Chapter4.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-14 Chapter 4 Creating Simple Queries

Data Explorer
The Data Explorer provides an alternative way to
interactively filter and sort data, and build a Query task
in the project.

15

Data Exploration Pane


The Data Exploration pane enables you to do the
following:
select columns
filter rows
sort rows
view data properties
examine quick statistics

16

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-15

Data Explorer
Pending updates are queued and not applied until you
click Apply Updates. A new view of the data is then
created.

17

4.03 Quiz
1. Select File Open Data Exploration.
2. Double-click <servername> Libraries SASHELP
Cars to open the data source in the Data Explorer.
3. Click Edit next to Selected Columns. Add Make,
Model, Type, MSRP, MPG_City, and MPG_Highway
to the Selected columns pane.
4. Click Add to Pending Updates.

18
continued...

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-16 Chapter 4 Creating Simple Queries

4.03 Quiz
5. Click Edit next to Filter Conditions.
6. Select Make in the first drop-down list.
7. Click the Define condition below field and select
Click to load values. Select the Acura and Honda
check boxes.
8. Click Add to Pending Updates.

19
continued...

4.03 Quiz
9. Click Edit next to Sort Order.
10. Add Make and MSRP to the Selected columns pane.
Change the direction for MSRP to Descending.
11. Click Add to Pending Updates.
12. Click Apply Updates to generate the new data view.

20

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-17

Adding Exploration to the Process Flow


A Query task can be added to the process flow with
the instructions to filter and sort the data.

22

Managing Explorations
Use the Data Exploration History in the Resources pane
to access and manage explorations.

23

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-18 Chapter 4 Creating Simple Queries

Setup for the Poll


1. Access the Data Exploration
History in the Resources pane.
Double-click the CARS exploration
to reopen it if necessary.
2. Select the Click to run all
statistics link.
3. Click on the generated graph
and report thumbnails to examine
the Quick Stats results.

24

4.04 Multiple Answer Poll


What are the top two distinct values for Type?
a. Hybrid
b. SUV
c. Sedan
d. Sports
e. Truck
f. Wagon

25

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-19

4.05 Multiple Choice Poll


What is the average MPG_Highway?
a. 31.7
b. 25.3
c. 28.9
d. 30.5

27

Query Tools Comparison


Filter Query Data
and Sort Builder Explorer

Sort data

Filter row s and colum ns

Create a new SAS data set

Define new colum ns

Join tables

Group and sum m arize data

Define colum n attributes

Rem ove duplicates

Calculate Quick Stats

29

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-20 Chapter 4 Creating Simple Queries

Exercises

Level 1

1. Creating a New Table in the Filter and Sort Task with a Basic Filter
Use the Filter and Sort task to create a new table with San Diego employees sorted in postal code order.
a. In the Chapter4 project, add the employee_addresses data set.

If you do not have the Chapter4 project, you can create a new project.

b. Using the Filter and Sort task, create a new table for the San Diego office manager. This table
should include Employee_ID, Employee_Name, Street_Number, Street_Name, and Postal_Code.

c. Create a filter to include only employees from San Diego in the output table.
d. Order the output table in ascending postal code order.
e. Name the task and output table SanDiegoEmployees.
f. Submit the task to create the new table.
Partial Results (8 of 112 rows)

g. Save the Chapter4 project.


2. Creating a New Table in the Query Builder with a Basic Filter
Use the Query Builder to create a new table that includes all employees with the word Sales in their
job titles.
a. In the Chapter4 project, add the employee_organization data set.
b. Use the Query Builder to create a query named Sales Employees Query and a table named
sales_emps. Include all employees that contain the word Sales as part of their job titles.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-21

When you create the filter, remember that Sales is case sensitive.

c. Include all columns and sort the resulting table by Department.


d. Run the query and verify the results. Save the Chapter4 project.
Partial Results (8 of 189 rows)

Level 2

3. Using the Data Explorer


Use the Data Explorer to create a subset of Australian employees with salaries less than $100,000.
a. In the Chapter4 project, select File Open Data Exploration to explore the
Employee_Master table in the orion library.
If the orion library is not available, use the Assign Project Library task to create the
orion library that points to the location of the course data. Refer to Chapter 2, Exercise 1.
b. Use the Data Exploration pane on the right to select only the following columns: Employee_ID,
Employee_Name, Employee_Hire_Date, Salary, City, Department, and Job_Title.
c. Filter the rows to include only employees from Australia who have salaries less than $100,000.
d. Sort the data by ascending employee name.
e. Apply all updates and verify that there are 71 rows and seven columns.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-22 Chapter 4 Creating Simple Queries

Partial Results (8 of 71 rows)

f. Use Quick Stats to answer the following questions regarding this subset of employees:
What percentage work in the Sales Department?
What cities do the employees work in?
What is the average salary?
What is the oldest hire date?

g. Add the Data Exploration to the process flow as a new data source.
h. Save the Chapter4 project.

Challenge

No SAS programming experience is required.

4. Creating a New Table in the Filter and Sort Task with an Advanced Filter
Use the Filter and Sort task to create a new table with San Diego employees in the 920 postal code
area. Sort the rows in postal code order.
a. In the Chapter4 project, add the employee_addresses data set if necessary

b. Use the Filter and Sort task to create a new table for the San Diego office manager. The table
should include Employee_ID, Employee_Name, Street_Number, Street_Name, and
Postal_Code.
c. Include only those employees who have a Postal_Code value that begins with the characters 920.

Access the Advanced Filter Builder by clicking Advanced Edit on the Filter tab.
The SUBSTR function can be used to create the filter.

d. Order the output table in ascending postal code order.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-23

e. Submit the task to create the new table.


Partial Results (8 of 47 rows)

f. Save the Chapter4 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-24 Chapter 4 Creating Simple Queries

4.2 Creating New Columns with an


Expression

Objectives
Define a new column of data in a query by building
an expression.

34

Business Scenario
Orion Star wants to analyze shipment methods by
determining how many days elapse between each order
date and delivery date. The company also wants to
calculate the total amount invoiced to the customer, which
is the sum of total retail price and shipping charges.

Orders
Order Delivery Total_Retail Shipping
_Date _Date _Price

shipment total invoice


methods amount

35

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns w ith an Expression 4-25

Computed Columns
New summarized columns, recoded columns, or columns
based on an expression can be added to a query
in the Query Builder.

Click the tab or


the button to
begin creating
a new column.
36

New Computed Column Wizard


A wizard guides you through the process of creating
the new column and assigning attributes such
as the column name, label, and format.

37

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-26 Chapter 4 Creating Simple Queries

SAS Functions
A SAS function is a routine that returns a value
that is determined from specified arguments.

General form of a SAS function:

function-name(argument1,argument2, . . .)

Example:

sum(Salary,Bonus)

38

Using SAS Functions


SAS functions can do the following:
perform arithmetic operations
compute sample statistics (for example, sum, mean,
and standard deviation)
manipulate SAS dates
process character values
perform many other tasks

Sample statistics functions ignore missing values.

39

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns w ith an Expression 4-27

4.06 Multiple Choice Poll


What is the result of the expression given the values
of Var1, Var2, and Var3?
a. . (missing)
b. 3
c. 9
d. 12

Var1 Var2 Var3


9 . 3

Var1+Var2+Var3

40

4.07 Multiple Choice Poll


What is the result of the expression given the values
of Var1, Var2, and Var3?
a. . (missing)
b. 3
c. 9
d. 12

Var1 Var2 Var3


9 . 3

sum(Var1,Var2,Var3)

42

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-28 Chapter 4 Creating Simple Queries

Creating a Column with an Expression

Orion Star would like to analyze shipment methods by determining how many days passed between each
order date and delivery date. The company also wants to calculate the total amount invoiced to the
customer, which is the sum of the total retail price and shipping charges. Use the Query Builder to create
a table named shipping with the new computed columns.

1. In the Chapter4 project, double-click the orders table. Select Query Builder.

If you do not have the Chapter4 project, you can create a new project.

2. Enter Shipping Detail Query in the Query name field. Click Change and enter shipping
in the File name field. Select Save.

3. Verify that the Select Data tab is active. Add the following columns from the orders table:
Order_ID, Order_Date, Delivery_Date, Product_ID, Total_Retail_Price, Shipping, and Profit.

4. To add a new column to the query, begin by clicking on the Select Data tab, or you can select
Computed Columns New.
5. In Step 1, select Advanced expression Next.

6. In Step 2, expand Selected Columns. Double-click Delivery_Date to add the column


to the expression. Select or enter a minus sign. Double-click Order_Date to complete the
expression. Click Next.

7. In Step 3, enter Days_to_Deliver in the Column Name field. Enter Days to Deliver
in the Label field. Click Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns w ith an Expression 4-29

8. In Step 4, review the summary of the new columns properties and click Finish.
9. Repeat the process to create the Invoice_Amt column. Begin by clicking .

10. In Step 1, select Advanced expression Next.


11. In Step 2, scroll down. Find the SUM function under the Functions folder. Double-click
SUM Function to add it to the expression. Notice that the syntax for the SUM function
is to the right of the list of functions.

12. Select Favorites Tables to quickly collapse the Functions folder. Expand Selected Columns.
Double-click Total_Retail_Price, and then enter or select the comma. Double-click Shipping
to complete the expression as follows:

13. Click Next. In Step 3, enter Invoice_Amt in the Column Name field. Enter Invoice Amount
in the Label field. To display the data values as currency, click Change next to the Format field.
In the Format window, select Currency in the Categories pane and DOLLARw.d in the Formats
pane. Change the overall width to 10 and the decimal places to 2. Click OK Next.

14. Verify the summary of the properties and click Finish. Both new columns are added to the Selection
pane and the Select Data tab.

15. To emphasize the orders with the longest delivery time, sort the table in descending sequence
by Days_to_Deliver. Click the Sort Data tab, and drag and drop the Days_to_Deliver column onto
the tab area. Change the sort direction to Descending.
16. Run the query and examine the results. Save the Chapter4 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-30 Chapter 4 Creating Simple Queries

Partial Results (8 of 617 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns w ith an Expression 4-31

Exercises

Level 1

5. Using the Query Builder to Create a New Table with a Computed Column
Use the Query Builder to create New_Salary, which is the current salary plus a 2% raise.
a. In the Chapter4 project, add the employee_payroll data set.
If you do not have the Chapter4 project, you can create a new project.
b. Use the Query Builder to create a query named New Salary Query. Name the output table
New_Salary.
c. Include Employee_ID, Employee_Gender, Salary, Birth_Date, and Employee_Hire_Date.
Modify the properties of the Salary column to change the column name to Old_Salary.
d. Include only active employees who have a missing value for Employee_Term_Date.
e. Create a new column named New_Salary that is the current salary plus a 2% raise. Format
the column to include dollar signs and two decimal places.
Hint: Multiply Old_Salary by 1.02.
f. Submit the query and verify the results.
Partial Results (8 of 308 rows)

g. Save the Chapter4 project.

Level 2

6. Creating a Query with a Computed Column Using a Function


Use the Query Builder to create a table from the employee_donations table with a new column
that indicates the total contributions from each employee.
a. In the Chapter4 project, add the employee_donations data set.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-32 Chapter 4 Creating Simple Queries

b. Use the Query Builder to create a query named Donations Query and a table named
Total_Donations.
c. Include the Employee_ID, Recipients, and Paid_By columns in the new table.
d. Create a new column named Total_Donations, which totals the values of the four quarterly
donations. Format the new column to display dollar signs, commas, and two decimal places.

Use a function to calculate the total and thereby ignore any missing values that might
be in the input columns.
e. Submit the query and verify that the new column was calculated correctly. Save the Chapter4
project.

Partial Results (8 of 124 rows)

Challenge

No SAS programming experience is required.

7. Creating a Query to Calculate the Number of Years Employed


Use the Query Builder to create a table that includes active employees (those with no termination
date) and the number of years that each was employed.

a. In the Chapter4 project, use the employee_payroll table to create a query named Years
Employed Query and a table named Years_Employed. Include Employee_ID and
Employee_Hire_Date. Include only employees without a termination date.

b. Create a new column named Years_Employed that calculates the number of years that each
employee worked at Orion Star, based on the hire date and todays date. Apply a format that
displays the values rounded to one decimal place.
Hint: The YRDIF function can be used to calculate the number of years between two dates.
Also, the TODAY function can be used to provide the current date.

To learn about the YRDIF function, you can either select the function in the Advanced
Expression Editor (in the Date and Time category), or use SAS OnlineDoc.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns w ith an Expression 4-33

A new value for the basis (the third argument in the YRDIF function) was added in
SAS 9.3. AGE calculates the accurate age based on the start and end dates provided in
the YRDIF function. In earlier versions of SAS, you can use ACTUAL as the basis, but it
can produce unexpected results if the start or end date occurs in a leap year. See Computing
Ages in SAS (http://support.sas.com/publishing/authors/extras/61860_update.pdf)
for details and alternate solutions for SAS 9.2 and earlier.
c. Run the query, verify the results, and save the Chapter4 project.
Partial Results (8 of 308 rows)

Your results might differ from those shown above.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-34 Chapter 4 Creating Simple Queries

4.3 Grouping and Summarizing 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.

49

Business Scenario
Orion Star wants to offer a sales promotion that highlights
the most lucrative products. The company would like a list
of all products with a total profit that exceeds $500.
Orders (partial)
Product_ID Profit
230100500026 $551.80
230100500026 $137.95
230100500056 $4.50
230100500056 $9.00 Query_for_Orders (partial)
230100500056 $4.50 Total
Product_ID
_Profit
230100500026 $689.75

230100500056 $18.00

50

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.3 Grouping and Summarizing Data in a Query 4-35

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

51

Grouping Data
The Select Data tab can be used to group and summarize
data.
Choose a statistic
for columns to
be summarized.

Columns without an assigned


statistic automatically define
the groups.
52

A summarized column can also be created by using the New Computed Column Wizard.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-36 Chapter 4 Creating Simple Queries

The order of the columns on the Select Data tab determines the initial grouping hierarchy. However,
this can be modified in the Summary Groups pane. To modify the grouping structure of the data, clear
the Automatically select groups check box and select Edit Groups.
Statistics include the following:

AVG, MEAN STD (standard deviation)

COUNT, FREQ, N (number nonmissing values) STDERR (standard error of the mean)

CSS (corrected sum of squares) SUM

CV (coefficient of variation) SUMWGT (sum of WEIGHT variable values)

MAX or MIN T (Students t-value testing the hypothesis that


the population mean is zero)

NMISS (number of missing values) USS (uncorrected sum of squares)

PRT (two-tailed p-value for Students t statistic) VAR (variance)


RANGE (range of values)

Some summary functions enable you to select DISTINCT as part of the function. For example,
the summary statistic AVG computes the average for all observations within each group.
However, the summary function AVG DISTINCT excludes duplicate values in the calculation
so that the computed statistic is the average of only the distinct values within each group.

Grouping by Column Values


The query result includes one row for every unique value
of the group column or columns and a calculated statistic
for the summarized column or columns.

53

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.3 Grouping and Summarizing Data in a Query 4-37

4.08 Quiz
1. Open the Query Builder and use any data source
in the current project.
2. Click the Filter Data tab and notice the layout.
3. Return to the Select Data tab and add any two
columns.
4. For one of the columns on the Select Data tab,
select Count in the Summary field.
5. Return to the Filter Data tab.

How does the Filter Data tab change after a query


includes grouped data?

54

Filtering Data
The Filter Data tab can be used to filter both raw data
and summarized data.

56

First, the query extracts, from the table or tables, all rows that satisfy the conditions specified in the Filter
the raw data pane. Then the resulting data is grouped by the assigned grouping variable, and summary
statistics are computed for each unique group as defined on the Select Data tab. Further subsetting that is
defined in the Filter the summarized data pane is then applied to the summarized values.

Filtering grouped data is the same as using the HAVING clause in an SQL query.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-38 Chapter 4 Creating Simple Queries

Summarizing and Filtering by Groups

Orion Star would like to offer a sales promotion that highlights the most frequently purchased products.
The company wants a list of all products with a total profit exceeding $500. Use the Query Builder
to group, summarize, and filter the orders data set.

1. In the Chapter4 project, right-click the orders table in the project tree or process flow and select
Query Builder.

2. Name the query Top Products Query and name the output table TopProducts.

3. Double-click Product_ID and Profit in the Selection pane to add both columns to the Select Data tab.
4. On the Select Data tab, click in the Summary column for the Profit column. Select the SUM statistic
from the drop-down list. Notice that the Automatically select groups check box is selected.

You can double-click SUM_of_Profit to modify the properties, including column name, label,
and format.

5. Click the Filter Data tab. Drag SUM_of_Profit from the Selection pane to the Filter the summarized
data pane.

6. In the New Filter Wizard, verify that the column name is SUM_of_Profit. Select Greater than
in the Operator field. Enter 500 in the Value field and click Finish.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.3 Grouping and Summarizing Data in a Query 4-39

7. Click the Sort Data tab. Drag and drop SUM_of_Profit onto the tab area and change the sort
direction to Descending.
8. Click Run and verify the results. Save the Chapter4 project.

Partial Results (8 of 19 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-40 Chapter 4 Creating Simple Queries

Exercises

Level 1

8. Using the Query Builder to Group and Summarize Data


Use the Query Builder to create an output table with the average payroll by city.
a. In the Chapter4 project, add the employee_master data set.

If you do not have the Chapter4 project, you can create a new project.

b. Use the Query Builder to create a query named Average Salary per City Query
and an output table named AvgSal_City.
c. Include only the City and Salary columns in the query.
d. Select the AVG (average) statistic for Salary.

After you choose a summary statistic, the Summary groups section appears on the lower
part of the Select Data tab. The Automatically select groups check box is selected.

e. Sort the table in decreasing order of AVG_of_Salary.


f. Submit the query and view the results. Save the Chapter4 project.
Results

Level 2

9. Using the Query Builder to Group, Summarize, and Filter Data


a. In the Chapter4 project, add the employee_master data set if necessary.
b. Create a new query named Salary Summary by Dept Query and an output table named
salary_summary.
c. Include Department, Employee_ID, and Salary (twice) on the Select Data tab. Select the
appropriate statistics to calculate the number of employees, the average salary, and the total salary
for each department.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.3 Grouping and Summarizing Data in a Query 4-41

d. Modify the formats applied to the AVG_of_Salary and SUM_of_Salary columns to round
values to the nearest dollar.
e. Filter the query to include only those departments with more than 10 employees.
f. Sort the data by decreasing department size, based on the number of employees.
g. Submit the query and view the results. Save the Chapter4 project.

Results

Challenge

No SAS programming experience is required.

10. Using the Query Builder to Produce a Top-Ten Report


a. In the Chapter4 project, add the employee_master data set if necessary.
b. Create a new query named Top 10 Paid Job Titles.
c. Calculate the average salary for each job title. Rename the column AverageSalary and apply
a format to round to the nearest dollar.

d. Filter the data to exclude any employees with Chief as part of the job title.
e. Sort the data in decreasing sequence of average salary.
f. Modify the query options to produce the following results:
Generate a report, rather than a data table.
Limit the number of output rows to 10.
Title the report Top 10 Average Salaries by Job Title.

Look for the appropriate option by selecting Options Options for this query.

g. Submit the query and view the report. Save the Chapter4 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-42 Chapter 4 Creating Simple Queries

Results

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-43

4.4 Joining Tables

Objectives
Join multiple tables by common columns.
Include only matching rows.

62

Business Scenario
Products with total profits exceeding $500 were identified.
Analysts need more details about these top products,
including the product name, category, supplier, and
country. These columns come from three different tables.

topproducts products country


_lookup
63

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-44 Chapter 4 Creating Simple Queries

Business Scenario
To include the necessary columns, the topproducts
SAS table must be joined with the products SAS table
and the country_lookup Excel spreadsheet.

64

You might need to join tables to accomplish the following:


create a report with columns from more than one table
compute a new column when the input columns are located in separate tables
add information from a lookup table into a base table
identify column values that do or do not occur in other tables

Tables and Joins Window


Joining tables enables you to extract and simultaneously
process data from more than one table.

65

Select Add Tables to include additional tables in the query. The Query Builder attempts to join tables
by columns that have the same name and type. If no column name and type matches are found, then
a warning message tells you to join the columns manually.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-45

To prevent SAS Enterprise Guide from attempting to join tables by matching columns, select
Tools Options Query and clear the Automatically attempt to join tables in query check box.

Join Properties
The Join Properties window provides the ability to modify
the join type or condition. Selecting a different join type
can be used to identify or eliminate nonmatching rows.

66

To learn more about the join types, select Help in the Tables and Joins window, and then select
Understanding the types of joins.

Join Types
By default, the Query Builder performs an inner join,
which includes matching rows only in the results.
Em ployee_Payroll Em ployee_Organization
Employee_ID Salary Employee_ID Department
120101 163040 120101 Sales Management
120102 108255 120102 Sales Management
120103 87975 120103 Engineering
120104 92500 120105 Administration

Employee_ID Salary Department


120101 163040 Sales Management
120102 108255 Sales Management
120103 87975 Engineering

67

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-46 Chapter 4 Creating Simple Queries

Join Types
A full outer join includes all rows from both tables.

Em ployee_Payroll Em ployee_Organization
Employee_ID Salary Employee_ID Department
120101 163040 120101 Sales Management
120102 108255 120102 Sales Management
120103 87975 120103 Engineering
120104 92500 120105 Administration

Employee_ID Salary Department


120101 163040 Sales Management
120102 108255 Sales Management
120103 87975 Engineering
120104 92500
120105 Administration

68

Join Types
A left join includes all rows from Employee_Payroll.

Em ployee_Payroll Em ployee_Organization
Employee_ID Salary Employee_ID Department
120101 163040 120101 Sales Management
120102 108255 120102 Sales Management
120103 87975 120103 Engineering
120104 92500 120105 Administration

Employee_ID Salary Department


120101 163040 Sales Management
120102 108255 Sales Management
120103 87975 Engineering
120104 92500

69

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-47

4.09 Multiple Answer Poll


Which Employee_ID values would be included
in a right join?
a. 120101
b. 120102
c. 120103
d. 120104
e. 120105

Em ployee_Payroll Em ployee_Organization
Employee_ID Salary Employee_ID Department
120101 163040 120101 Sales Management
120102 108255 120102 Sales Management
120103 87975 120103 Engineering
120104 92500 120105 Administration

70

Join Results
When joining tables in the Query Builder, you can filter
or sort on any of the columns from the input tables.
You can also compute new columns, or group
and summarize them.

72

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-48 Chapter 4 Creating Simple Queries

Joining Tables

In a previous query, products with total profits exceeding $500 were identified. Analysts asked for more
details about these top products, including the product category, the product, supplier, and country name.
To include the necessary columns, use the Query Builder to join the TopProducts SAS table with the
products SAS table and the country_lookup Excel spreadsheet.

1. In the Chapter4 project, add the TopProducts and Products SAS data sets and the country_lookup
Excel file to the project.
2. The Import Data task opens to import the country_lookup Excel file. Name the imported table
country_lookup and select the First row of range contains field names check box. Do not make
any changes to the field attributes.
3. In the process flow, hold down the Ctrl key and select TopProducts, Products, and Data Imported
from country_lookup. Right-click one of the three tables and select Query Builder.

If you are using an older version of Enterprise Guide, start building the query and use only
one of the three tables. Then select Add Tables to add the other two data sets.

4. A message appears and indicates that Enterprise Guide was unable to find matching columns
on which to join in all three tables. Click OK.

5. The Tables and Joins window automatically appears. To join the products and country_lookup
tables, first select Supplier_Country in the products table. Select Supplier_Country a second time
and drag it to connect it to Country_Key in the country_lookup table.

You can also right-click Supplier_Country and select Join with <choosetable>
Country_Key.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-49

6. The Join Properties dialog box automatically appears. Verify that the join type is Matching rows only
given a condition (Inner Join) and that the condition is t2.Country_Key = t3.Supplier_Country.

The table alias names (t1, t2, or t3) might differ depending on the order in which the data sets
were added to the query.

7. Click OK and verify that the three tables are linked as displayed below. Click Close to return to the
Select Data tab.

The order of the tables might differ in the Tables and Joins window.

8. Name the query Top Products Info Query and the output table TopProductsInfo.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-50 Chapter 4 Creating Simple Queries

9. Double-click the following columns to add each to the Select Data tab: Product_ID,
SUM_of_Profit, Product_Category, Product_Name, Supplier_Name, and Country_Name.
10. Click the Sort Data tab and sort the data by SUM_of_Profit in descending order.
11. Click Run to execute the query. Verify the results and save the Chapter4 project.
Partial Results (8 of 19 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-51

Exercises

Level 1

11. Joining Data from Two Tables


Use the Query Builder to create a new table whose data results from a join of two tables.
Create a new column.
a. In the Chapter4 project, add the employee_payroll and employee_addresses data sets
if necessary.

If you do not have the Chapter4 project, you can create a new project.

b. Use the Query Builder to join employee_payroll and employee_addresses to create a table
named employee_payroll_location. Label the query Payroll Location Join Query.

c. Open the Tables and Joins window to verify that the join between the two tables is
on the Employee_ID column.

d. Include the following columns on the Select Data tab: Employee_ID, Employee_Name,
Employee_Gender, Birth_Date, Salary, Street_Number, Street_Name, City, State,
and Country.
e. Format the Salary column with a dollar sign, comma, and two decimal places. Format
the Birth_Date column with the calendar form 01JAN2014.
f. Create a new column named Bonus that represents 1.5% of the Salary column. Format
the values with a dollar sign, comma, and two decimal places.

g. Include only active employees in the output table, or those that do not have a value for
Employee_Term_Date.

h. Submit the query and view the results. Save the Chapter4 project.
Partial Results (8 of 308 rows)

Level 2

12. Joining Data from Three Tables


a. Complete the Level 1 exercise.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-52 Chapter 4 Creating Simple Queries

b. Add the country_lookup SAS data set to the Chapter4 project.


c. Modify Payroll Location Join Query. Manually join country_lookup and employee_addresses
by the common column.
The common column might be named differently in the two tables.

d. Remove the Country column on the Select Data tab and replace it with a column representing
the full country name in the country_lookup table.
e. Resubmit the query and view the results. Save the Chapter4 project.

Partial Results (8 of 308 rows)

13. Isolating Nonmatches


Use the Query Builder to identify employees who did not make donations.
a. In the Chapter4 project, add the employee_donations data set if necessary.
b. Build a query to join the employee_addresses table with employee_donations. Name the query
Employees Without Donations Query and the table no_donations.
c. Modify the join properties to include all rows from the employee_addresses table.
d. Include all columns from the employee_addresses table.
e. Filter the query to include only the missing Employee_ID values from the employee_donations
table. This isolates those employees who do not appear in the employee_donations table.

f. Submit the query and view the results. Save the Chapter4 project.
Partial Results (8 of 300 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-53

Challenge

No SAS programming experience is required.

14. Joining Data Using a Non-Equijoin Condition


Use the Query Builder to join the data from two sources where the join condition involves
a non-equijoin condition.

Two columns in the bonus_schedule data set, Employed_After and Employed_Before,


define the time range for a given bonus percentage. To find the correct bonus percentage for
each employee, join the Employee_Hire_Date column with the Employed_After column
with the greater-than-or-equal-to operator. Set a second join with the Employee_Hire_Date.
This time, use the Employed_Before column with the less-than-or-equal-to operator.

a. In the Chapter4 project, add the employee_payroll and bonus_schedule data sets if necessary.
b. Because there are no matching columns between these two tables, a manual join is required.
Join the tables so that Employee_Hire_Date is on or after the Employed_After column
and is on or before the Employed_Before column.

c. Add Employee_ID, Employee_Hire_Date, Salary, and Bonus_Percent to the query.


d. Create a new column named Bonus_Amount that multiplies Salary by the percent value
in the Bonus_Percent column. Display Bonus_Amount with a dollar sign, comma,
and two decimal places.
e. Submit the query and verify the results. Save the Chapter4 project.
Partial Results (8 of 424 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-54 Chapter 4 Creating Simple Queries

4.5 Solutions
Solutions to Exercises
1. Creating a New Table in the Filter and Sort Task with a Basic Filter
Use the Filter and Sort task to create a new table with San Diego employees sorted in postal code order.
a. In the Chapter4 project, add the employee_addresses data set.

If you do not have the Chapter4 project, you can create a new project.

1) Select File Open Data and navigate to the location of the course data.

2) Select employee_addresses Open.


b. Using the Filter and Sort task, create a new table for the San Diego office manager. This table
should include Employee_ID, Employee_Name, Street_Number, Street_Name, and Postal_Code.
1) In the data grid, select Filter and Sort.

2) On the Variables tab, select Employee_ID, Employee_Name, Street_Number,


Street_Name, and Postal_Code. Move them to the Selected pane.
c. Create a filter to include only employees from San Diego in the output table.
1) On the Filter tab, select the City column in the drop-down menu.

2) In the second field, select the Equal to operator in the drop-down menu.

3) In the third field, click and then select San Diego OK.

d. Order the output table in ascending postal code order.


On the Sort tab, select Postal_Code.
e. Name the task and output table SanDiegoEmployees.
1) Click the Results tab.
2) Enter SanDiegoEmployees in the Task name field.
3) Click Change and enter SanDiegoEmployees in the File name field.
4) Select Save.

f. Submit the task to create the new table.


Click OK to submit the task.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-55

Partial Results (8 of 112 rows)

g. Save the Chapter4 project.


1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.

2. Creating a New Table in the Query Builder with a Basic Filter


Use the Query Builder to create a new table that includes all employees with the word Sales in their
job titles.

a. In the Chapter4 project, add the employee_organization data set.


1) Select File Open Data and navigate to the location of the course data.
2) Select employee_organization Open.
b. Use the Query Builder to create a query named Sales Employees Query and a table named
sales_emps. Include all employees that contain the word Sales as part of their job titles.

When you create the filter, remember that Sales is case sensitive.

1) Select Query Builder in the data grid or right-click employee_organization in the project
and select Query Builder.
2) Enter Sales Employees Query in the Query name field.
3) Click Change and enter sales_emps in the File name field. Select Save.
4) Click the Filter Data tab. Drag and drop Job_Title onto the tab area.

5) In the New Filter window, select Contains from the Operator drop-down list.
6) Enter Sales in the Value field and click Finish.
c. Include all columns and sort the resulting table by Department.
1) Drag t1(employee_organization) onto the Select Data tab.
2) Click the Sort Data tab. Drag and drop Department onto the tab area.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-56 Chapter 4 Creating Simple Queries

d. Run the query and verify the results. Save the Chapter4 project.
1) Click Run.
2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.

Partial Results (8 of 189 rows)

3. Using the Data Explorer


Use the Data Explorer to create a subset of Australian employees with salaries less than $100,000.
a. In the Chapter4 project, select File Open Data Exploration to explore the
Employee_Master table in the orion library.

If the orion library is not available, use the Assign Project Library task to create the
orion library that points to the location of the course data. Refer to Chapter 2, Exercise 1.

1) Select File Open Data Exploration.


2) Double-click Servers Libraries ORION and select Employee_Master. Click Open.
b. Use the Data Exploration pane on the right to select only the following columns: Employee_ID,
Employee_Name, Employee_Hire_Date, Salary, City, Department, and Job_Title.

1) In the Data Exploration pane, select Edit next to Selected Columns.


2) Hold down the Ctrl key and highlight Employee_ID, Employee_Name,
Employee_Hire_Date, Salary, City, Department, and Job_Title. Select the arrow
to move the columns to Selected columns.
3) Click Add to Pending Updates.

c. Filter the rows to include only employees from Australia who have salaries less than $100,000.
1) In the Data Exploration pane, select Edit next to Filter Conditions.
2) Change the first Select column value to Country.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-57

3) Click on the first filter, and select Click to load values. Select AU Apply Selection.
4) Change the second Select column value to Salary.
5) Click on the second filter and select the Conditional Filter tab.
6) Change is equal to to is less than and enter 100000. Select Apply Selection.
7) Click Apply to Pending Updates.
d. Sort the data by ascending employee name.
1) In the Data Exploration pane, select Edit next to Sort Order.
2) Select Employee_Name and select the arrow to move it to Selected columns.
3) Click Add to Pending Updates.
e. Apply all updates and verify that there are 71 rows and seven columns.
Select Apply Updates in the Data Exploration pane.
Partial Results (8 of 71 rows)

f. Use Quick Stats to answer the following questions regarding this subset of employees:
1) Click in the Data Exploration pane and select Click to run all statistics.

2) Click the Quick Stats icon next to each column name to answer the questions.
What percentage work in the Sales Department? 64. 79%
What cities do they work in? Sydney, Melbourne
What is the average salary? $29,819.72
What is the oldest hire date? 01JAN1979

g. Add the Data Exploration to the process flow as a new data source.
Select Add to Process Flow.
h. Save the Chapter4 project.
1) Click on the toolbar.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-58 Chapter 4 Creating Simple Queries

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.
4. Creating a New Table in the Filter and Sort Task with an Advanced Filter

No SAS programming experience is required.

Use the Filter and Sort task to create a new table with San Diego employees in the 920 postal code
area. Sort the rows in postal code order.

a. In the Chapter4 project, add the employee_addresses data set if necessary.


1) Select File Open Data and navigate to the location of the course data.
2) Select employee_addresses Open.
b. Use the Filter and Sort task to create a new table for the San Diego office manager. This table
should include Employee_ID, Employee_Name, Street_Number, Street_Name, and
Postal_Code.
1) In the data grid, select Filter and Sort, or right-click employee_addresses in the project
and select Filter and Sort.
2) On the Variables tab, hold down the Ctrl key and select the Employee_ID, Employee_Name,
Street_Number, Street_Name, and Postal_Code columns. Click to move the
columns to the Selected pane.

c. Include only those employees who have a Postal_Code value that begins with the characters 920.
Access the Advanced Filter Builder by clicking Advanced Edit on the Filter tab.
The SUBSTR function can be used to create the filter.

1) On the Filter tab, click Advanced Edit to open the Advanced Filter Builder.
2) Expand the Functions folder and select the SUBSTR function.
The documentation for this function is included in the right window. In this case,
the string value is the Postal_Code column, starting in the first column and
extracting a total of three characters.
3) Double-click the SUBSTR function to add it to the Enter a Filter window.
4) Collapse the Functions folder and expand Tables t1(employee_addresses).
5) Double-click the Postal_Code column to add it as the first argument of the function.
6) Enter 1 for the second argument to indicate that characters in the first position should
be extracted. Enter a comma and then enter 3 to indicate to extract three characters.
7) Move the cursor outside the close parenthesis and enter ="920" to set the filter condition.
The complete filter should appear as follows:

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-59

8) Click OK to close the Advanced Filter Builder.


d. Order the output table in ascending postal code order.
1) Click the Sort tab.
2) In the Sort by field, select Postal_Code.
e. Submit the task to create the new table.
Click OK to submit the task.
Partial Results (7 of 47 rows)

f. Save the Chapter4 project.


1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.
5. Using the Query Builder to Create a New Table with a Computed Column
Use the Query Builder to create New_Salary, which is the current salary plus a 2% raise.
a. In the Chapter4 project, add the employee_payroll data set.

1) Select File Open Data and navigate to the location of the course data.
2) Select employee_payroll Open.
b. Use the Query Builder to create a query named New Salary Query. Name the output table
New_Salary.

1) In the data grid, select Query Builder or right-click employee_payroll in the project
and select Query Builder.
2) Enter New Salary Query in the Query name field.
3) Click Change to the right of the Output name field.
4) Enter New_Salary in the File name field. Select Save.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-60 Chapter 4 Creating Simple Queries

c. Include Employee_ID, Employee_Gender, Salary, Birth_Date, and Employee_Hire_Date.


Modify the properties of the Salary column to change the column name to Old_Salary.
1) Hold down the Ctrl key and select Employee_ID, Employee_Gender, Salary, Birth_Date,
and Employee_Hire_Date. Drag all columns and drop them onto the Select Data tab.

2) Select Salary on the Select Data tab and click (the Properties icon).

3) In the Properties for Salary window, enter Old_Salary in the Column Name field. Click OK.
d. Include only active employees who have a missing value for Employee_Term_Date.
1) Click the Filter Data tab.
2) Drag and drop Employee_Term_Date to the Filter the raw data text box to open the
New Filter Wizard.

3) Select Is Missing in the Operator field.

You can also use the Equal-to operator and enter . (a period) in the Value field.

4) Click Next.
5) Click Finish after you review the summary.
e. Create a new column named New_Salary that is the current salary plus a 2% raise. Format
the column to include dollar signs and two decimal places.
Hint: Multiply Old_Salary by 1.02.
1) Click the Select Data tab.
2) Click to open the New Computed Column Wizard.

3) Select Advanced expression Next.


4) Expand Selected Columns to view the columns in the query. Double-click the Old_Salary
column to add it to the expression.

The name of the variable in the expression is t1.Salary, referring to the column name
from the input table. The query result reflects the column name change to Old_Salary.
5) Using the menu bar or the keyboard, enter * (the multiplication operator), and enter 1.02
for the operand. The final expression appears as follows:

6) Click Next.
7) In Step 3 of the wizard, enter New_Salary in the Column Name field.
8) Click Change next to the Format field.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-61

9) In the Formats window, select the Currency category and the DOLLARw.d format.
Set the overall width to 12 and the decimal places to 2.
10) Click OK Next.
11) Click Finish after you review the Summary step.
f. Submit the query and verify the results.

Click Run.
Partial Results (8 of 308 rows)

g. Save the Chapter4 project.

1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.

6. Creating a Query with a Computed Column Using a Function


Use the Query Builder to create a table from the employee_donations table with a new column
that indicates the total contributions from each employee.
a. In the Chapter4 project, add the employee_donations data set.

1) Select File Open Data and navigate to the location of the course data.
2) Select employee_donations Open.
b. Use the Query Builder to create a query named Donations Query and a table named
Total_Donations.

1) In the data grid, click the Query Builder icon.


2) In the Query name field, enter Total Donations Query.
3) Click Change. In the File name field, enter Total_Donations and select Save.
c. Include the Employee_ID, Recipients, and Paid_By columns in the new table.
Double-click the columns Employee_ID, Recipients, and Paid_By to add each
on the Select Data tab.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-62 Chapter 4 Creating Simple Queries

d. Create a new column named Total_Donations, which totals the values of the four quarterly
donations. Format the new column to display dollar signs, commas, and two decimal places.

Use a function to calculate the total, and thereby ignore any missing values that might
be in the input columns.

1) Select Computed Columns New.


2) Select Advanced expression Next.
3) In the Enter an expression text box, enter the following:
sum(Qtr1, Qtr2, Qtr3, Qtr4)
4) Click Next.
5) Enter Total_Donations in the Column Name field.
6) Click Change. In the Formats window, select the Currency category and select the
DOLLARw.d format. Set the Overall width to 10 and the Decimal places to 2.
Click OK Next.

7) After you verify the summary, click Finish Close.


e. Submit the query and verify that the new column was calculated correctly. Save the Chapter4
project.

1) Click Run to submit the query.


2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.

Partial Results (8 of 124 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-63

7. Creating a Query to Calculate the Number of Years Employed

No SAS programming experience is required.

Use the Query Builder to create a table that includes active employees (those with no termination
date) and the number of years each was employed.
a. In the Chapter4 project, use the employee_payroll table to create a query named Years
Employed Query and a table named Years_Employed. Include Employee_ID and
Employee_Hire_Date. Include only employees without a termination date.
1) If necessary, add the employee_payroll table to the project by selecting File Open Data.
2) Navigate to the location of the course data. Select employee_payroll Open.
3) In the data grid, select Query Builder or right-click employee_payroll in the project
and select Query Builder.

4) In the Query name field, enter Years Employed Query.


5) Click Change. Enter Years_Employed in the File name field and select Save.
6) On the Select Data tab, double-click the Employee_ID and Employee_Hire_Date columns
to add each to the query.

7) Click the Filter Data tab.


8) Drag and drop Employee_Term_Date into the Filter the raw data text box. In the Edit Filter
Wizard, select the Is missing operator. This part of the filter keeps only the active employees.

9) Click Finish.
b. Create a new column named Years_Employed that calculates the number of years that each
employee worked at Orion Star, based on the hire date and todays date. Apply a format that
displays the values rounded to one decimal place.
Hint: The YRDIF function can be used to calculate the number of years between two dates.
Also, the TODAY function can be used to provide the current date.

To learn about the YRDIF function, you can either select the function in the Advanced
Expression Editor (in the Date and Time category), or use SAS OnlineDoc.

A new value for the basis (the third argument in the YRDIF function) was added in
SAS 9.3. AGE calculates the accurate age based on the start and end dates provided in
the YRDIF function. In earlier versions of SAS, you can use ACTUAL as the basis, but it
can produce unexpected results if the start or end date occurs in a leap year. See Computing
Ages in SAS (http://support.sas.com/publishing/authors/extras/61860_update.pdf)
for details and alternate solutions for SAS 9.2 and earlier.

1) Click the Select Data tab.


2) Select Computed Columns New.
3) Select Advanced expression Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-64 Chapter 4 Creating Simple Queries

4) Use the available functions list or enter the following expression:


yrdif(Employee_Hire_Date, today( ), 'age')
5) Click Next. Enter Years_Employed in the Column Name field.
6) Click Change to apply a format.
7) In the Format window, select the Numeric category and the w.d format.
8) Change the overall width to 4 and the decimal places to 1.
9) Click OK Next.
10) Verify the summary and click Finish Close.
c. Run the query, verify the results, and save the Chapter4 project.
1) Click Run to submit the query.
2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.
Partial Results (8 of 308 rows)

Your results might differ from those shown above.


8. Using the Query Builder to Group and Summarize Data
Use the Query Builder to create an output table with the average payroll by city.

a. In the Chapter4 project, add the employee_master data set.


If you do not have the Chapter4 project, you can create a new project.

1) Select File Open Data and navigate to the location of the course data.
2) Select employee_master Open.
b. Use the Query Builder to create a query named Average Salary per City Query
and an output table named AvgSal_City.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-65

1) Select Query Builder in the data grid.


2) Enter Average Salary per City Query in the Query name field.
3) Click Change and enter AvgSal_City in the File name field.
4) Select Save.
c. Include only the City and Salary columns in the query.
Drag and drop the City and the Salary columns onto the Select Data tab.
d. Select the AVG (average) statistic for Salary.
After you choose a summary statistic, the Summary groups section appears on the lower
part of the Select Data tab. The Automatically select groups check box is selected.
1) Click the Summary field next to Salary on the Select Data tab. Select AVG from
the statistics list.

2) Verify that the name of the new column changes to AVG_of_Salary.


e. Sort the table in decreasing order of AVG_of_Salary.
1) Click the Sort Data tab.
2) Drag and drop the AVG_of_Salary column under the Computed Columns section
onto the Sort Data tab.

3) Change the sort direction to Descending.


f. Submit the query and view the results. Save the Chapter4 project.
1) Click Run and view the results.
2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.

Results

9. Using the Query Builder to Group, Summarize, and Filter Data


a. In the Chapter4 project, add the employee_master data set if necessary.
1) Select File Open Data and navigate to the location of the course data.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-66 Chapter 4 Creating Simple Queries

2) Select employee_master Open.


b. Create a new query named Salary Summary by Dept Query and an output table named
salary_summary.
1) In the data grid, select Query Builder or right-click employee_master in the project
and select Query Builder.
2) Enter Salary Summary by Dept Query in the Query name field.
3) Click Change and enter salary_summary in the File name field.
4) Select Save.
c. Include Department, Employee_ID, and Salary (twice) on the Select Data tab. Select the
appropriate statistics to calculate the number of employees, the average salary, and the total salary
for each department.
1) Double-click or drag and drop the Department, Employee_ID, and Salary columns
onto the Select Data tab. Be sure to add Salary two times.
2) Next to Employee_ID on the Select Data tab, change the Summary field to COUNT.
3) Next to the first instance of Salary on the Select Data tab, change the Summary field to AVG.
4) Next to the second instance of Salary on the Select Data tab, change the Summary field to SUM.

d. Modify the formats applied to the AVG_of_Salary and SUM_of_Salary columns to round
values to the nearest dollar.
1) Highlight the AVG_of_Salary column on the Select Data tab and click .
2) Click Change next to the Format field.
3) In the Formats window, change the number of decimal places to 0. Click OK OK.
4) Repeat Steps 1 through 3 for the SUM_of_Salary column.
e. Filter the query to include only those departments with more than 10 employees.
1) Click the Filter Data tab.
2) Drag COUNT_of_Employee_ID to the Filter the summarized data pane.
3) Select Greater than in the Operator field.
4) Enter 10 in the Value field and click Finish.

f. Sort the data by decreasing department size, based on the number of employees.
1) Click the Sort Data tab.
2) Drag and drop COUNT_of_Employee_ID onto the tab area.
3) Change the sort direction to Descending.

g. Submit the query and view the results. Save the Chapter4 project.
1) Click Run and view the results.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-67

2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.
Results

10. Using the Query Builder to Produce a Top-Ten Report

No SAS programming experience is required.

a. In the Chapter4 project, add the employee_master data set if necessary.


1) Select File Open Data and navigate to the location of the course data.
2) Select employee_master Open.
b. Create a new query named Top 10 Paid Job Titles.
1) In the data grid, select Query Builder or right-click employee_master in the project
and select Query Builder.
2) Enter Top 10 Paid Job Titles in the Query name field.
c. Calculate the average salary for each job title. Rename the column AverageSalary and apply
a format to round to the nearest dollar.
1) Double-click or drag and drop the Job_Title and Salary columns onto the Select Data tab.
2) Next to Salary on the Select Data tab, change the Summary field to AVG.
3) Select the AVG_of_Salary column on the Select Data tab and click to modify the
properties.
4) Enter AverageSalary in the Column Name field.
5) Click Change next to the Format field. Change the decimal places to 0. Click OK OK.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-68 Chapter 4 Creating Simple Queries

d. Filter the data to exclude any employees with Chief as part of the job title.
1) Click the Filter Data tab.
2) Drag Job_Title to the Filter the raw data pane.
3) In the New Filter window, select Does not contain in the Operator field.
4) Enter Chief in the Value field and click Finish.
e. Sort the data in decreasing sequence of average salary.
1) Click the Sort Data tab.
2) Drag and drop AVG_of_Salary onto the tab area.
3) Change the sort direction to Descending.
f. Modify the query options to produce the following results:
Generate a report, rather than a data table.
Limit the number of output rows to 10.
Title the report Top 10 Average Salaries by Job Title.

Look for the appropriate option by selecting Options Options for this query.

1) Select Options.
2) In the Result format pane, select the Override the corresponding default settings
in Tools-Options check box and select Report.

3) In the Query limits pane, select the Limit number of rows to save in output check box
and enter 10.

4) Select Titles in the Selection pane and select the Override the corresponding default
settings in Tools-Options check box.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-69

5) Enter Top 10 Average Salaries by Job Title and click OK.


g. Submit the query and view the report. Save the Chapter4 project.
Results

1) Click Run and view the results.


2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.
11. Joining Data from Two Tables
Use the Query Builder to create a new table whose data results from a join of two tables.
Create a new column.
a. In the Chapter4 project, add the employee_payroll and employee_addresses data sets
if necessary.

If you do not have the Chapter4 project, you can create a new project.

1) Select File Open Data and navigate to the location of the course data.
2) Hold down the Ctrl key. Select employee_payroll and employee_addresses Open.
b. Use the Query Builder to join employee_payroll and employee_addresses to create a table
named employee_payroll_location. Label the query Payroll Location Join Query.

1) In the process flow, hold down the Ctrl key and select the employee_payroll and
employee_addresses tables. Right-click one of the tables and select Query Builder.

2) Enter Payroll Location Join Query in the Query name field.


3) Click Change. Enter employee_payroll_location in the File name field. Select Save.
c. Open the Tables and Joins window to verify that the join between the two tables
is on the Employee_ID column.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-70 Chapter 4 Creating Simple Queries

1) Select Join Tables. The two tables should automatically be connected by the Employee_ID
column.
2) Click Close.
d. Include the following columns on the Select Data tab: Employee_ID, Employee_Name,
Employee_Gender, Birth_Date, Salary, Street_Number, Street_Name, City, State,
and Country.
e. Format the Salary column with a dollar sign, comma, and two decimal places. Format
the Birth_Date column with the calendar form 01JAN2009.

1) Highlight Salary on the Select Data tab and click .

2) Click Change next to the Format field.


3) Select Currency from the Categories pane and DOLLARw.d from the Formats pane.
4) Change the overall width to 12 and the decimal places to 2.
5) Click OK OK.
6) Highlight Birth_Date on the Select Data tab and click .

7) Click Change next to the Format field.


8) Select Date from the Categories pane and DATEw.d from the Formats pane.

9) Change the overall width to 9.


10) Click OK OK.
f. Create a new column named Bonus that represents 1.5% of the Salary column. Format
the values with a dollar sign, comma, and two decimal places.
1) On the Select Data tab, click to create a new column.

2) In Step 1, select Advanced expression Next.


3) In Step 2, type or click to provide the following expression:
Salary * .015
If you select Salary rather than enter it in the expression, it is included as either
t1.Salary or t2.Salary.

4) In Step 3, enter Bonus in the Column Name field.


5) Click Change next to the Format field.
6) Select Currency from the Categories pane and DOLLARw.d from the Formats pane.
7) Change the overall width to 10 and the decimal places to 2. Click OK.
8) Click Next Finish.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-71

g. Include only active employees in the output table, or those that do not have a value for
Employee_Term_Date.
1) Click the Filter Data tab. Drag and drop Employee_Term_Date onto the tab area.
2) In the New Filter window, change the operator to Is missing and click Finish.

h. Submit the query and view the results. Save the Chapter4 project.
1) Click Run.
2) Click on the toolbar.
3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.

Partial Results (8 of 308 rows)

12. Joining Data from Three Tables


a. Complete the Level 1 exercise.
Refer to the solutions for the previous exercise.
b. Add the country_lookup SAS data set to the Chapter4 project.
1) Select File Open Data and navigate to the location of the course data.
2) Select country_lookup Open.

c. Modify Payroll Location Join Query. Manually join country_lookup and employee_addresses
by the common column.
The common column might be named differently in the two tables.

1) Right-click Payroll Location Join Query in the project tree or process flow and select Modify.
2) In the Query Builder, select Add tables.
3) Select the country_lookup table and select Open.
4) A message appears and indicates that Enterprise Guide cannot automatically join
the tables by common columns. Click OK.

5) In the Tables and Joins window, select Country in the employee_addresses table.
Select Country a second time and drag the cursor to connect with Country_Key
in the country_lookup table.

6) The Join Properties window appears automatically. Verify that the join condition is
t2.Country = t3.Country_Key. Click OK Close.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-72 Chapter 4 Creating Simple Queries

d. Remove the Country column on the Select Data tab and replace it with a column representing
the full country name in the country_lookup table.
1) Select Country on the Select Data tab and click .

2) Double-click Country_Name from the country_lookup table to add it to the query.


3) Select Country_Name on the Select Data tab and click the up arrow to move it before Bonus.
e. Resubmit the query and view the results. Save the Chapter4 project.
1) Click Run.
2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.
Partial Results (8 of 308 rows)

13. Isolating Nonmatches


Use the Query Builder to identify employees who did not make donations.
a. In the Chapter4 project, add the employee_donations table if necessary.
1) Select File Open Data and navigate to the location of the course data.
2) Select employee_donations Open.

b. Build a query to join the employee_addresses table with employee_donations. Name the query
Employees Without Donations Query and the table no_donations.
1) In the process flow, hold down the Ctrl key and select the employee_donations and
employee_addresses tables. Right-click one of the tables and select Query Builder.
2) Enter Employees Without Donations Query in the Query name field.
3) Click Change and enter no_donations in the File name field. Select Save.
4) Select Add Tables. Select employee_addresses from the project and select Open.
c. Modify the join properties to include all rows from the employee_addresses table.
1) Select Join Tables to open the Tables and Joins window. Right-click the Venn diagram that
connects the two tables and select Properties.
2) In the Join Properties window, change the join type to All rows from the left table given
a condition.
Verify that the table on the left is employee_addresses.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-73

3) Click OK Close.
d. Include all columns from the employee_addresses table.
Drag the t1(employee_addresses) table onto the Select Data tab.
e. Filter the query to include only the missing Employee_ID values from the employee_donations
table. This isolates those employees who do not appear in the employee_donations table.

1) Click the Filter Data tab.


2) Drag Employee_ID from the employee_donations table onto the tab area.
3) In the New Filter window, change the operator to Is missing. Click Finish.
f. Submit the query and view the results. Save the Chapter4 project.
1) Click Run.
2) Click on the toolbar.
3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.
Partial Results (8 of 300 rows)

14. Joining Data Using a Non-Equijoin Condition


No SAS programming experience is required.

Use the Query Builder to join the data from two sources where the join condition involves
a non-equijoin condition.
Two columns in the bonus_schedule data set, Employed_After and Employed_Before,
define the time range for a given bonus percentage. To find the correct bonus percentage for
each employee, join the Employee_Hire_Date column with the Employed_After column
with the greater-than-or-equal-to operator. Set a second join with the Employee_Hire_Date.
This time, use the Employed_Before column with the less-than-or-equal-to operator.
a. In the Chapter4 project, add the employee_payroll and bonus_schedule data sets if necessary.
1) Select File Open Data and navigate to the location of the course data.
2) Select employee_payroll Open.
3) Repeat for bonus_schedule.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-74 Chapter 4 Creating Simple Queries

b. Because there are no matching columns between these two tables, a manual join is required.
Join the tables so that Employee_Hire_Date is on or after the Employed_After column
and is on or before the Employed_Before column.
1) In the process flow, hold down the Ctrl key and select the employee_payroll and
bonus_schedule tables. Right-click one of the tables and select Query Builder.
2) A message appears and indicates that Enterprise Guide cannot automatically join
the tables by common columns. Click OK.
3) In the Tables and Joins window, select Employee_Hire_Date in the employee_payroll table.
Select Employee_Hire_Date a second time and drag the cursor to connect with
Employed_After in the bonus_schedule table.
4) The Join Properties window appears automatically. Change the join condition so that
it is t1.employee_hire_date >= t2.Employed_After. Click OK.
5) Select Employee_Hire_Date again in the employee_payroll table. Select
Employee_Hire_Date a second time and drag the cursor to connect with
Employed_Before in the bonus_schedule table.
6) The Join Properties window appears automatically. Change the join condition so that
it is t1.employee_hire_date <= t2.Employed_Before. Click OK Close.

c. Add Employee_ID, Employee_Hire_Date, Salary, and Bonus_Percent to the query.


1) Click the Select Data tab.
2) Double-click Employee_ID, Employee_Hire_Date, Salary, and Bonus_Percent to add each
column to the query.

d. Create a new column named Bonus_Amount that multiplies Salary by the percent value
in the Bonus_Percent column. Display Bonus_Percent with a dollar sign, comma, and
two decimal places.
1) On the Select Data tab, click to begin creating a new column.

2) In Step 1, select Advanced expression Next.


3) In Step 2, type or click to create the following expression:
t1.Salary * t2.Bonus_Percent
4) Click Next. In Step 3, enter Bonus_Amount in the Column Name field.
5) Click Change next to the Format field.
6) Select Currency from the Categories pane and DOLLARw.d from the Formats pane.
7) Change the overall width to 10 and the decimal places to 2. Click OK.
8) Click Next Finish.
e. Submit the report and verify the results. Save the Chapter4 project.
1) Click Run.
2) Click on the toolbar.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-75

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter4 in the File name field and select Save.
Partial Results (8 of 424 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-76 Chapter 4 Creating Simple Queries

Solutions to Student Activities (Polls/Quizzes)

4.01 Multiple Answer Poll Correct Answers


Double-click on any data source in your project.
Select Filter and Sort and explore the available tabs.
What functionality do you think is supported by this task?
a. subsetting rows
b. selecting columns
c. calculating new columns
d. controlling the sort order of the rows
e. summarizing data
f. creating a SAS data set

4.02 Quiz Correct Answer


Close the Filter and Sort task and return to the data grid.
Select Query Builder. What options appear to be
available that are not present in the Filter and Sort task?

Possible answers: Query name, Output name,


Computed Columns, Prompt Manager, Tools, Options,
Add Tables, Join Tables

10

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-77

4.03 Quiz Correct Answer


CARS (View 1) is created with 24 rows and six columns.

21

4.04 Multiple Answer Poll Correct Answers


What are the top two distinct values for Type?
a. Hybrid
b. SUV
c. Sedan
d. Sports
e. Truck
f. Wagon

26

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-78 Chapter 4 Creating Simple Queries

4.05 Multiple Choice Poll Correct Answer


What is the average MPG_Highway?
a. 31.7
b. 25.3
c. 28.9
d. 30.5

28

4.06 Multiple Choice Poll Correct Answer


What is the result of the expression given the values
of Var1, Var2, and Var3?
a. . (missing)
b. 3
c. 9
d. 12

Var1 Var2 Var3


9 . 3

Var1+Var2+Var3

41

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-79

4.07 Multiple Choice Poll Correct Answer


What is the result of the expression given the values
of Var1, Var2, and Var3?
a. . (missing)
b. 3
c. 9
d. 12

Var1 Var2 Var3


9 . 3

sum(Var1,Var2,Var3)

43

4.08 Quiz Correct Answer


How does the Filter Data tab change after a query
includes grouped data?

An additional pane labeled Filter the summarized


data is added to the Filter Data tab.

with
without grouping
grouping

55

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-80 Chapter 4 Creating Simple Queries

4.09 Multiple Answer Poll Correct Answers


Which Employee_ID values would be included
in a right join?
a. 120101
b. 120102 Employee_ID Salary Department
120101 163040 Sales Management
c. 120103 120102 108255 Sales Management
120103 87975 Engineering
d. 120104 120105 Administration
e. 120105

Em ployee_Payroll Em ployee_Organization
Employee_ID Salary Employee_ID Department
120101 163040 120101 Sales Management
120102 108255 120102 Sales Management
120103 87975 120103 Engineering
120104 92500 120105 Administration

71

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 5 Creating Summarized
Output

5.1 Generating Summary Statistics ................................................................................ 5-3


Demonstration: Generating Summary Statistics........................................................... 5-5
Exercises............................................................................................................... 5-8

5.2 Creating a Summary Report with the Summary Tables Task ................................. 5-12
Demonstration: Creating a Tabular Summary Report.................................................. 5-14

Exercises............................................................................................................. 5-18

5.3 Solutions ................................................................................................................. 5-21


Solutions to Exercises ........................................................................................... 5-21
5-2 Chapter 5 Creating Summarized Output

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-3

5.1 Generating Summary Statistics

Objectives
Create a summary table.
Create a summary report.
Export summary data to Excel.

Business Scenario
Management wants an HTML report and an Excel file
that include a summary of profits for each product line
and category.

Orion_Profit

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-4 Chapter 5 Creating Summarized Output

Summary Statistics Task


The Summary Statistics task can be used to calculate
summary statistics based on groups within the data. You
can produce reports, graphs, and data sets as output.

Summary Statistics Task


The Summary Statistics task has both a wizard and a
standard task dialog box that can be used to set up results.

These options are available in Advanced View but not in the wizard:
sorting by a classification variable
applying a format to a classification variable
including missing values in calculations
specifying combinations of classification variables

If you convert from the wizard to Advanced View, you cannot switch back to the wizard.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-5

Generating Summary Statistics

Management wants a report that summarizes profits for each product line and category. Management
wants to be able to access an HTML report or an Excel file from a shared network drive.

1. Create a new project and add the orion_profit table.


2. To create the summary report and data set, select Describe Summary Statistics Wizard
in the data grid.

3. In Step 1, you can verify the data and apply a filter if desired. Accept the default settings and click Next.
4. In Step 2, variables are assigned to task roles. Drag Profit into the Summary statistics of pane.
First, drag Product_Line into the For each value of pane, and then add Product_Category.
Click Next.

5. In Step 3, designate the statistics to include in the report. Click Edit.


a. On the Basic tab, clear Standard deviation, Minimum, Maximum, and Number of observations.
b. Select Sum.
c. Change the number of decimal places to 2.
d. Click the Percentile tab and select Median OK.
6. Continuing in Step 3, select the Box and whisker check box to add a graph to the report.
7. Select the Save statistics to data set check box and click Browse. Enter profit_summary
in the File name field and select Save Next.
8. In Step 4, delete the default analysis title and enter Summary of Profit by Product Line/Category.
Click Finish.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-6 Chapter 5 Creating Summarized Output

9. Notice the multiple tabs as part of the task results, including both the Results and Output Data tabs.
Partial Results

10. To create a more descriptive name for the task, right-click Summary Statistics in the project tree
and select Rename. Enter Profit by Product Summary.

11. To automate the export of the output data to Excel, click the Output Data tab. Select Export
Export Summary Statistics for <libname>.ORION_PROFIT As A Step In Project.

12. In Step 1 of the Export Wizard, verify that Summary Statistics for <library>.ORION_PROFIT
is highlighted. Click Next.

13. In Step 2, select Microsoft Excel Workbooks (*.xlsx) as the output file type. Click Next.
14. In Step 3, select the Use labels for column names check box. Click Next.
15. In Step 4, change the name of the output file.
a. Click Browse and navigate to the location that is specified by your instructor.
b. Enter Profit_Summary in the File name field. Select Save.

If you clear the Overwrite existing output check box and a file with the same name already
exists, then a new filename is created. The new filename appends the current date and time
to the existing filename.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-7

16. Click Next to review the export settings and click Finish. The Profit_Summary.xlsx file
is exported and an Export File task is added to the project.

If the project is rerun, both the Summary Statistics and Export File tasks run to update all results.

17. Save the project as Chapter5.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-8 Chapter 5 Creating Summarized Output

Exercises

Level 1

1. Creating a Summary Report of Salary by Department


Use the Summary Statistics Wizard to generate a report that analyzes the salaries of all employees
by Department.
a. In the Chapter5 project, add the employee_master table.
If you do not have the Chapter5 project, you can create a new project.

b. Use the Summary Statistics Wizard to generate a report on the Salary column by Department.
c. Include the mean, minimum, maximum, and median salary for each group and round values
to the nearest dollar.
d. Create a SAS data set named salary_stats that includes the calculated statistics.
e. Enter Summary Statistics for Salary by Department as the title and delete the footnote.
f. Submit the task and view the report. Rename the task Salary by Dept Summary.
Partial Results

g. As a step in the project, export the output data to an Excel file named SalaryStats.xlsx.
h. Save the Chapter5 project.

Level 2

2. Creating a Summary Report of Salary by Department and State


Use the Summary Statistics task to create a report that summarizes employee salaries by department
and state.

a. In the Chapter5 project, add the employee_master table if necessary.


b. Use the Summary Statistics Wizard to summarize Salary by Department first, and then by State.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-9

c. Include the mean, minimum, maximum, and median salary for each group and round values
to two decimal places.
d. Enter Summary Statistics for Salary by Department and State as the title and delete the
footnote.
e. Submit the task and view the report. Rename the task Salary by Dept, State Summary.
Partial Results

f. Modify the task to generate multiple reports for all combinations of the two classification
variables. In the project tree or process flow, right-click the Salary by Dept, State Summary
icon and select Open Open in Advanced View to open the Summary Statistics task.

g. Select Results from the Selection pane. Select All ways in the Combinations of classification
variables drop-down list.

h. Submit the report. Click Yes when you are prompted to replace the results from the previous run.
Verify that four tables are included in the report, that is, one for each combination of the
classification variables.

i. Modify the task again to include only the second and third tables from the previous results .
Summarize Salary by Department first and Salary by State second. Run the task and replace
the results. Save the Chapter5 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-10 Chapter 5 Creating Summarized Output

Partial Results

Challenge

3. Modifying the Summary Statistics Task Code to Include an Additional Statistic


Insert custom code into the SAS program generated by the Summary Statistics task to calculate
the skewness statistic for employee salary by country.
a. In the Chapter5 project, add the employee_master table if necessary.
b. Use the Summary Statistics Wizard to create a report based on the employee_master table.
Rename the task Salary by Country Summary.
Partial Results

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-11

c. Reopen the task in Advanced View and modify the underlying code in the Salary by Country
Summary task to add the skewness statistics in the report. Add the SKEWNESS keyword directly
after other listed statistics.
Skewness is a measure that indicates to what degree the distribution of data values has
a longer tail to the left or to the right. For the salary distribution for both US and AU,
there are a few extreme values at the high end and a concentration of values at the low
end of the distribution, so the right tail of the distribution curve is longer (right-skewed).
For such data, the skewness statistic is greater than zero. If the data is left-skewed, the
skewness statistic is less than zero.
d. Run the task and replace the results. Verify that the additional skewness statistic was added to the
report. Save the Chapter5 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-12 Chapter 5 Creating Summarized Output

5.2 Creating a Summary Report with the


Summary Tables Task

Objectives
Access the Summary Tables task.
Specify a table layout and statistics.
Define headings for columns and rows.
Assign a label for missing values.
Add titles to the report.
Generate the tabular summary report.

12

Business Scenario
To better understand customer purchasing, the Orion
marketing group requested a report that summarizes total
profits for each customer age group and product category.

13

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.2 Creating a Summary Report w ith the Summary Tables Tas k 5-13

Summary Tables
The Summary Tables Wizard or task can be used
to generate a tabular summary report.

14

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-14 Chapter 5 Creating Summarized Output

Creating a Tabular Summary Report

Using the orion_profit table, create a tabular summary report to display the sum of profit for each
product category and customer age group.

1. In the Chapter5 project, double-click the orion_profit icon in the project tree or process flow
to open it in the data grid.

2. Select Describe Summary Tables Wizard from the data grid.


3. In Step 1, verify that the active data source is the orion_profit table. Click Next.
4. In Step 2, analysis variables and statistics are assigned. To calculate the sum of profit, select
Add Profit.

5. To apply a format so that the values in the table appear as currency values, click Browse.
Select Currency from the Categories pane and DOLLARw.d from the Formats pane. Change
the overall width to 8 and leave the number of decimal places as 0. Click OK Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.2 Creating a Summary Report w ith the Summary Tables Tas k 5-15

6. In Step 3, classification variables are assigned to define the rows and columns of the table. Select
Add Customer_Age_Group in the Columns pane, and select Add Product_Category
in the Rows pane. Click Next.

7. In Step 4, verify that Grand total only is selected for both rows and columns. Click Next.
8. Click Next twice to proceed through the final two steps. Click Finish to view the intermediate results.

9. Further modifications can be made to improve the display of the report in the Summary Tables
Wizard. On the Results tab, select Modify Task to reopen the wizard.
10. To delete the Profit and Sum headings, click Next to advance to Step 2. Change the value in the
Analysis variable labels and Statistics labels fields to hidden.
11. Click Next to advance to Step 3. To group Product_Category by Product_Line, select Add
Product_Line in the Rows box. Select Product_Line and click to move it to the top of the list.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-16 Chapter 5 Creating Summarized Output

12. To delete the labels for Product_Category, Product_Line, and the extra blank space that is included
in the first row of the table, select More Options. Click the Hide the row headers check box.
Click OK Next.
13. To add subtotals for each value of Product_Line, change the value in the Rows field to Totals at
each level.

14. Click Finish. When you are prompted to replace the results, click Yes.

15. To further modify the appearance of the table, the Advanced View of the Summary Tables task must
be used. Right-click the Summary Tables Wizard icon in the project tree or process flow.
Select Open Open in Advanced View.
16. Select Summary Tables in the Selection pane. To change the column heading for
Customer_Age_Group, right-click Customer_Age_Group in the Preview area and select
Heading Properties.

17. In the Heading Properties window, enter Profit by Customer Age Group in the Label field. Click
OK.

If you delete a label entirely, the box is also removed from the final report.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.2 Creating a Summary Report w ith the Summary Tables Tas k 5-17

18. Change the column heading for the Product_Line subtotals by right-clicking the Total label
and selecting Heading Properties.

19. Enter Product Line Subtotal in the Label field. Click OK.
20. To highlight the subtotals with a different color background and font, right-click Total (the subtotals
for Product_Line) and select Data Value Properties.
21. In the Data Value Properties window, click the Font tab. Select the Bold Italic font style and light
yellow for the background color. Click OK.
22. To highlight the grand total row, right-click Total (the last row of the report) and select Heading
Properties. On the Font tab, select the Bold font style and 3 for the size. Click OK.

23. Right-click Total again and select Data Value Properties. On the Font tab, select the Bold font style
and 3 for the size. Click OK.

24. To specify a label for missing values, right-click anywhere on the table and select Table Properties.
25. In the Table Properties window, click the General tab. Delete the default label in the Label for
missing values field and enter **. Click OK.

26. Click Run to generate the final report. Click Yes when you are prompted to replace the results.

27. Save the Chapter5 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-18 Chapter 5 Creating Summarized Output

Exercises

Level 1

4. Creating a Summary Tables Report with Multiple Statistics


Use the Summary Tables task to generate a report that displays the minimum and maximum salary
for each country and department.
a. In the Chapter5 project, add the employee_master table if necessary.
If you do not have the Chapter5 project, you can create a new project.

b. Open the Summary Tables Wizard. In Step 2, add Salary to the Analysis variables list two times.
Select Minimum for the first statistic and Maximum for the second.
c. Hide the analysis variable labels and apply the DOLLARw.d format to the table with 10
for the overall width and 0 for the decimal places.

d. Add Country in the Columns pane and Department in the Rows pane. Hide the row headings.
e. Eliminate the totals for both the rows and columns.
f. Generate the report and examine the results.

g. Modify the Summary Tables task by opening it in Advanced View. Modify the heading properties
for the Minimum and Maximum columns to display Low and High.

h. Modify the heading properties for Country to display Salary Ranges by Country.
i. Modify the table properties to display missing values as a single hyphen.
j. Change the task label to Salary Ranges by Country.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.2 Creating a Summary Report w ith the Summary Tables Tas k 5-19

k. Generate the report and save the Chapter5 project.

Level 2

5. Creating a Summary Tables Report with Multiple Statistics and Highlighting


Use the Summary Tables task to generate a report that displays the frequency, percent of column
frequency, and percent of column sum by department for each city in Australia.
a. In the Chapter5 project, open the employee_master table and the Summary Tables Wizard.

b. Edit the data so that only employees from Australia are included in the report.
c. Add the Salary variable as the analysis variable three times. Select the first statistic as
Frequency, the second statistic as % of Column Frequency, and the third statistic as
% of Column Sum. Hide the analysis variable label.
d. Add City as the column classification variable and Department as the row classification variable.
Hide the row and column headings.
e. Enter Summary of Salaries for Australia by Department as the title and delete the footnote.
Submit the task and view the report.

f. Modify the report by opening the task in Advanced View. Use the Summary Tables preview
to delete ColPctN from the Total column.
Hint: Delete Salary first and then delete ColPctN.
g. Modify the headings to match the final output below. Change the background color of the data
values in the Total row and Total column to light orange.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-20 Chapter 5 Creating Summarized Output

h. Change the task label to AU Salary Report. Generate the report and save the Chapter5 project.

Challenge

6. Creating and Applying a Custom Percentage Format


You might want to display a percent sign (%) after the percentage values in your table created by the
Summary Tables task. If you use the PERCENTw.d format, it multiplies data values by 100, and then
adds a percent sign (%) to the end of the formatted value. The Summary Tables task already
multiplied the values by 100 to compute the percent. Therefore, if you use the PERCENTw.d format
to format the values, they are incorrect. Because you do not want the value multiplied by 100, you
need to create a picture format. Use PROC FORMAT to add the percent sign to the value.
a. Complete the Level 2 exercise.
b. Open and run the e105e06 SAS program. This program creates a user-defined format named
MYPCT that rounds values to the nearest tenth and adds a percent sign.

c. Modify AU Salary Report, which was created in the Level 2 exercise. Apply the MYPCT format
by modifying the data value properties for all percentage columns in the report.
Look for the User Defined category in the Format window.

d. Generate the report and save the Chapter5 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-21

5.3 Solutions
Solutions to Exercises
1. Creating a Summary Report of Salary by Department
Use the Summary Statistics Wizard to generate a report that analyzes the salaries of all employees
by Department.

a. In the Chapter5 project, add the employee_master table.

If you do not have the Chapter5 project, you can create a new project.

1) If you need to create a new project, select File New Project.


2) Select File Open Data and navigate to the location of the course data.
3) Select employee_master Open.
b. Use the Summary Statistics Wizard to generate a report on the Salary column by Department.

1) In the data grid, select Describe Summary Statistics Wizard.


2) In Step 1, verify that the data being processed is employee_master. Click Next.
3) In Step 2, drag the Salary column to the Summary statistics of pane and the Department
column to the For each value of pane. Click Next.

c. Include the mean, minimum, maximum, and median salary for each group and round values
to the nearest dollar.
1) In Step 3, click Edit to open the Edit Statistics window. On the Basic tab, clear the Standard
deviation and Number of observations check boxes. Use the drop-down box to select 0 for
the number of decimal places.
2) Click the Percentile tab and select the Median statistic. Click OK to close the Edit Statistics
window.
d. Create a SAS data set named salary_stats that includes the calculated statistics.
1) In Step 3, select the Save statistics to data set check box.
2) Click Browse.
3) Enter salary_stats in the File name field and select Save.
4) Click Next.
e. Enter Summary Statistics for Salary by Department as the title and delete the footnote.
In Step 4, add the title Summary Statistics for Salary by Department in the Analysis pane,
and delete the footnote.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-22 Chapter 5 Creating Summarized Output

f. Submit the task and view the report. Rename the task Salary by Dept Summary.
1) Click Finish. In the project tree, right-click the Summary Statistics Wizard icon and select
Properties.
2) Change the label to Salary by Department Summary. Click OK to close the Properties
window.
Partial Results

g. As a step in the project, export the output data to an Excel file named SalaryStats.xlsx.
1) Click the Output Data tab.
2) Select Export Export Summary Statistics for <libname>.EMPLOYEE_MASTER
As A Step In Project.
3) In the Export Wizard, click Next to advance to Step 2.
4) In Step 2, select Microsoft Excel Workbooks (*.xlsx). Click Next.
5) In Step 3, select the Use labels for column names check box. Click Next.
6) In Step 4, click Browse and navigate to the location that is indicated by your instructor.
7) Enter SalaryStats in the File name field and select Save. Click Next.
8) In Step 5, verify the selections and click Finish.
h. Save the Chapter5 project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter5 in the File name field and select Save.
2. Creating a Summary Report of Salary by Department and State
Use the Summary Statistics task to create a report that summarizes employee salaries by department
and state.
a. In the Chapter5 project, add the employee_master table if necessary.
1) Select File Open Data and navigate to the location of the course data.
2) Select employee_master Open.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-23

b. Use the Summary Statistics Wizard to summarize Salary by Department first, and then by State.
1) In the data grid, select Describe Summary Statistics Wizard.
2) In Step 1, verify that the data being processed is employee_master and click Next.
3) In Step 2, drag the Salary column to the Summary statistics of pane and the Department
and State columns to the For each value of pane. Click Next.

c. Include the mean, minimum, maximum, and median salary for each group and round values
to two decimal places.
1) In Step 3, click Edit to open the Edit Statistics window. On the Basic tab, clear the
Standard deviation and Number of Observations check boxes. Use the drop-down box
to select 2 for the number of decimal places.
2) Click the Percentile tab and select the Median statistic. Click OK to close the Edit Statistics
window.
3) Click Next.

d. Enter Summary Statistics for Salary by Department and State as the title and delete
the footnote.
In Step 4, add the title Summary Statistics for Salary by Department and State
in the Analysis pane, and delete the footnote.
e. Submit the task and view the report. Rename the task Salary by Dept, State Summary.
1) Click Finish and review the results.
2) In the project tree or process flow, right-click the Summary Statistics Wizard icon and select
Properties.
3) Change the label to Salary by Dept, State Summary. Click OK to close the Properties window.
Partial Results

f. Modify the task to generate multiple reports for all combinations of the two classification
variables. In the project tree or process flow, right-click the Salary by Dept, State Summary
icon and select Open Open in Advanced View to open the Summary Statistics task.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-24 Chapter 5 Creating Summarized Output

g. Select Results from the Selection pane. Select All ways in the Combinations of classification
variables drop-down list.
h. Submit the report. Click Yes when you are prompted to replace the results from the previous run.
Verify that four tables are included in the report, that is, one for each combination of the
classification variables.

Click Run Yes.


i. Modify the task again to include only the second and third tables from the previous results .
Summarize Salary by Department first and Salary by State second. Run the task and replace
the results. Save the Chapter5 project.

1) In the Results window, click the Modify Task button to reopen the task.
2) Select the Results pane.
3) Use the Combination of classification variables drop-down box to select Specify ways.
In the Specify ways box, enter 1.
4) Click Run Yes when you are prompted to replace the results.
5) Click on the toolbar.

6) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter5 in the File name field and select Save.

Partial Results

3. Modifying the Summary Statistics Task Code to Include an Additional Statistic


Insert custom code in the SAS program generated by the Summary Statistics task to calculate
the skewness statistic for employee salary by country.

a. In the Chapter5 project, add the employee_master table if necessary.


1) Select File Open Data and navigate to the location of the course data.
2) Select employee_master Open.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-25

b. Use the Summary Statistics Wizard to create a report based on the employee_master table.
Rename the task Salary by Country Summary.
1) In the data grid, select Describe Summary Statistics Wizard.
2) In Step 1, verify that the data being processed is employee_master and click Next.
3) In Step 2, drag the Salary column to the Summary statistics of pane and the Country column
to the For each value of pane. Click Next.
4) In Step 3, click Edit to open the Edit Statistics window. On the Basic tab, use the drop-down
box to select 2 for the number of decimal places. Click OK to close the Edit Statistics
window. Select the Histogram check box. Click Next.

5) In Step 4, enter the title Salary by Country Summary in the Analysis pane. Delete the
histogram title and footnote.

6) Click Finish and view the report.


7) Right-click Summary Statistics under EMPLOYEE_MASTER in the project tree and select
Rename. Enter Salary by Country Summary.

Partial Results

c. Reopen the task in Advanced View and modify the underlying code in the Salary by Country
Summary task to add the skewness statistics in the report. Add the SKEWNESS keyword directly
after other statistics listed.
1) Right-click the Salary by Country Summary task in the project tree or process flow and
select Open Open in Advanced View.
2) Select Preview Code and select the Show custom code insertion points check box.
3) Scroll down to find the end of the PROC MEANS statement. Click to insert custom code
between the N option and the semicolon. Enter skewness.
4) Close the Code Preview window.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-26 Chapter 5 Creating Summarized Output

d. Run the task and replace the results. Verify that the additional skewness statistic was added
to the report. Save the Chapter5 project.
1) Click Run Yes.
2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter5 in the File name field and select Save.

4. Creating a Summary Tables Report with Multiple Statistics


Use the Summary Tables task to generate a report calculating the minimum and maximum salary
for each country and department.
a. In the Chapter5 project, add the employee_master table.

If you do not have the Chapter5 project, you can create a new project.

1) Select File Open Data and navigate to the location of the course data.
2) Select employee_master Open.
b. Open the Summary Tables Wizard. In Step 2, add Salary to the Analysis variables list two times.
Select Minimum for the first statistic and Maximum for the second.

1) In the project tree or process flow, double-click the employee_master table to open the data
grid. Select Describe Summary Tables Wizard.

2) In Step 1 of the wizard, confirm that the employee_master table is being processed. Click Next.
3) In Step 2, click Add and select Salary from the list. Repeat these steps so that Salary is listed
twice. Notice at this point that the statistic for both lines is Sum.

4) Click the Statistic column for the first Salary row. Use the drop-down menu to select
the Minimum statistic.

5) Click the Statistic column for the second Salary row. Use the drop-down menu to select
the Maximum statistic.
c. Hide the analysis variable labels and apply the DOLLARw.d format to the table with 10
for the overall width and 0 for the decimal places.
1) For the Analysis variable labels, use the drop-down menu to select hidden.
2) Click Browse to open the Select Column Format window. Select the Currency category
and select the DOLLARw.d format. Use the spin boxes to set the overall width to 10 and
the decimal places to 0. Click OK to close the Select Column Format window. Click Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-27

d. Add Country in the Columns pane and Department in the Rows pane. Hide the row headings.
1) In Step 3, click Add for the Columns section and select the Country column from the list.
2) Click Add in the Rows section and select the Department column from the list.
3) Select More Options and select the Hide the row headers check box. Click OK to close
the More Options window.

4) Click Next.
e. Eliminate the totals for both the rows and columns.
In Step 4, for both the column and row totals, use the drop-down menu to select None.
f. Generate the report and examine the results.
Click Finish.

g. Modify the Summary Tables task by opening it in Advanced View. Modify the heading properties
for the Minimum and Maximum columns to display Low and High.
1) In the project tree or process flow, right-click the Summary Tables icon under the
employee_master table and select Open Open in Advanced View.
2) Select the Summary Tables pane.
3) Right-click either of the Min statistics headings and select Heading Properties. In the Heading
Properties for Min window, enter Low in the Label field. Click OK to close the window.

4) Right-click either of the Max statistics headings and select Heading Properties. In the Heading
Properties for Max window, enter High in the Label field. Click OK to close the window.

h. Modify the heading properties for Country to display Salary Ranges by Country.
1) Right-click the Country heading and select Heading Properties.
2) In the Heading Properties for Country window, enter Salary Ranges by Country in the Label
field. Click OK to close the window.

i. Modify the table properties to display missing values as a single hyphen.


1) Right-click in the table and select Table Properties.
2) In the Table properties window, delete the period and enter a hyphen (-) in the Label for
missing value field. Click OK to close the window.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-28 Chapter 5 Creating Summarized Output

j. Change the task label to Salary Ranges by Country.


1) Select Properties in the Selection pane and click Edit.
2) Enter Salary Ranges by Country in the Label field and click OK.
k. Generate the report and save the Chapter5 project.
1) Click Run. Click Yes when you are prompted to replace the results. View the updated report.

2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter5 in the File name field and select Save.

5. Creating a Summary Tables Report with Multiple Statistics and Highlighting


Use the Summary Tables task to generate a report that calculates the frequency, percent of column
frequency, and percent of column sum by department for each city in Australia.

a. In the Chapter5 project, open the employee_master table and the Summary Tables Wizard.
1) In the project tree or process flow, double-click the employee_master table to open
the data grid.

2) Select Describe Summary Tables Wizard.


b. Edit the data so that only employees from Australia are included in the report.
1) In Step 1 of the wizard, confirm that the employee_master table is being processed.
Click Edit.

2) In the first field of the Edit Data and Filter window, use the drop-down menu to select
the Country column.

3) In the second field, use the drop-down menu to select Equal to. In the third field, click .
Select AU and click OK twice.

4) Click Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-29

c. Add the Salary variable as the analysis variable three times. Select the first statistic as
Frequency, the second statistic as % of Column Frequency, and the third statistic as
% of Column Sum. Hide the analysis variable label.
1) In Step 2, click Add and select Salary from the list. Repeat these steps twice so that Salary
is listed three times. Notice at this point that the statistic for all lines is Sum.

a) Click in the statistic column for the first Salary row. Use the drop-down menu to select
the Frequency statistic.

b) Click in the statistic column for the second Salary row. Use the drop-down menu to select
the % of Column Frequency statistic.

c) Click in the statistic column for the second Salary row. Use the drop-down menu to select
the % of Column Sum statistic.

2) In the Analysis variable labels field, use the drop-down menu to select hidden.
3) Click Next.
d. Add City as the column classification variable and Department as the row classification variable.
Hide the row and column headings.

1) In Step 3, click Add for the Columns section and select the City column from the list.
2) Click Add in the Rows section and select the Department column from the list.
3) Click the More Options button. Select the Hide the row headers and the Hide the column
headers check boxes. Click OK to close the More Options window.

4) Click Next three times to move to Step 6 of the wizard.


e. Enter Summary of Salaries for Australia by Department as the title and delete the footnote.
Submit the task and view the report.

1) In Step 6, delete the current text in the Table Titles field, and enter Summary of Salaries
for Australia by Department.
2) Delete the text in the Footnote field.
3) Click Finish and view the report.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-30 Chapter 5 Creating Summarized Output

f. Modify the report by opening the task in Advanced View. Use the Summary Tables preview
to delete ColPctN from the Total column.
Hint: Delete Salary first and then delete ColPctN.
1) In the project tree or process flow, right-click the Summary Tables icon under
the employee_master table. Select Open Open in Advanced View.
2) Select the Summary Tables pane.
3) In the Total column, right-click the Salary cell above the ColPctN statistic and select
Remove Cells. Right-click the ColPctN statistic and select Remove Cells. This deletes
% of Column Frequency from the Total column.
4) Right-click the ColPctSum statistic under the Total column, and select Heading Properties.
Enter Percent of Total Salaries in the Label field. Click OK.

g. Modify the headings to match the final output below. Change the background color of the data
values in the Total row and Total column to light orange.
1) Right-click either N statistic under the city variable, and select Heading Properties.
Enter Employee Count in the Label field. Click OK.
2) Right-click either ColPctN statistic under the city variable, and select Heading Properties.
Enter Percent of Employees in the Label field. Click OK.
3) Right-click either ColPctSum statistic under the city variable, and select Heading Properties.
Enter Percent of Salaries in the Label field. Click OK.
4) Right-click the N statistic under the Total column, and select Heading Properties.
Enter Total Employees in the Label field. Click OK.
5) Select the column Total heading. Right-click and select Data Value Properties. In the Data
Values Properties for All window, click the Font tab. Use the drop-down menu for the
Background color to select Light Orange. Click OK.
6) Select the row Total heading. Right-click and select Data Value Properties. In the Data
Values Properties for All window, click the Font tab. Use the drop-down menu for
the Background color to select Light Orange. Click OK.

h. Change the task label to AU Salary Report. Generate the report and save the Chapter5 project.
1) Select Properties in the Selection pane and click Edit.
2) Enter AU Salary Report in the Label field and click OK.
3) Click Run Yes when you are prompted to replace the results.
4) Click on the toolbar.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-31

5) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter5 in the File name field and select Save.

6. Creating and Applying a Custom Percentage Format


You might want to display a percent sign (%) after the percentage values in your table created
by the Summary Tables task. If you use the PERCENTw.d format, it multiplies data values by 100,
and then adds a percent sign (%) to the end of the formatted value. The Summary Tables task already
multiplied the values by 100 to compute the percent. Therefore, if you use the PERCENTw.d format
to format the values, they are incorrect. Because you do not want the value multiplied by 100, you
need to create a picture format. Use PROC FORMAT to add the percent sign to the value.
a. Complete the Level 2 exercise.
Refer to the solutions for the previous exercise.
b. Open and run the e105e06 SAS program. This program creates a user-defined format named
MYPCT that rounds values to the nearest tenth and adds a percent sign.

1) Select File Open Program.


2) Navigate to the location of the course data and select e105e06 Open.
3) On the Program tab, click Run.
c. Modify AU Salary Report, which was created in the Level 2 exercise. Apply the MYPCT format
by modifying the data value properties for all percentage columns in the report.

Look for the User Defined category in the Format window.

1) Right-click the AU Salary Report task that was produced in the previous exercise and select
Modify Summary Tables.

2) Select Summary Tables.


3) Right-click each ColPctN and ColPctSum column and select Data Value Properties.
4) Click the Format tab and the User Defined category. Highlight the MYPCT. format. Click OK.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-32 Chapter 5 Creating Summarized Output

d. Generate the report and save the Chapter5 project.


1) Click Run Yes when you are prompted to replace the results. View the updated report.

2) Click on the toolbar.

3) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter5 in the File name field and select Save.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 6 Using Prompts in Tasks
and Queries

6.1 Prompting in Projects................................................................................................ 6-3

6.2 Creating and Using Prompts in Tasks ...................................................................... 6-6


Demonstration: Prompting in Tasks ......................................................................... 6-10

Exercises............................................................................................................. 6-13

6.3 Creating and Using Prompts in Queries ................................................................. 6-15


Demonstration: Prompting in Queries ...................................................................... 6-18

Exercises............................................................................................................. 6-21

6.4 Solutions ................................................................................................................. 6-25


Solutions to Exercises ........................................................................................... 6-25
Solutions to Student Activities (Quizzes/Polls) ........................................................... 6-35
6-2 Chapter 6 Using Prompts in Tasks and Queries

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.1 Prompting in Pr ojects 6-3

6.1 Prompting in Projects

Objectives
Define a prompt.
Illustrate examples of prompts.

Prompts
Prompts enable you to request input from the user
when a task, query, or SAS program is run.

Prompts create SAS macro variables that can be used in tasks, queries, SAS programs, and SAS Stored
Processes. Values for the macro variables are assigned at run time, and are typically based on user input.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-4 Chapter 6 Using Prompts in Tasks and Queries

Prompt Examples
Possible prompts include the following:
variable lists
date
values

color
selection

text or
numeric entry single or multiple
selection from a list
5

Prompt Manager
Prompts are stored in a project. You can use the Prompt
Manager section of the Resources pane to create, edit,
and delete prompts.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.1 Prompting in Pr ojects 6-5

Setup for the Poll


1. Open the e106a01.egp project.
2. Select Yes when you are prompted to run
the Autoexec process flow.
3. In the Specify Values for Project Prompts window,
do the following:
On the Customer Age Group menu, select
31-45 years.
In the Orders with profits exceeding field,
enter 100.
4. Run the query.

6.01 Multiple Choice Poll


How many rows were returned in the query result?
a. 0
b. 58
c. 76
d. 617

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-6 Chapter 6 Using Prompts in Tasks and Queries

6.2 Creating and Using Prompts in Tasks

Objectives
List steps for adding a prompt to a task.
Define general prompt properties.
Define the prompt type and values.
Retrieve prompt values from a data source.
Use prompts in a task.

11

Business Scenario
The CEO at Orion Star wants the ability to view a pie
chart that illustrates the distribution of profit based
on different categories. He does not want a separate
pie chart for each category. He prefers to be able
to access a single task, and at run time, specify
the variable to analyze.

12

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.2 Creating and Us ing Prompts in Tasks 6-7

Prompts in Tasks
Adding a prompt to a task is a two-step process.
1. Create a prompt.
2. Use the prompt definition in a task.

13

Creating a Prompt: General


When you create a prompt, you must first specify
the general properties of the prompt, such as the name,
displayed text, description, and options.

14

On the General tab, enter a unique name for the prompt in the Name field. Names can contain only
alphanumeric characters and underscores, cannot begin with a number, and cannot exceed 32 characters.
In the Displayed text field, enter the text that the user sees when the prompt is run. By default,
the displayed text is the same as the prompt name.
In the Description field, enter an optional description that is displayed when the prompt is run.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-8 Chapter 6 Using Prompts in Tasks and Queries

You can select any of the following options:

Hide from user Specifies whether the user is able to view the prompt and its value.

Requires a non-blank value Specifies whether the user is required to provide a non-blank value.

Read-only values Specifies whether the user can change the value of the prompt.

Use prompt value Specifies whether the value or values that a user assigns to a
throughout project prompt can be used by other tasks, queries, and programs in the
project. If you do not select this option, then the values are deleted
after the code is run.

6.02 Multiple Answer Poll


Which of the following are valid names for prompts?
a. Select Country
b. Select_a_Category
c. Profit$Segments
d. 1stQtrValues
e. Qtr1Values

15

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.2 Creating and Us ing Prompts in Tasks 6-9

Creating a Prompt: Prompt Type and Values


By selecting
Variable as the
prompt type, you
can assign the
prompt to task
roles in tasks.
The prompt value
list can be
populated by the
variable names
from an existing
data source.

17

For more details about each available prompt type, select Help SAS Enterprise Guide Help.
On the Contents tab, expand Working with Prompts Creating a Prompt and select
Selecting the prompt type and its values.

Using a Prompt: Variable Type


Variable type prompts appear in tasks as an additional
variable that can be assigned to task roles or used in titles
and footnotes.

18

In the code, macro variables are referenced by preceding the prompt name with & (an ampersand).

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-10 Chapter 6 Using Prompts in Tasks and Queries

Prompting in Tasks

Create a variable prompt for the Pie Chart task. This prompt enables the CEO at Orion Star to view a pie
chart that illustrates the distribution of profit based on different categories.

1. Create a new project and add the orion_profit data set.


2. Begin creating the prompt that lists the variables that can be used to segment the slices of the pie
chart. Click the Prompt Manager button in the Resources pane. Select Add.

If you do not see the Prompt Manager, select View Prompt Manager.

3. On the General tab, enter ProfitCategories in the Name field. Enter Select a variable to segment
the pie chart: in the Displayed text field. Select the Requires a non-blank value check box.

4. On the Prompt Type and Values tab, change the prompt type to Variable so that the prompt is
accessible in tasks. To populate the prompt list with variables from the orion_profit data set,
select Load Values.

By default, the selected Variable type value is Character. If you select Load Values,
all character columns from the selected table are added to the list. You can use the Variable
type pane to select other column types.

5. In the Open file window, select Project orion_profit Open. All character variables from
the orion_profit data set are entered into the list. Because Customer_Name, Supplier_Name and
Product_Name are not appropriate variables to use in the Bar Chart task, remove them from the list
by highlighting the variables and clicking .

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.2 Creating and Us ing Prompts in Tasks 6-11

6. To assign a default value, select the Default value check box and double-click Product_Category.
Click OK to close the Add New Prompt window.

7. In the data grid, select Graph Pie Chart Wizard.


8. Click Next to advance to Step 2. Select the ProfitCategories prompt in the Slice drop-down list
and Profit in the Slice size drop-down list. Click Next.

9. In Step 3, select 3D chart. Verify that the Slice name and Data value check boxes are selected.
To add the percentage on the inside of each slice, select the Percentage check box. Change the value
to Inside. Click Next.

10. In Step 4, delete the default title and enter Profit by &ProfitCategories.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-12 Chapter 6 Using Prompts in Tasks and Queries

11. Click Finish. At the prompt, select Customer_Country Run and examine the results.

A warning symbol might appear on the task icon. This symbol indicates a warning
in the log regarding overlapping text in the graph.

12. On the Results tab, click Refresh. At the prompt, select Product_Category Run.

13. Save the project as Chapter6.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.2 Creating and Us ing Prompts in Tasks 6-13

Exercises

Level 1

1. Creating a Variable Type Prompt and Using It in a Bar Chart


Create a prompt so that the user can select a variable from the employee_master table for
the charting variable.
a. In the Chapter6 project, add the employee_master table.

If you do not have Chapter6 project, you can create a new project.

b. Use the Prompt Manager to create a new prompt. On the General tab, enter SelectVar in the
Name field and Which column do you want to analyze? in the Displayed text field. Set an
option to require a value for this prompt.

c. On the Prompt Type and Values tab, change the prompt type to Variable.
d. Type or use the Load Values button to populate the Value list box with Employee_Gender, City,
Country, and Department. Assign City as the default value.

e. Use the Bar Chart Wizard to create a three-dimensional horizontal bar chart based on
employee_master. Use the SelectVar prompt to specify the bars. Select Salary as
the variable to control the bar length. Use to set the statistic type as Average.

f. Change the following display attributes:


Color the bars separately.
Display the data labels, and show the average salary.
Change the horizontal axis label to Average Annual Salary.
Assign Average Annual Salary by &SelectVar as the title and delete the footnote.

g. Using the default variable City for the prompt value, run the wizard.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-14 Chapter 6 Using Prompts in Tasks and Queries

Results

To use another charting variable, click the Refresh button in the Graph window
and select another variable in the prompt.
h. Save the Chapter6 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Us ing Prompts in Quer ies 6-15

6.3 Creating and Using Prompts in Queries

Objectives
List prompt types that can be used in query filters.
Retrieve prompt values from a data source.
Use prompts in a query.

24

Business Scenario
Suppliers frequently request a summary of the orders
for their products. Rather than create a task or report
for each supplier, the supplier services representative
at Orion prefers to create a report by choosing a particular
supplier at run time.

25

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-16 Chapter 6 Using Prompts in Tasks and Queries

Using a Prompt: Text, Numeric, Date Types


Text, numeric, and date type prompts can be used
in the Query Builder to filter data.

26

Creating a Prompt in the Query Builder


You can create prompts by accessing the Prompt
Manager directly in the Query Builder.

27

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Us ing Prompts in Quer ies 6-17

Creating a Prompt for a Query


Text, numeric, date,
and time prompt types
can be used to enable
the selection of values
to be used in a filter.
Select Get Values to
load data values from
an existing data
source into the
prompt list.

28

When you create a prompt, you must specify how the values for the prompt are obtained. You use
the Method for populating prompt drop-down list.

You can use these three methods:

User enters values Specifies that the user enters the value or values when the prompt is run.

User selects values Specifies that the user selects from a fixed set of values that you define when
from a static list you create the prompt.

User selects values Specifies that the user selects from a list of unique values. This list is populated
from a dynamic by values from the selected data source when the prompt is run. For this option,
list the data source must be defined in a SAS folder.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-18 Chapter 6 Using Prompts in Tasks and Queries

Prompting in Queries

Create a text prompt and use it in a query to extract orders for a specific supplier. Generate a report for
the orders and include the supplier name in the title.

1. In the Chapter6 project, right-click orion_profit in the project tree or process flow, and select
Query Builder.

2. Enter Choose a Supplier Query in the Query name field. Click Change and enter SupplierOrders
in the File name field. Select Save.

3. On the Select Data tab, add Product_ID, Product_Name, Order_Date, Quantity, and Profit.

4. To build a prompt that enables the selection of a single supplier, select Prompt Manager Add.
5. On the General tab, enter ChooseSupplier in the Name field and Select a Supplier: in the Displayed
text field. Select the Requires a non-blank value and Use prompt value throughout project check
boxes.

Selecting the Use prompt value throughout project check box enables you to use
the prompt value in future tasks.

6. On the Prompt Type and Values tab, verify that the prompt type is Text. Change the method for
populating the prompt to User selects values from a static list. To populate the list with supplier
names from the orion_profit data set, select Get Values.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Us ing Prompts in Quer ies 6-19

7. To define the data source, click Browse Project orion_profit Open.


8. Change the column value in the Unformatted Values pane to Supplier_Name.
9. Select Get values and click to fill the prompt list with all Supplier_Name values.

10. Click OK OK Close to return to the Query Builder.

11. To use the prompt in a filter, click the Filter Data tab. Drag and drop Supplier_Name onto the tab
area. In the New Filter Wizard, verify that the operator is Equal to. Click next to the Value field
and select Prompts &ChooseSupplier. Click Finish.

12. To create a report that includes the name of the selected supplier in the title, select Options. Select
the Override the corresponding default settings in Tools->Options check box and select Report.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-20 Chapter 6 Using Prompts in Tasks and Queries

13. Select Titles in the Selection pane and select the Override the corresponding default settings
in Tools->Options check box. Enter Orders for &ChooseSupplier. Click OK.
14. Click Run. At the prompt, select Carolina Sports Run. Verify that 11 rows are returned.

15. Select Refresh to run the query again and select a different supplier. Save the Chapter6 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Us ing Prompts in Quer ies 6-21

Exercises

Level 1

2. Creating a Text Prompt and Using It in a Query


Use the Prompt Manager to create a text prompt that enables the user to select a city. Use the prompt
to filter the employee_master table in a query.
a. In the Chapter6 project, add the employee_master table if necessary.

If you do not have the Chapter6 project, you can create a new project.

b. Open the Query Builder. Name the query Select City Query and the output table select_city.
Include all columns in the query.
c. Use the Prompt Manager to create a new prompt. On the General tab, enter SelectCity
in the Name field and Select a City: in the Displayed text field. Set an option to require
a value for this prompt.

d. On the Prompt Type and Values tab, verify that Text is the prompt type. In the Method for
populating the prompt drop-down list, select User selects values from a static list.
e. Click the Get Values button to populate the prompt list with the distinct values of City
from the employee_master data set. Set the default value as Miami-Dade.
f. On the Filter Data tab, create a filter on the City column so that the value is equal to the prompt,
SelectCity.
g. Run the query and use the default city, Miami-Dade.
Partial Results (8 of 85 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-22 Chapter 6 Using Prompts in Tasks and Queries

h. Click to rerun the query. Select Sydney in the prompt and click Run.

Partial Results (8 of 47 rows)

i. Save the Chapter6 project.

Level 2

3. Creating a Date Range Prompt and Using It in a Query


Use the Prompt Manager and the Query Builder to create a query that prompts the user to subset
the employee_master table for a specified range of hire dates.

a. In the Chapter6 project, create a query based on the employee_master table. Name the query
Employee Hire Date Query and name the output table employee_hire_date. Add all columns
to the query.
b. Create a prompt that enables a selection for a range of dates. Name the prompt DateRange
and the displayed text Select a beginning and end date for the employee hire date range.
The prompt type should be Date range and the date type should be Day.
c. Create a filter on the Employee_Hire_Date column. Set the operator to In a range.
Use the prompt that you created to select the date range at execution.

d. Sort the results by ascending Employee_Hire_Date.


e. Submit the query and set the range of dates from January 1, 2010 to December 31, 2010.
Partial Results

f. Save the Chapter6 project.


4. Creating a Multiple Value Prompt
Use the Prompt Manager to create a multiple value selection prompt for the City column.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Us ing Prompts in Quer ies 6-23

a. In the Chapter6 project, create a prompt named SelectCities that enables the selection of one
or more cities and appears as follows:

If you do not have the Chapter6 project, you can create a new project and add
the employee_master data set.
b. Create a query based on the employee_master table. Name the query Multi-Cities Query
and the output table Multi_Cities. Include all columns on the Select Data tab.

c. Build a filter that includes only those cities that are in the list of cities selected in the prompt.
d. Run the query and select Melbourne and Sydney for the cities. Verify the results and save
the Chapter6 project.

Partial Results (8 of 73 rows)

Challenge

5. Using a Prompt in a SAS Program


Create a prompt that can be used as a macro variable in a SAS program.
a. In the Chapter6 project, add the e106e5.sas program. Notice that the program includes
a WHERE statement that filters the data to include only employees in the Administration
Department. Run the program and verify that 31 rows are returned.

b. Create a prompt named SelectDept that enables the selection of any department
from the employee_master table. The prompt should appear as follows:

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-24 Chapter 6 Using Prompts in Tasks and Queries

c. Modify the WHERE statement in the SAS program to reference the SelectDept prompt
(macro variable) rather than Department.
d. Modify the properties of the program by clicking on the Program toolbar.
Add the &SelectDept prompt to the properties.
e. Run the program with Engineering as the selected value and verify the results. Save
the Chapter6 project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-25

6.4 Solutions
Solutions to Exercises
1. Creating a Variable Type Prompt and Using It in a Bar Chart
Create a prompt so that the user can select a variable from the employee_master table for
the charting variable.

a. In the Chapter6 project, add the employee_master table.

If you do not have the Chapter6 project, you can create a new project.

1) Select File Open Data and navigate to the location of the course data.
2) Select employee_master Open.
b. Use the Prompt Manager to create a new prompt. On the General tab, enter SelectVar in the
Name field and Which column do you want to analyze? in the Displayed text field. Set an
option to require a value for this prompt.
1) Select View Prompt Manager to open the Prompt Manager window in the lower left part
of the Enterprise Guide session.

2) Select Add to open the Add New Prompt window.


3) Enter SelectVar in the Name field and Which column do you want to analyze?
in the Displayed text field.
4) Select the Requires a non-blank value check box.
c. On the Prompt Type and Values tab, change the prompt type to Variable.
1) Click the Prompt Type and Values tab.
2) Select Variable from the Prompt type drop-down list.
d. Type or use the Load Values button to populate the Value list box with Employee_Gender, City,
Country, and Department. Assign City as the default value.

1) Select Load Values. In the Open File window, select Project employee_master Open.
2) All character variables in the employee_master table are added in the Variable List pane.
Hold down the Ctrl key and select Employee_Name, Street_Name, State, Postal_Code,
and Job_Title. Click .

3) Select the Default value check box in the Options pane. Double-click City in the Values list.
4) Click OK.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-26 Chapter 6 Using Prompts in Tasks and Queries

e. Use the Bar Chart Wizard to create a three-dimensional horizontal bar chart based on
employee_master. Use the SelectVar prompt to specify the bars. Select Salary as
the variable to control the bar length. Use to set the statistic type as Average.

1) Select employee_master in the project tree or process flow. Select Tasks Graph
Bar Chart Wizard.
2) In Step 1, verify that employee_master is the data set and click Next.
3) In Step 2, select the Horizontal bar chart check box.
4) Use the drop-down menu to select SelectVar as the bars variable.
5) Use the drop-down menu to select Salary as the bar length variable.
6) Click . In the Statistic window, select Average OK.

7) Click Next.
f. Change the following display attributes:
Color the bars separately.
Display data labels, and show the average salary.
Change the horizontal axis label to Average Annual Salary.
Assign Average Annual Salary by &SelectVar as the title and delete the footnote.
1) In Step 3, select the 3D chart check box.
2) Select Bar category from the Color bars by drop-down list.
3) Select the Data labels check box. Use the drop-down list to select Average as the displayed
statistic.

4) Select Axis Labels. In the Bar length field, enter Average Annual Salary.
5) Click OK Next.
6) In Step 4, delete the default title and enter Average Annual Salary by &SelectVar.
g. Using the default variable City for the prompt value, run the wizard.
1) Click Finish.
2) In the Specify Values for Project Prompts window, verify that City is selected.
3) Click Run and view the results.

To use another charting variable, click the Refresh button in the Graph window
and select another variable in the prompt.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-27

Results

h. Save the Chapter6 project.


1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter6 in the File name field and select Save.
2. Creating a Text Prompt and Using It in a Query
Use the Prompt Manager to create a text prompt that enables the user to select a city. Use the prompt
to filter the employee_master table in a query.

a. In the Chapter6 project, add the employee_master table if necessary.

If you do not have the Chapter6 project, you can create a new project.

1) Select File Open Data and navigate to the location of the course data.
2) Select employee_master Open.
b. Open the Query Builder. Name the query Select City Query and the output table select_city.
Include all columns in the query.
1) Right-click the employee_master table in the project tree or process flow and select
Query Builder.
2) Enter Select City Query in the Query name field.
3) Click Change. In the File name field, enter select_city and select Save.
4) Right-click t1 (employee_master) and select Select All Columns.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-28 Chapter 6 Using Prompts in Tasks and Queries

c. Use the Prompt Manager to create a new prompt. On the General tab, enter SelectCity
in the Name field and Select a City: in the Displayed text field. Set an option to require
a value for this prompt.
1) Select Prompt Manager Add.
2) Enter SelectCity in the Name field.
3) Enter Select a City: in the Displayed text field.
4) Select the Requires a non-blank value check box.
d. On the Prompt Type and Values tab, verify that Text is the prompt type. In the Method for
populating the prompt drop-down list, select User selects values from a static list.
1) Click the Prompt Type and Values tab. Verify that the Prompt type is Text.
2) Use the Method for populating prompt drop-down list to select User selects values from
a static list.
3) Verify that the Number of values field is set to Single value.
e. Click the Get Values button to populate the prompt list with the distinct values of City
from the employee_master data set. Set the default value as Miami-Dade.
1) Select Get Values Browse.
2) Select Project employee_master Open.
3) In the Unformatted Values pane, use the drop-down menu to select City.
4) Select Get Values in the Available values pane. The five city values are displayed.

5) Move all five values to the Selected values pane by clicking .

6) Click OK to close the Get Values window.


7) In the List of values pane, select the radio button in the Default column for Miami-Dade.
8) Click OK Close.
f. On the Filter Data tab, create a filter on the City column so that the value is equal to the prompt,
SelectCity.

1) Drag and drop City into the Filter Data pane. This opens the New Filter window.
2) In Step 1, verify that the operator is set to Equal to.
3) Verify the Generate filter for a prompt value check box is selected.
4) Click next to the Value field. Click the Prompts tab and select &SelectCity.

5) Click Next.
6) Review the summary and Click Finish.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-29

g. Run the query and use the default city, Miami-Dade.


1) Click Run in the Query Builder.
2) Verify that Miami-Dade is the selected city in the Specify Values for Project Prompts window.
Click Run.
3) Verify that the output table has 85 rows.

Partial Results (8 of 85 rows)

h. Click to rerun the query. Select Sydney in the prompt and select Run.

1) Click . The Specify Values for Project Prompt window appears.

2) Use the drop-down menu to select Sydney.


3) Click Run and verify that the output table has 47 rows.
Partial Results (8 of 47 rows)

i. Save the Chapter6 project.


1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter6 in the File name field and select Save.

3. Creating a Date Range Prompt and Using It in a Query


Use the Prompt Manager and the Query Builder to create a query that prompts the user to subset
the employee_master table for a specified range of hire dates.
a. In the Chapter6 project, create a query based on the employee_master table. Name the query
Employee Hire Date Query and name the output table employee_hire_date. Add all columns
to the query.

If you do not have the Chapter6 project, you can create a new project and add the
employee_master data set.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-30 Chapter 6 Using Prompts in Tasks and Queries

1) In the project tree, right-click the employee_master data set and select Query Builder.
2) Enter Employee Hire Date Query in the Query name field.
3) Click Change and enter employee_hire_date in the File name field. Select Save.
4) With the Select Data tab active, right-click t1 (employee_master), and select
Select All Columns.

b. Create a prompt that enables a selection for a range of dates. Name the prompt DateRange
and the displayed text Select a beginning and end date for the employee hire date range.
The prompt type should be Date range and the date type should be Day.
1) Select Prompt Manager Add.
2) In the Name field, enter DateRange. In the Displayed Text field, enter Select a beginning
and end date for the employee hire date range.
3) Select the Requires a non-blank value check box.
4) Click the Prompt Type and Values tab.
5) Change the prompt type value to Date range.
6) Verify that the Date type field value is Day. Click OK Close.
c. Create a filter on the Employee_Hire_Date column. Set the operator to In a range.
Use the prompt that you created to select the date range at execution.
1) Drag and drop the Employee_Hire_Date column onto the Filter Data tab.
2) In Step 1 of the New Filter window, use the drop-down menu to select In a range for
the operator.
3) Select the drop-down arrow for the Value field and select DateRange.
4) Click Next.
5) In Step 2, view the summary and click Finish to complete the filter.
d. Sort the results by ascending Employee_Hire_Date.
1) Click the Sort Data tab.

2) Drag Employee_Hire_Date onto the Sort Data tab.


e. Submit the query and set the range of dates from January 1, 2010 to December 31, 2010.
1) In the Query Builder, click Run.
2) In the Specify Values for Project Prompt window, select January 1 for any year.
Then delete the year and enter 2010. Enter or select December 31, 2010 in the To field.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-31

Partial Results

f. Save the Chapter6 project.


1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter6 in the File name field and select Save.

4. Creating a Multiple Value Prompt


Use the Prompt Manager to create a multiple value selection prompt for the City column.
a. In the Chapter6 project, create a prompt named SelectCities that enables the selection of one
or more cities and appears as follows:

If you do not have the Chapter6 project, you can create a new project and add
the employee_master data set.

1) Select Add in the Prompt Manager window.


2) On the General tab, enter SelectCities in the Name field and enter Select Cities to Include:
in the Display Text field.

3) Select the Requires a non-blank value check box.


4) Click the Prompt Type and Values tab.
5) On the Prompt Type and Values tab, verify that the prompt type is Text. Change the Method
of populating prompt value to User selects value from a static list.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-32 Chapter 6 Using Prompts in Tasks and Queries

6) Change the Number of values field to Multiple values.


7) Select Get Values Browse. In the Open File window, select Project employee_master
Open.
8) Use the drop-down list in the Unformatted values field to select City.
9) Select Get Values. The five city values are populated in the Available values pane.

10) Click to move all cites to the Selected values pane.

11) Click OK OK.


b. Create a query based on the employee_master table. Name the query Multi-Cities Query
and the output table Multi_Cities. Include all columns on the Select Data tab.
1) Right-click the employee_master table in the project tree or process flow
and select Query Builder.
2) In the Query Builder, enter Multi-Cities Query in the Name field.

3) Click Change and enter Multi_Cities in the File name field. Select Save.
4) With the Select Data tab active, right-click t1 (employee_master) and select
Select All Columns.
c. Build a filter that includes only those cities that are in the list of cities selected in the prompt.

1) Click the Filter Data tab.


2) Drag and drop City onto the tab area.
3) In the New Filter window, change the operator to In a list.
4) Select the Generate filter for a prompt value check box.
5) Select the drop-down arrow next to the Value field and select Prompts &SelectCities.
6) Click Next Finish.
d. Run the query and select Melbourne and Sydney for the cities. Verify the results and save
the Chapter6 project.

1) Click Run.
2) In the prompt, hold down the Ctrl key and select Melbourne and Sydney.
3) Click to move the columns to the Selected pane.

4) Click Run and verify that the output table has 73 rows.
5) Click on the toolbar.

6) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter6 in the File name field and select Save.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-33

Partial Results (8 of 73 rows)

5. Using a Prompt in a SAS Program


Create a prompt that can be used as a macro variable in a SAS program.
a. In the Chapter6 project, add the e106e05.sas program. Notice that the program includes
a WHERE statement that filters the data to include only employees in the Administration
Department. Run the program and verify that 31 rows are returned.

1) Select File Open Program.


2) Navigate to the location of the course data and select e106e5.sas Open.
3) If necessary, modify the SET statement to provide the path of the course data.
4) Click Run.
b. Create a prompt named SelectDept that enables the selection of any department
from the employee_master table. The prompt should appear as follows:

1) Select Prompt Manager in the Resources pane and select Add.


2) Enter SelectDept in the Name field and Choose a department to create employee address
labels: in the Display text field.

3) Select the Requires a non-blank value check box.


4) Click the Prompt Type and Values tab.
5) Change the Method for populating prompt drop-down list to User selects values
from a static list.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-34 Chapter 6 Using Prompts in Tasks and Queries

6) To populate the list, select Get Values Browse.


7) In the Open File dialog box, select Project employee_master Open.
8) In the Unformatted values pane, select Department from the Column drop-down list.
9) Select Get Values and click to move all values to the Selected values window.

10) Click OK OK.


c. Modify the WHERE statement in the SAS program to reference the SelectDept prompt
(macro variable) rather than Department.

Change the WHERE statement so that it appears as follows:


where Department="&SelectDept";
d. Modify the properties of the program by clicking on the Program toolbar.
Add the &SelectDept prompt to the properties.

1) In the toolbar of the Program tab, click .

2) Select Prompts in the Selection pane. Select Add SelectDept OK OK.


e. Run the program with Engineering as the selected value and verify the results. Save the
Chapter6 project.

1) Click Run Yes when you are prompted to replace the results.
2) In the prompt, select Engineering Run.
3) Click on the toolbar.

4) If the Save window appears, navigate to the location that is specified by your instructor.
Enter Chapter6 in the File name field and select Save.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-35

Solutions to Student Activities (Quizzes/Polls)

6.01 Multiple Choice Poll Correct Answer


How many rows were returned in the query result?
a. 0
b. 58
c. 76
d. 617
Partial Results

6.02 Multiple Answer Poll Correct Answers


Which of the following are valid names for prompts?
a. Select Country
b. Select_a_Category
c. Profit$Segments
d. 1stQtrValues
e. Qtr1Values
Names can contain only alphanumeric characters
and underscores, cannot begin with a number,
and cannot exceed 32 characters.

16

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-36 Chapter 6 Using Prompts in Tasks and Queries

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 7 Customizing and
Organizing Project Results

7.1 Combining Results .................................................................................................... 7-3


Demonstration: Combining Results ........................................................................... 7-6
Exercises............................................................................................................... 7-9

7.2 Updating and Organizing Projects .......................................................................... 7-11


Demonstration: Updating Results ............................................................................ 7-17

Exercises............................................................................................................. 7-20

7.3 Solutions ................................................................................................................. 7-22


Solutions to Exercises ........................................................................................... 7-22

Solutions to Student Activities (Quizzes/Polls) ........................................................... 7-27


7-2 Chapter 7 Customizing and Organizing Project Results

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.1 Combining Results 7-3

7.1 Combining Results

Objectives
Combine results from multiple tasks.
Customize the report layout.
Save and export the document as HTML
and PDF files.

Business Scenario
Analysts at Orion Star need to combine results from the
Profit Analysis project into a single HTML or PDF report.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-4 Chapter 7 Customizing and Organizing Project Results

SAS Reports
When you create results in SAS Report format, you can
use those results to create a customized report that you
can print, export, and share with other SAS applications.

Previewing Results
After the report layout is created, additional menus enable
further customization, including adding page headers
and footers, removing task titles or footnotes, setting page
margins, or inserting additional text.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.1 Combining Results 7-5

7.01 Quiz
Open the e107a01.egp project if it is not currently open.
Double-click Days to Deliver Report in the project.
Which buttons enable you to make the following changes?

Change the page margins.

Hide individual task titles or footnotes.

Save the report as HTML, PDF, XML, or SAS Report.

Updating Results
As tasks are rerun and updated, the report automatically
includes the current results.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-6 Chapter 7 Customizing and Organizing Project Results

Combining Results

Analysts at Orion Star want to combine the results from the Profit Analysis tasks into a single page.
They want to save the report as an HTML file to publish it on the intranet.

1. Open the e107d01.egp project and click Yes to run the Autoexec process flow.
2. To begin creating a combined report, select File New Report.
3. Drag Profit by Cust Age Group, Profit by Product Category Summary, and Profit by Cust
Cntry/Type to the positions. Expand the Profit by Cust Cntry/Type results to span two squares.

4. Click OK to close the Edit Report Contents window.


5. Select Header & Footer. On the Header tab, click Browse to locate the banner image. Navigate
to the course data and select Orion-Banner.jpg Open.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.1 Combining Results 7-7

6. In the Line section, click the Below header check box, and change Style to Double and Color
to blue.

7. Click the Titles & Footnotes tab and clear Show All for the footnote column. Click OK.
8. Select Page Setup and change the orientation to Landscape. Click OK and Page View to preview
the result.

9. Right-click the Report icon in the project tree or process flow, and select Rename. Change the name
to Profit Report. Press Enter.
10. To export the results, select Export Export Report As A Step In Project.
11. In Step 1, verify that Profit Report is highlighted and click Next.
12. In Step 2, select HTML Documents (*.html) Next.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-8 Chapter 7 Customizing and Organizing Project Results

13. In Step 3, navigate to the location that is specified by your instructor and name the file Profit
Report.html. Click Next.
14. In Step 4, view the summary and click Finish to complete the export. The exported HTML file can
then be published to the intranet or distributed to others to view in a browser.
A new icon is added to the process flow. It branches from the tasks that are included in the report.
Also, a new section named Custom Reports is added to the project, including the Report and Export
tasks.

You do not need to save the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.1 Combining Results 7-9

Exercises
Level 1

1. Creating a Report Using Multiple Results from the Available SAS Report Results
Build a SAS report that combines the output from three different tasks into a single PDF document.
a. Open and run the e107e01.egp project.
b. Create a combined report. Use the One-Way Frequencies, Summary Tables, and Bar Chart
SAS Report results. Build the report as it appears below.

c. Select Header & Footer to add Orion-Banner.jpg as a banner image to the top of the report.
d. Select Page Setup to change the page orientation to Landscape.
e. Select Page View to preview the report. If the graph and frequency report do not appear side
by side, return to Normal View to reduce the size of the graph.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-10 Chapter 7 Customizing and Organizing Project Results

f. Name the report Employee Report.


g. Add a step in the project to export the combined report as a PDF document. Do not overwrite
existing results.

Each time that the Export task is run, a new file is created with a date and time.
They are appended to the filename.

You do not need to save the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-11

7.2 Updating and Organizing Projects

Objectives
Demonstrate methods for updating project results.
Run a subset of the process flow diagram.
Build and run a new process flow diagram.

15

Business Scenario
A large SAS Enterprise Guide project was created
to analyze profit and shipping methods. The creator
wants to organize the project so that it is easy
to navigate and update.

16

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-12 Chapter 7 Customizing and Organizing Project Results

Updating Results
Selecting Run enables you to update the following:
the highlighted project item
the highlighted project item and all items that follow
the current process flow
the entire project

17

Project Organization
By default, when you run a process flow, project items
run in order from left to right, and then top to bottom.

18

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-13

7.02 Quiz
Open the e107a02.egp project. Double-click
the customers table.
What must be run first in the project in order to access
the SAS data sets?

19

Modifying Task Links


User-defined links can be added between project items
to ensure that tasks run in a certain order.
user-defined link automatic link
(dashed line) (solid line)

21

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-14 Chapter 7 Customizing and Organizing Project Results

Setup for the Poll


1. In the process flow, drag Assign Project Library
to the top of the window.
2. Right-click Assign Project Library and select Link
Assign Project Library to CUSTOMERS OK.
3. Select Run Run Process Flow.

22

7.03 Poll
Double-click the CUSTOMERS table. Does it open?
Yes
No

23

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-15

Multiple Process Flows


Creating multiple process flows provides another way
to order and group similar tasks within a single project.

25

Using multiple process flows is a convenient way to group project items so that you can execute them
as a group rather than individually. Using a process flow is particularly useful when the following conditions
exist:
A specific order in which tasks and code should execute is present. For example, output from one task
serves as input to another.
Changes to the underlying data and the tasks associated with a data source must be updated.
A desire to execute tasks outside of the SAS Enterprise Guide environment occurs.

Autoexec Process Flow


If there is a process flow named Autoexec,
SAS Enterprise Guide prompts you to run the
process flow each time that the project is opened.

26

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-16 Chapter 7 Customizing and Organizing Project Results

Scheduling Updates
Projects or individual process flows can be scheduled
to update based on a certain time or event.

27

When you schedule an Enterprise Guide project via the Enterprise Guide scheduler, a Visual Basic script
is created. This script is executed in accordance with the parameters that are supplied to the Windows
Scheduler plug-in. If both the SAS server and the Enterprise Guide client reside on a single machine,
scheduling a project is straightforward. However, if Enterprise Guide is configured to execute SAS
processes on a remote server and the SAS server is configured to prompt for a user name and password,
additional setup is required to enable the authentication process to complete.

If logon credentials for the SAS Metadata Server cannot be saved on the local machine,
scheduling of Enterprise Guide projects is not possible.

Other Recommendations
Rename project icons and table names to be more
descriptive.
Insert notes and link them to project icons to provide
documentation.
Use Auto-Arrange to create the process flow.
Then turn it off to make specific adjustments.
Change the color of the background for each process
flow.

28

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-17

Updating Results

The orders table is frequently updated, which requires all dependent tasks and queries to be rerun.
Users of this project want to organize it so that they can easily update the queries, tasks, and reports
related to the Profit analysis.

1. Open the e107d02.egp project. Notice that the entire project is contained in a single process flow.
2. To create a new process flow, select File New Process Flow. Click the Properties button
and enter Autoexec in the Label field. Click OK.
You can drag the Autoexec flow to the top of the project tree so that it appears first.

3. To copy project items into the Autoexec flow, hold down the Ctrl key and select the Create
OrderTypeFmt and Assign Project Library tasks. Right-click and select Copy.

4. Right-click the Autoexec process flow in the project tree and select Paste. After the tasks are copied
to the new Autoexec process flow, select the tasks again in the original process flow. Right-click
and select Delete.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-18 Chapter 7 Customizing and Organizing Project Results

5. In the Autoexec flow, select Run Run Autoexec.


6. Select Process Flow in the project tree and select Run Run Process Flow. Notice that the last task
fails because the work.orderdata table does not exist.

7. The Days to Deliver Frequencies report can be run based on the data in the OrderDetail table.
To switch the task to a new data source, right-click Days to Deliver Frequencies and select
Select Input Data WORK.OrderDetail.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-19

8. To update all tasks related to the OrderDetail table, highlight the icon in the process flow and select
Run Run Branch from OrderDetail. Verify that the Days to Deliver report is created.

9. To remove the OrderData table from the project, right-click on the icon in the project tree or process
flow. Select Delete Yes.

10. The individual icons in the process flow can be arranged to improve the display. Right-click in the
process flow and deselect Auto Arrange. You can then move project icons to the desired layout.

Other options available in the pop-up menu of the process flow include the ability to print,
zoom, and change the background color.

You do not need to save the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-20 Chapter 7 Customizing and Organizing Project Results

Exercises

Level 1

2. Creating a Process Flow Diagram


a. Open the e107e02.egp project and run the Autoexec flow.
b. Add a new process flow named Graphic Reports to the project.

c. Add the Bar Chart and Pie Chart tasks and results to the new Graphic Reports process flow.
d. Run the Graphic Reports process flow to update the results.

You do not need to save the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-21

Challenge

3. Controlling Project Flow and Exporting Combined Code and the Log from a Project
a. Open the e107e03.egp project and run the Autoexec flow.
b. Manually link the Create Format task with the Employee_Master_code icon so that
the Create Format task executes first.
c. Click the Project Log button and turn on logging for the project.
d. Run the entire project and view the project log.

e. Select File Export Export All Code In Project to create a SAS program named
EmployeeReports.sas. The program should include the code from all items in the project.
f. Export the project log as a text file.

You do not need to save the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-22 Chapter 7 Customizing and Organizing Project Results

7.3 Solutions
Solutions to Exercises
1. Creating a Report Using Multiple Results from the Available SAS Report Results
Build a SAS report that combines the output from three different tasks into a single PDF document.
a. Open and run the e107e01.egp project.
1) Select File Open Project and navigate to the course data. Select e107e01.egp Open.
2) Click Yes when you are prompted to run the Autoexec flow.
b. Create a combined report. Use the One-Way Frequencies, Summary Tables, and Bar Chart
SAS Report results.

1) Select File New Report.


2) Drag and drop the One-Way Frequencies and Bar Chart results onto the first row of the data
grid. Drag and drop the Summary Tables results in the second row and expand the box
to cover two columns.

3) Click OK to create the report.


c. Select Header & Footer to add Orion-Banner.jpg as a banner image to the top of the report.
1) Select Header & Footer.
2) Click Browse and navigate to the course data.
3) Select Orion-Banner.jpg Open.
4) Click OK.
d. Select Page Setup to change the page orientation to Landscape.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.3 Solutions 7-23

e. Select Page View to preview the report. If the graph and frequency report do not appear side by
side, return to Normal View to reduce the size of the graph.

f. Name the report Employee Report.


1) In the project tree or process flow, right-click Report and select Rename.
2) Enter Employee Report and press Enter.
g. Add a step in the project to export the combined report to a PDF document. Do not overwrite
existing results.

Each time that the Export task is run, a new file is created with a date and time.
They are appended to the filename.

1) Select Export Export Report As A Step In Project.


2) In Step 1, verify that Employee Report is highlighted and click Next.
3) In Step 2, select Portable Document Format (*.pdf). Click Next.
4) In Step 3, click Browse and navigate to the location of the course data.
5) Clear the Overwrite existing output check box.
6) Click Next Finish.

You do not need to save the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-24 Chapter 7 Customizing and Organizing Project Results

2. Creating a Process Flow Diagram


a. Open the e107e02.egp project and run the Autoexec flow.
1) Select File Open Project and navigate to the course data. Select e107e02.egp Open.
2) Click Yes when you are prompted to run the Autoexec flow.
b. Add a new process flow named Graphic Reports to the project.
1) Select File New Process Flow. The new Process Flow window appears.
2) Click the Properties icon to access the Properties window.
3) Enter Graphic Reports in the Label field and click OK.
c. Add the Bar Chart and Pie Chart tasks and results to the new Graphic Reports process flow.
1) Use the Process Flow drop-down menu on the toolbar to select the Autoexec process flow.
2) In the Autoexec process flow, hold down the Ctrl key and select the Salary by Department
Bar Chart, Salary by Country Pie Chart, and Salary by City Bar Chart tasks.

3) Right-click on any of the highlighted tasks and select Move to Graphic Reports.
d. Run the Graphic Reports process flow to update the results.
1) Use the Process Flow drop-down menu on the toolbar to select the Graphic Reports process
flow.

2) Right-click Graphic Reports in the process flow and select Run Graphic Reports.

You do not need to save the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.3 Solutions 7-25

3. Controlling Project Flow and Exporting Combined Code and the Log from a Project
a. Open the e107e03.egp project and run the Autoexec flow.
1) Select File Open Project.
2) Navigate to the location of the course data, select e107e03.egp, and select Open.
b. Manually link the Create Format task with the Employee_Master_code icon so that
the Create Format task executes first.

1) In the Reports process flow, click the Create Format icon, right-click, and select
Link Create Format ($cntryfmt Local) to.
2) In the Link window, select Employee_Master_code and click OK.
c. Click the Project Log button and turn on logging for the project.
1) Click the Project Log button and click the Turn On button.
2) Return to the Reports Process Flow window by double-clicking Reports in the project tree
or process flow.

d. Run the entire project and view the project log.


1) Select Run Run Reports.
2) From the menu bar, select View Project Log.

e. Select File Export Export All Code In Project to create a SAS program named
EmployeeReports.sas. The program should include the code from all items in the project.

1) Select File Export Export All Code In Project.


2) Click Browse, navigate to the location of the course data, enter EmployeeReports.sas
in the File name field, and select Save.

3) Notice the options in the Export All Code window to include additional code that is generated
by Enterprise Guide.
4) Select Export.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-26 Chapter 7 Customizing and Organizing Project Results

f. Export the project log as a text file.


1) In the Reports Process Flow window, click the Project Log button.
2) In the Project Log window, select Export Export Project Log.
3) In the Export window, select the course location to save the file and enter ProjectLog1
in the File name field. Save the file as a text (.txt) file. Select Save.

You do not need to save the project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.3 Solutions 7-27

Solutions to Student Activities (Quizzes/Polls)

7.01 Quiz Correct Answer


Open the e107a01.egp project if it is not currently open.
Double-click Days to Deliver Report in the project.
Which buttons enable you to make the following changes?

Change the page margins.


Page Setup
Hide individual task titles or footnotes.
Header & Footer
Save the report as HTML, PDF, XML, or SAS Report.
Export

7.02 Quiz Correct Answer


What must be run first in the project in order to access
the SAS data sets?
The Assign Project Library task must run first to create
the orion library.

20

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-28 Chapter 7 Customizing and Organizing Project Results

7.03 Poll Correct Answer


Double-click the CUSTOMERS table. Does it open?
Yes
No

24

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 8 Learning More

8.1 SAS Resources.......................................................................................................... 8-3


8-2 Chapter 8 Learning More

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8.1 SAS Resources 8-3

8.1 SAS Resources

Objectives
Identify the areas of support that SAS offers.
Identify the next steps after the completion
of this course.

Customer Support
SAS provides a variety of resources to help customers.

http://support.sas.com/resourcekit/
3

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8-4 Chapter 8 Learning More

Education
SAS Education provides comprehensive training, including
more than 200 course offerings
world-class instructors
multiple delivery methods
worldwide training centers.

http://support.sas.com/training/

SAS Books
Convenient. Practical. Enlightening.
Valuable insight with solid results.
Available in a variety of formats
to best meet your needs:
hard-copy books
e-books
PDF

5 www.sas.com/store/books

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8.1 SAS Resources 8-5

SAS Global Certification Program


SAS Education also provides
globally recognized certifications
preparation materials
practice exams.

http://support.sas.com/certify/

Networking
Social media channels and user group organizations
enable you to
interact with other SAS users and SAS staff
learn new programming tips and tricks
get exclusive discounts.

For training-specific information:


http://support.sas.com/training/socialmedia

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8-6 Chapter 8 Learning More

User Groups and SAS Support Communities


SAS supports many local, regional, international,
and special-interest SAS user groups.
http://support.sas.com/usergroups

SAS Support Communities enable you to collaborate


with SAS and other SAS users.
http://communities.sas.com

SAS Blogs
SAS provides access to several featured blogs.
http://blogs.sas.com

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8.1 SAS Resources 8-7

SAS Blogs
Visit http://blogs.sas.com/sasdummy to read about
interesting tips and insights regarding SAS Enterprise
Guide.

10

SAS Enterprise Guide Community


Use the SAS Enterprise Guide Community to share your
questions and experiences with other SAS customers.
SAS employees occasionally respond to your posts.
Visit https://communities.sas.com to participate
in all discussion topics.

11

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8-8 Chapter 8 Learning More

Extending Your Learning


An extended learning page is available for this course.
It includes the following:
the course files
a PDF of the course notes
instructor-tip videos
papers and presentations

12

Next Steps
SAS Enterprise Guide 1: Querying and Reporting
is the entry point to many areas of the SAS curriculum.
SAS Enterprise Guide 1:
Querying and Reporting

Accessing and Reports and


Manipulating Statistical Graphs
Data Analysis

13

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8.1 SAS Resources 8-9

Next Steps
To learn more about this: Enroll in the following:

Manipulating data using SAS SAS Enterprise Guide 2:


Enterprise Guide Advanced Tasks and Querying

Producing advanced graphs and Creating Reports and Graphs


reports using Enterprise Guide with SAS Enterprise Guide

SAS Programming 1:
SAS Programming
Essentials

SAS Enterprise Guide:


SAS Statistics Using
ANOVA, Regression, and
SAS Enterprise Guide
Logistic Regression
14

Next Steps
In addition, prerecorded, short, technical discussions
and demonstrations are referred to as e-lectures.
http://support.sas.com/training/

15

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8-10 Chapter 8 Learning More

SAS Video Tutorials


SAS Education provides an extensive set of how-to
videos, tutorials, and demos to learn tips and tricks for
working with SAS software.

16 http://support.sas.com/training/tutorial

Additional Training Categories


In addition to SAS Enterprise Guide training, courses
are available in the following areas:
Advanced Analytics
SAS Foundation
SAS Solutions

Visit http://support.sas.com/training/us/paths to view


all of the courses that are available to meet your
training needs.

17

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Appendix A Writing and Submitting
SAS Programs

A.1 Writing and Submitting SAS Programs .................................................................... A-3


Demonstration: Adding a SAS Program to a Project...................................................A-13
Exercises.............................................................................................................A-21

A.2 Solutions ................................................................................................................. A-24


Solutions to Exercises ...........................................................................................A-24

Solutions to Student Activities (Polls/Quizzes) ...........................................................A-28


A-2 Appendix A Writing and Submitting SAS Programs

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-3

A.1 Writing and Submitting SAS Programs

Objectives
Create and submit new SAS programs.
Insert existing programs into a project.
List programming statements to avoid.
Generate a combined project program and log.

Enterprise Guide Program Editor


Enterprise Guide has a Program Editor that includes
several advanced features:
autocomplete
dynamic syntax
tooltips
formatting
programs
to provide
consistent
spacing
analyzing
program
flow

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-4 Appendix A Writing and Submitting SAS Programs

Writing a New SAS Program


To build a SAS program, select File New Program
to create a new code node in the project. The new
program is saved along with the project.

Adding Existing Code


To add a shortcut in the project to an existing
SAS program, select File Open Program.

When you insert code, a shortcut to the file is added in the project. This means that changes made
to the code in the project are also saved to the .sas file that you inserted when the project was saved.
Also, if you make changes to the .sas file outside of Enterprise Guide, the changes are reflected when
you open or run the project again.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-5

Running SAS Code


A SAS program can be submitted using one of these
techniques:
Select Run or Run Selection on the toolbar.
Select Program Run or Run Selection
on the menu bar.
Right-click on the program and select Run
or Run Selection.
Press F8 or F3.

If SAS is available on multiple servers, you can select Select Server and designate the server on which
the program should run.

If the data for a task is located on a server that is different from the server where the SAS code is run,
then Enterprise Guide copies the data to the server where the code actually runs. Moving large amounts
of data over a network can be time and resource intensive. It is recommended that the server on which
you choose to process the code be the same server on which the data resides.

Accessing Program, Log, and Results


The program, log, output data, and results are accessible
via separate tabs.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-6 Appendix A Writing and Submitting SAS Programs

Identifying Warning and Errors in the Log


The code icons in the project indicate whether there are
warnings or errors in the SAS log.

Arrows on the Log tab enable quick navigation to the next


warning or error.

Identifying Warning and Errors in the Log


The Log Summary window list all notes, warnings,
and errors messages. It enables direct navigation
to any message.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-7

A.01 Quiz
Open the SAS program e1Aa01.sas in SAS Enterprise
Guide and run it.
1. Use the Log Summary and the Log windows to identify
any errors.
2. Right-click on the error in the Log Summary window.
Navigate to the line in the program that must
be corrected.
3. Correct the program, and rerun it.

e1Aa01.sas
10

A.02 Quiz
Examine the Program and Log tabs. What differences
do you observe?

12

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-8 Appendix A Writing and Submitting SAS Programs

Simplifying the Log


You can suppress the wrapper code in the log
by selecting Tools Options Results General.
Then clear the Show generated wrapper code
in SAS log check box.

14

Using the Program Toolbar


A toolbar above the program offers easy access
to common actions, such as the following:
saving the program
running or stopping a program
selecting the execution server
analyzing the program for flow or grid computing
exporting and e-mailing
creating a stored process
modifying program properties

15

The Analyze Program button enables you to select one of these three options:
Analyze Program Flow: Enterprise Guide can create a process flow from a program. Using this
process flow, you can quickly identify the different parts of the program and see how the parts are related.
Analyze for Grid Computing: When you analyze a program for grid computing, Enterprise Guide
identifies the parts of the program that are not dependent on one another. These parts can run
simultaneously on multiple computers. This means that Enterprise Guide returns the results faster.
When SAS analyzes a program, lines of SAS/CONNECT code are added to your original program.
Therefore, you must have a license for SAS Grid Manager or SAS/CONNECT to analyze a program
for grid computing.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-9

Analyze for Internationalization: When you analyze a program for internationalization, Enterprise
Guide identifies lines of code that might contain syntax that is specific to a particular geographic
location. Examples include locale-specific currency and date formats or Unicode problems. When you
analyze a program for internationalization, SAS Enterprise Guide lists the lines of code that might
be affected and suggests substitutions when it is possible.

All options run the code behind the scenes to complete the analysis. If a data set is open
in the Enterprise Guide session, the analysis might fail. To view and close any open data sets,
select Tools View Open Data Sets.

Embedding Programs in a Project


New SAS programs are
embedded in the project
so that it is saved as
part of the .egp file.
When an existing
SAS program is added
to a project, a shortcut
to the program file is
created. You can also
embed the program so
that it is stored as part Select Embed in the
of the project file. Program window.

16

A.03 Quiz
Embed the e1Aa01 program into the project by
clicking the Properties button on the Program tab.
Select Embed OK. View the process flow.
How does the Code icon change?

e1Aa01.sas
17

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-10 Appendix A Writing and Submitting SAS Programs

Using Autocomplete
The Program Editor also includes an autocomplete
feature. The editor can suggest the following:
SAS statements
procedures
macro programs
macro variables
functions
formats
librefs
SAS data sets
variable names

19

The autocomplete feature automatically suggests appropriate keywords. You can manually open
the Autocomplete window by using the following shortcut keys:

Action Keyboard Shortcut

Open the Autocomplete window for the keyword on which the pointer is currently Ctrl + spacebar
positioned. In a blank program, this shortcut displays a list of global statements.

Open the Autocomplete window that contains a list of the SAS libraries
Ctrl + L
that are available with the current server connection.

Open the Autocomplete window that contains a list of data sets


Ctrl + D
that were created by using the DATA statement.

Open the Autocomplete window that contains a list of SAS functions. Ctrl + Shift + F1

Open the Autocomplete window that contains a list of macro functions. Ctrl + Shift + F2

Open the Autocomplete window that contains a list of SAS formats. Ctrl + Shift + F

Open the Autocomplete window that contains a list of SAS informats. Ctrl + Shift + I

Open the Autocomplete window that contains a list of statistics keywords. Ctrl + Shift + K

Open the Autocomplete window that contains a list of SAS colors. Ctrl + Shift + C

Open the Autocomplete window that contains a list of style attributes. Ctrl + Shift + F4

Open the Autocomplete window that contains a list of style elements. Ctrl + Shift + F3

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-11

Customizing the Program Editor


You can customize the Program Editor by selecting
Program Editor Options.

20

Rearranging Windows
Stacking windows enables you to view two components
in the project simultaneously.

21

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-12 Appendix A Writing and Submitting SAS Programs

Linking Items in the Process Flow


Links can enable you to force a particular flow between
programs and point-and-click tasks in the project.

user-defined link automatic link


(dashed line) (solid line)

22

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-13

Adding a SAS Program to a Project

1. Open a new project and add the products SAS data set.
2. To open an existing SAS program, select File Open Program. Navigate to the location of
the course data and select e1Ad01.sas Open. A shortcut to the program is added to the project.

3. There is no indenting in this program to make it easier to read. Select Edit Format Code
to improve the spacing, or you can right-click on the program and select Format Code.

To modify the rules for formatting code, select Program Editor Options Indenter.

4. To execute the SAS program, select Run on the toolbar. A frequency report is generated, and four
new SAS data sets, children, sports, outdoors, and clothing, are added to the project. Because
children was the first created data set, it is automatically placed on a new Output Data tab. All other
data sets are accessible from the drop-down list on the Output Data tab or in the process flow.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-14 Appendix A Writing and Submitting SAS Programs

5. The original process flow currently does not show a direct connection between the e1Ad01 program
and the products data set. You can manually connect these items in the process flow to visually
indicate that the program references the products data set. This is not required, but is helpful for
controlling the sequence of the process flow. To link icons, right-click products in the process flow
and select Link products to e1Ad01 OK.
Project items can also be connected by clicking and dragging from one icon to another.
The dashed line indicates a manual link, and the solid lines indicate a link generated
by Enterprise Guide.

6. Double-click the e1Ad01 icon in the project tree or process flow to return to the program. To add
a report that lists the products in the children data set, use the PRINT procedure in the SAS program.
At the end of the program, type pr. A list of keywords is provided. After PROC is highlighted, you
can either press the spacebar or the Enter key to add PROC to the program.

7. Automatically, a list of procedure names is provided. To add PRINT to the program, begin by typing
p. You can either use the down arrow key to select PRINT and then press the spacebar or Enter key,
or you can double-click PRINT.

8. Next, a list of valid options for the PROC PRINT statement is provided. Type da and press the
spacebar to select DATA=.

9. A list of data sets in the project and defined libraries is provided. Type ch and press the spacebar
to add children to the program.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-15

10. The list of valid options for the PROC PRINT statement appears again. Type la and enter a semicolon
to complete the statement as follows:

11. To list specific variables, type var and press the spacebar. A list of variables in the children data set
is provided. Double-click Product_Name, Product_Category, and Supplier_Name.
Press the spacebar after each variable name to be prompted again with the variable list.

12. Continue to use the autocomplete feature to write the remainder of the step.

13. Highlight the PROC PRINT step in the program and select Run Run Selection. Select Yes
when you are prompted to replace the results.
Partial Results

14. The program now includes three steps and creates multiple data sets and reports. To better
visualize the flow of the program, return to the Program tab and select Analyze Program
Analyze for Program Flow.

15. In the Analyze SAS Program window, select Begin analysis. Enter Products Analysis
in the Name of process flow to create field. Select Create process flow Close.

If a data set is open in the Enterprise Guide session, the analysis might fail. To view and close
any open data sets, select Tools View Open Data Sets.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-16 Appendix A Writing and Submitting SAS Programs

A new process flow is added to the project, and illustrates the flow of the steps in the program.

To delete a process flow, right-click on the process flow in the project tree and select Delete.

16. The Program Editor also includes syntax tooltips. Double-click the e1Ad01 program in the project
tree or process flow. Position the mouse pointer over any keyword in the program. A tooltip displays
syntax details for that particular step or statement. Helpful links to online resources are included
in the tooltip.

The F1 key also displays syntax help.

You can view syntax tooltips by positioning the pointer over items in the autocomplete windows.

17. Syntax help is also available when you enter SAS functions. Use the FIND function to create another
data set that includes all products containing shoes as part of the name. Type shoes at the end
of the DATA statement to create an additional data set. Add the following IF statement before
the RUN statement in the DATA step:
if find(Product_Name,"shoes","i") > 0 then output shoes;

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-17

Notice how the syntax tooltips provide a description of each argument in the FIND function as you type.

The FIND function returns a number that indicates the starting position of the substring
shoes. If shoes does not exist in the name, the FIND function returns a zero.
18. Select Run and replace the results. Click the Output Data tab and select SHOES from the
drop-down list.

Partial Results (5 of 45 rows)

19. Save the modified program by returning to the Program tab and selecting Save Save As.
Save the program as e1Ad01s and select Save.

20. Save the project as AppendixA.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-18 Appendix A Writing and Submitting SAS Programs

Exporting Code
All SAS code within a project can be exported to a file that
can be edited and executed in other SAS environments.

Select
File Export
Export All Code
in Project.

24

Project Log
The project log can be used to maintain and export
an aggregated log of all code submitted for the project.

25

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-19

Setup for the Poll


1. Open the e1Aa01.egp project.
2. Select Project Log in the Process Flow window
or select View Project Log.

3. Select Turn On.


4. Return to the Process Flow window and select
Run Process Flow.
5. After the results are generated, select
Run Process Flow a second time.
6. Examine the project log by selecting
View Project Log.
26

A.04 Poll
Is the project log overwritten or appended when
the project is run the second time?
overwritten
appended

27

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-20 Appendix A Writing and Submitting SAS Programs

Programming Statements to Avoid


Programs that run in the SAS windowing environment
can also run successfully in SAS Enterprise Guide.
Be aware of the following exceptions:
Code that calls X commands or SYSTASK might
not work unless this permission is granted
by the administrator.
Code that normally causes a window or prompt
to appear in the SAS windowing environment
(DEBUG, PROC FSLIST, AF applications) does
not work in SAS Enterprise Guide.
Code that terminates the SAS process with ABORT
or ENDSAS calls terminates the connection between
SAS Enterprise Guide and the SAS server.

29

For more information about enabling X and SYSTASK commands, go to


http://blogs.sas.com/content/sasdummy/2009/11/19/using-the-x-and-systask-commands-from-sas-
enterprise-guide/.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-21

Exercises

Level 1

1. Modifying and Running a SAS Program in a Project


a. In the AppendixA project, add the e1Ae01.sas program.

If another project is open, select File Open Recent Projects to quickly access
the AppendixA project.

If you do not have the AppendixA project, you can create a new project.

b. Format the program to improve the spacing of the statements.

The rules for indenting can be modified by selecting Program Editor Options
Indenter.
c. If necessary, modify the path in the LIBNAME statement to point to the location of the course
data.
d. To better understand the flow of the program, use the Analyze Program tool to generate a new
process flow that outlines the steps included in the code. Name the new process flow Salary
Analysis. After you examine the Salary Analysis process flow, delete it from the project.

e. Run the program and review the results.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-22 Appendix A Writing and Submitting SAS Programs

f. Return to the e1Ae01.sas program and add the PROC MEANS step below to calculate average
salary and median salary. Open the Autocomplete window to supply keywords in the code.
proc means data=CurrentEmployees mean median noprint;
var Salary;
class Department;
output out=work.SalaryStats mean=AvgSalary Median=MedSalary;
run;
g. Highlight the added step and submit only the new code.

Partial Results (7 of 18 rows)

h. Save the modified program as EmployeeSalary.sas.


i. Save the AppendixA project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-23

Level 2

2. Using the Autocomplete Tab with Functions, Linking Items in a Project, and Creating a Project Log
a. If you completed the Level 1 exercise, use the AppendixA project. Otherwise, open the
e1Ae02.egp project.
b. In the DATA step of the EmployeeSalary program, add an assignment statement to create
a variable named Years_Employed. Use the INT, YRDIF, and TODAY functions to calculate
the number of years that elapsed between Employee_Hire_Date and todays date.

As you enter the arguments of the functions, notice the syntax tooltips that are provided.

c. Highlight the DATA step and run the selection.

The values of Years_Employed are different depending on the date on which you run
the program.
Partial Results (7 of 308 rows)

d. The EmployeeSalary program uses the employee_organization SAS data set as input.
To reflect this relationship, manually link the items in the process flow.
e. Turn on the project log in the process flow.
f. Run the entire project and examine the project log. Save the AppendixA project.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-24 Appendix A Writing and Submitting SAS Programs

A.2 Solutions
Solutions to Exercises
1. Modifying and Running a SAS Program in a Project
a. In the AppendixA project, add the e1Ae01.sas program.

If another project is open, select File Open Recent Projects to quickly access
the AppendixA project.

If you do not have the AppendixA project, you can create a new project.

1) Select File Open Program and navigate to the location of the course data.
2) Select e1Ae03.sas Open.
b. Format the program to improve the spacing of the statements.
Select Edit Format Code or hold down the Ctrl key and press the letter i on the keyboard.

The rules for indenting can be modified by selecting Program Editor Options
Indenter.

c. If necessary, modify the path in the LIBNAME statement to point to the location of the course
data.

If the path specified in quotation marks in the LIBNAME statement is not the path of the course
data, then replace this path with the correct location.
d. To better understand the flow of the program, use the Analyze Program tool to generate a new
process flow that outlines the steps included in the code. Name the new process flow Salary
Analysis. After examining the Salary Analysis process flow, delete it from the project.
1) On the Program tab, select Analyze Program Analyze Program Flow.
2) Select Begin Analysis.
3) Enter Salary Analysis in the Name of process flow to create field and select
Create process flow.
4) After you examine the new process flow, right-click Salary Analysis in the project tree
and select Delete Yes. A shortcut to the original program (e1Ae03) is still included
in the project.

e. Run the program and review the results.


1) Double-click the e1Ae01 icon in the project tree or process flow.
2) Select Run from the program toolbar.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.2 Solutions A-25

f. Return to the e1Ae01.sas program and add the PROC MEANS step below to calculate average
salary and median salary. Use the Autocomplete window to supply keywords in the code.
proc means data=CurrentEmployees mean median noprint;
var Salary;
class Department;
output out=work.SalaryStats mean=AvgSalary Median=MedSalary;
run;
g. Highlight the added step and submit only the new code.

1) Highlight the PROC MEANS step.


2) Select Run Run Selection. Click Yes to replace the results.
Partial Results (7 of 18 rows)

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-26 Appendix A Writing and Submitting SAS Programs

h. Save the modified program as EmployeeSalary.sas.


1) Click the Program tab.
2) Select Save Save As from the program toolbar.
3) Navigate to the location that is specified by your instructor.
4) Name the file EmployeeSalary and select Save.
i. Save the AppendixA project.
1) Click on the toolbar.

2) If the Save window appears, navigate to the location that is specified by your instructor.
Enter AppendixA in the File name field and select Save.

2. Using the Autocomplete Tab with Functions, Linking Items in a Project, and Creating a Project Log
a. If you completed the Level 1 exercise, use the AppendixA project. Otherwise, open the
e1Ae02.egp project.

1) If necessary, select File Open Project.


2) Navigate to the course data and select e1Ae02.egp Open.
b. In the DATA step of the EmployeeSalary program, add an assignment statement to create
a variable named Years_Employed. Use the INT, YRDIF, and TODAY functions to calculate
the number of years that elapsed between Employee_Hire_Date and todays date.

As you enter the arguments of the functions, notice the syntax tooltips that are provided.

1) Double-click the EmployeeSalary program in the project tree or process flow.


2) Before the RUN statement in the DATA step, add the following statement:
Years_Employed=int(yrdif(Employee_Hire_Date,today(),"act/act"));
c. Highlight the DATA step and run the selection.
Highlight the DATA step and select Run Run Selection.
Partial Results (7 of 308 rows)

d. The EmployeeSalary program uses the employee_organization SAS data set as input.
To reflect this relationship, manually link the items in the process flow.
1) Click the employee_organization data set once in the process flow to select the data source.
2) Position the mouse pointer over the border of the icon until a crosshair tool appears.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.2 Solutions A-27

3) Click and drag it to the EmployeeSalary icon.

You can also right-click employee organization and select


Link employee_organization to EmployeeSalary.

e. Turn on the project log in the process flow.


1) Click the Project Log tab in the process flow.
2) Click the Turn On tab.
3) Click to close the project log.

f. Run the entire project and examine the project log. Save the AppendixA project.
1) In the process flow, select Run Run Project.
2) Return to the process flow and select Project Log. You can expand each section to view
the log for the items in the project.

3) Click on the toolbar.

4) If the Save window appears, navigate to the location that is specified by your instructor.
Enter AppendixA in the File name field and select Save.

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-28 Appendix A Writing and Submitting SAS Programs

Solutions to Student Activities (Polls/Quizzes)

A.01 Quiz Correct Answer


Open the SAS program e1Aa01.sas in SAS Enterprise
Guide and run it.
1. Use the Log Summary and the Log windows to identify
any errors.
2. Right-click on the error in the Log Summary window.
Navigate to the line in the program that must
be corrected.
3. Correct the program, and rerun it.
The data set should be named children.

e1Aa01.sas
11

A.02 Quiz Correct Answer


Examine the Program and Log tabs. What differences
do you observe?
Enterprise Guide adds wrapper code before and after
the submitted program to format the results.

Keep the program


open for the next quiz.

13

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.2 Solutions A-29

A.03 Quiz Correct Answer


Embed the e1Aa01 program into the project by
clicking the Properties button on the Program tab.
Select Embed OK. View the process flow.
How does the Code icon change?
The shortcut arrow is removed.

Remove the e1Aa01 program from the project


by right-clicking the icon and selecting Delete.
e1Aa01.sas
18

A.04 Poll Correct Answer


Is the project log overwritten or appended when
the project is run the second time?
overwritten
appended

28

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-30 Appendix A Writing and Submitting SAS Programs

Copyright 2016, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.

Das könnte Ihnen auch gefallen