Curso Sas Enterprise Guide
Curso Sas Enterprise Guide
Curso Sas Enterprise Guide
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.
Copyright © 2014 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 E2537, course code LWEG161/EG161, prepared date 19Mar2014. LWEG161_001
ISBN 978-1-62959-165-0
For Your Information iii
Table of Contents
5.2 Creating a Summary Report with the Summary Tables Task......................................... 5-11
Demonstration: Creating a Tabular Summary Report ............................................. 5-12
Exercises.................................................................................................................. 5-16
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. 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 [email protected].
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 [email protected]. 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
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1 Introducing SAS Enterprise Guide 1-3
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
Neural Networks
Decision Trees High-Performance Forecasting
Information Theory
Descriptive Modeling Psychometric Analysis Mixed Models Multivariate Analysis
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-4 Chapter 1 Getting Started
This course is written for SAS Enterprise Guide 6.1. To determine which version
of Enterprise Guide you are using, select Help About SAS Enterprise Guide.
6 ...
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1 Introducing SAS Enterprise Guide 1-5
7 ...
8 ...
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-6 Chapter 1 Getting Started
export capabilities
9 ...
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1 Introducing SAS Enterprise Guide 1-7
export capabilities
programming interface
11
12
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-8 Chapter 1 Getting Started
Discussion
13
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1 Introducing SAS Enterprise Guide 1-9
15
Configuration
Enterprise Guide can be configured to work with
SAS either on the local PC or on a remote server.
Local Client/Server
16
Copyright © 2014, 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.
18
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-11
Objectives
Define the business scenario for class demonstrations
and exercises.
Describe the steps to build an Enterprise Guide
project.
List the topics 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
21
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-12 Chapter 1 Getting Started
22
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-13
24
Chapter 2
Working with Data in a Project
25
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-14 Chapter 1 Getting Started
Chapter 3
Getting Started with Tasks
26
Chapter 4
Creating Simple Queries
27
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-15
Chapter 5
Creating Summarized Output
28
Chapter 6
Using Prompts in Tasks and Queries
29
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-16 Chapter 1 Getting Started
Chapter 7
Customizing and Organizing Project Results
30
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
• Server List
4. By default, the Project Tree and Server List windows 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-17
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.
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 to 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-18 Chapter 1 Getting Started
11. Type CustomerCounts in the File name field and select Save Next.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-19
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-20 Chapter 1 Getting Started
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-21
32
63
instructor-tip videos
33
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-22 Chapter 1 Getting Started
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
Exercises
Level 1
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2 Course Scenarios 1-23
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.
Level 2
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-24 Chapter 1 Getting Started
d. Save the project as Chapter1 in the location that is specified by your instructor.
Challenge
You can right-click on the error message in the log summary to go to the corresponding
line in the program or log.
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.3 Solutions 1-25
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 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) Type 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-26 Chapter 1 Getting Started
If you saved the project, you can select File Save Chapter1 only.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.3 Solutions 1-27
3) Type 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.
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 right-click on the error message in the log summary to go to the corresponding
line in the program or log.
1) Select Run on the menu bar.
2) Because the program had an error, the SAS log appears automatically in the workspace.
Review the log to identify the error.
You can right-click on the error message in the log summary to go to the corresponding
line in the program or log.
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1-28 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 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) Type 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 2 Working with Data in a
Project
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.1 Understanding SAS Data Structure 2-3
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-4 Chapter 2 Working with Data in a Project
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.1 Understanding SAS Data Structure 2-5
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
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.
A new option in Enterprise Guide 6.1 allows 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-6 Chapter 2 Working with Data in a Project
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.1 Understanding SAS Data Structure 2-7
Column Type
A column’s type is either character (string) or numeric.
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 variable's 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.
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-8 Chapter 2 Working with 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
15
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.1 Understanding SAS Data Structure 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 set’s properties are referred to as the descriptor portion.
16
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-10 Chapter 2 Working with 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.
18
Many tasks in Enterprise Guide provide options for how to handle missing values in the report
or analysis.
Objectives
Identify methods for accessing data.
Define SAS libraries.
Add data to a project via a library definition.
Explore data interactively.
20
Copyright © 2014, 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
22
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-12 Chapter 2 Working with Data in a Project
23
24
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-13
25
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-14 Chapter 2 Working with Data in a Project
2.04 Quiz
1. Select File New Project.
2. Select View Server List or click the Server List
icon in the Resources pane below the project tree.
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 © 2014, 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-16 Chapter 2 Working with Data in a Project
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 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 © 2014, 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 Server List or click the Server List
icon in the Resources pane below the project tree.
34
Available Libraries
Some libraries can be defined automatically by SAS.
36
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-18 Chapter 2 Working with 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.
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-19
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, type 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, type 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-20 Chapter 2 Working with 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 Server List 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.
Exercises
Level 1
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 List pane. If you do not see the library or the data sets, select
your server and click Refresh.
d. Save the Chapter2 project.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.2 Accessing SAS and DBMS Data 2-21
Level 2
d. Right-click travel_expenses in the Work library in the Server List pane and select Delete.
Are you able to delete the table?
e. Right-click travel_expenses in the orion library in the Server List pane and select Delete.
Are you able to delete the table?
Challenge
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-22 Chapter 2 Working with Data in a Project
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-23
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
48
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
Microsoft Exchange Server 2000, 2003, 2007 Microsoft Exchange Server 2000, 2003, 2007
• HTML
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-24 Chapter 2 Working with Data in a Project
• Paradox 3 - 12
• 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?
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-25
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 can
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.
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. Type Import Products.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-26 Chapter 2 Working with Data in a Project
51
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-27
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
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-28 Chapter 2 Working with Data in a Project
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.
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-29
Exercises
Level 1
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.
The variable names appear in the data grid, but labels are displayed in the reports.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-30 Chapter 2 Working with Data in a Project
Level 2
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.3 Importing Data Files 2-31
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.
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)
Challenge
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-32 Chapter 2 Working with Data in a Project
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)
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-33
2) If the Save window appears, navigate to the location specified by your instructor.
Type Chapter2 in the File name field and select Save.
2. Using the Server List for File Operations
Use the server list to copy, paste, and delete data sets.
a. The server list 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.
d. Right-click travel_expenses in the Work library in the Server List pane 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 List pane. These actions cannot be undone, so be careful!
e. Right-click travel_expenses in the orion library in the Server List pane 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-34 Chapter 2 Working with Data in a Project
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-35
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.
Partial Results (8 of 424 rows)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-36 Chapter 2 Working with Data in a Project
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-37
b. Name the new SAS data set employee_payroll and indicate that the file is comma delimited.
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 .
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-38 Chapter 2 Working with Data in a Project
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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. In 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-39
c. Right-click the Import Employee Payroll icon in the project tree or process flow and select
Add as Code Template.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-40 Chapter 2 Working with Data in a Project
g. Submit the code for execution and view the data in the new data set.
Partial Results (8 of 308 rows)
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter2 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-41
10
17
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-42 Chapter 2 Working with Data in a Project
28
35
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2.4 Solutions 2-43
47
53
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
2-44 Chapter 2 Working with Data in a Project
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 3 Getting Started with Tasks
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.1 Introduction to Tasks and Wizards 3-3
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-4 Chapter 3 Getting Started with Tasks
3.01 Quiz
Select the Tasks menu 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 Task List window. You can open the window by selecting View
Task List. To see the task names and the corresponding SAS procedures, select Tasks by Name
from the drop-down list. You can also alphabetize the list by procedure name by clicking on the
SAS Procedures heading.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.1 Introduction to Tasks and Wizards 3-5
2. Select
a task.
Selecting a Task
Tasks can also be selected from the menu in the data grid.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-6 Chapter 3 Getting Started with Tasks
Selection
Pane
Tasks: Data
Select Data to define how columns are used to generate
the task result.
Help is displayed
when a Task role
is selected.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.1 Introduction to Tasks and Wizards 3-7
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?
10
Type custom
titles or
footnotes.
12
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-8 Chapter 3 Getting Started with Tasks
Tasks: Properties
Task properties can be modified to rename the task,
examine task attributes, and modify the output format.
13
Wizard View
Selected tasks have a wizard view that can be used
to set up the task results quickly.
14
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.1 Introduction to Tasks and Wizards 3-9
15
16
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-10 Chapter 3 Getting Started with Tasks
Objectives
Access the One-Way Frequencies task.
Generate a one-way frequency report and bar chart.
19
Business Scenario
Orion management wants a report that counts the number
of products offered for each category.
20
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-11
21
22
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-12 Chapter 3 Getting Started with Tasks
24
To generate crosstabulation tables, also known as contingency tables, use the Table Analysis task.
25
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-13
3.04 Quiz
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.
How many variables can be assigned to this role?
26
28
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-14 Chapter 3 Getting Started with Tasks
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 on 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 type 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. Type Products per Category in the Label field. Click OK.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-15
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-16 Chapter 3 Getting Started with Tasks
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
Scroll down in the Results window to find the Order output data by option.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.2 Creating a Frequency Report 3-17
Partial Results
Challenge
Documentation about the BYLINE and NOBYLINE system options can be found
by selecting Help SAS Syntax Help. On the Index tab, type byline.
e. To reinstate the secondary BYLINE title for future tasks, add the following statement at the end
of the task code:
options byline;
f. Create the modified report and replace the results.
g. Save the Chapter3 project.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-18 Chapter 3 Getting Started with Tasks
Partial Results
Objectives
List output format options.
Compare the advantages of each output format.
34
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.3 Generating HTML, PDF, and RTF Output 3-19
Business Scenario
Orion management wants to publish a product
categories frequency report in HTML format
on the intranet.
35
36
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-20 Chapter 3 Getting Started with Tasks
Summary
One-Way Statistics task
Frequencies task
37
38
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.3 Generating HTML, PDF, and RTF Output 3-21
3.06 Quiz
What are some advantages of each format?
39
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-22 Chapter 3 Getting Started with Tasks
42
43
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.3 Generating HTML, PDF, and RTF Output 3-23
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, PDF, and text results can all be viewed directly on the Results tabs.
Clicking the RTF Results tab opens the results in Microsoft Word.
Partial Results (Notice the SAS Report, HTML, PDF, RTF, and Listing tabs.)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-24 Chapter 3 Getting Started with Tasks
46
Objectives
Access the List Data task.
Set report options.
Group the report.
49
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.4 Creating a Listing Report 3-25
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.
50
Display
each row.
Sum
columns.
51
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-26 Chapter 3 Getting Started with Tasks
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.
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 type Orion Star Customer List.
5. Click Run to generate the report.
Partial Results
6. To modify the task to change the column labels and remove the row numbers, select Modify Task
on the Results tab.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.4 Creating a Listing Report 3-27
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, type Name in the Label field and click OK.
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 type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-28 Chapter 3 Getting Started with Tasks
Partial Results
Objectives
Filter data directly in a task.
Using various operators, build multiple filter criteria.
55
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-29
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.
56
57
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-30 Chapter 3 Getting Started with Tasks
58
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
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-31
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.
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 type "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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-32 Chapter 3 Getting Started with Tasks
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 type 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. Type
High Act/1970+ in the Label field. Click OK.
13. Click Run and examine the final report.
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. Type This report
includes customers in high activity groups born in 1970 or later.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-33
16. To rename the Note icon in the project, click the Properties button and type Filter Detail
in the Label field. Click OK.
Exercises
Level 1
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-34 Chapter 3 Getting Started with Tasks
Partial Results
Level 2
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.5 Filtering Data in a Task 3-35
Challenge
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-36 Chapter 3 Getting Started with Tasks
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.
64
Business Scenario
Management wants to see a comparison of average
customer age by country.
65
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-37
66
For more details about the graph output formats, select Help SAS Enterprise Guide Help.
Type setting results and graph options on the Search tab and select the third returned entry.
67
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-38 Chapter 3 Getting Started with Tasks
68
69
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-39
70
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-40 Chapter 3 Getting Started with Tasks
6. Click , change the statistic to Average, and click OK. Click Next.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-41
8. In Step 4, change the title to Average Customer Age by Country and click Finish.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-42 Chapter 3 Getting Started with Tasks
13. Select Horizontal Axis in the Selection pane. Type Average Customer Age in the Label box
and change the font size to 12.
14. Select Reference Lines in the Selection pane. Click the Specify values for lines check box, type 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. Type 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-43
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.
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 by selecting Developer Design Mode.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-44 Chapter 3 Getting Started with Tasks
• 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.
Exercises
Level 1
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.
h. Run the task and replace the results. Save the project as Chapter3.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.6 Creating a Graph 3-45
Level 2
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-46 Chapter 3 Getting Started with Tasks
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.
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-47
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-48 Chapter 3 Getting Started with Tasks
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 type 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 type Dept Freq Report.
4) Click OK.
f. Generate the report and examine the results.
1) Click Run.
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.
Type Chapter3 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-49
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-50 Chapter 3 Getting Started with Tasks
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 type 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.
Type Chapter3 in the File name field and select Save.
Partial Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-51
c. Access the code in the One-Way Frequencies task by selecting Preview Code Insert Code.
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, click the Insert Code button to open the User Code
window.
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, type byline.
1) Double-click on the first line that indicates <double-click to insert code>.
2) In the Enter User Code window, enter the following SAS OPTIONS statement:
options nobyline;
3) Click OK.
e. To reinstate the secondary BYLINE title for future tasks, add the following statement at the end
of the task code:
options byline;
1) Double-click on the last line that indicates <double-click to insert code>.
2) In the Enter User Code window, enter the following SAS OPTIONS statement:
options byline;
3) Click OK to close the Enter User Code window.
4) Click OK to close the User Code window.
5) Close the Code Preview for Task window by clicking in the upper right corner.
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter3 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-52 Chapter 3 Getting Started with Tasks
Partial Results
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-53
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.
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter3 in the File name field and select Save.
Partial Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-54 Chapter 3 Getting Started with Tasks
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-55
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter3 in the File name field and select Save.
Partial Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-56 Chapter 3 Getting Started with Tasks
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, type MONTH Function.
1) In the List Data task dialog box, click the Preview Code button to open the Code Preview
for Task window.
2) In this window, select Insert Code to open the User Code window.
3) Double-click <double-click to insert code> immediately below the FORMAT statement
and above the RUN statement for PROC PRINT.
4) In the Enter User code window, enter the following SAS statement:
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-57
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter3 in the File name field and select Save.
Partial Results
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-58 Chapter 3 Getting Started with Tasks
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-59
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.
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter3 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-60 Chapter 3 Getting Started with Tasks
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.
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, type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-61
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-62 Chapter 3 Getting Started with Tasks
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.
Type 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-63
11
23
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-64 Chapter 3 Getting Started with Tasks
27
40
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3.7 Solutions 3-65
47
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
3-66 Chapter 3 Getting Started with Tasks
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 4 Creating Simple Queries
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-3
Objectives
State the function of the Filter and Sort task
the Query Builder and Data Explorer.
Compare the functionality 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 © 2014, 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
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-5
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 © 2014, 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 type query output on the Search tab. Select
the second topic that is returned in the list: Setting Options for the Current Query.
Business Scenario
Orion Star wants to analyze Internet sales since 2010.
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 2010
12
Copyright © 2014, 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 © 2014, 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.
Orion Star would like to analyze Internet sales that occurred since the beginning of 2010. 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 01JAN2010, 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-9
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 typed in this form:
"DDMONYYYY"d. For example, January 1, 2010 would be typed as "01JAN2010"d.
5. Click the Sort tab. Select Order_Date as the sort variable and change the sort sequence
to Descending.
6. Click the Results tab. Type Internet Orders 2010+ in the Task name field. Click Change
and type internetorders2010 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, 6 of 13 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-10 Chapter 4 Creating Simple Queries
9. The Query Builder enables you to name the query icon and the name and storage location
of the SAS table that you created. Type Internet Orders 2010+ Query in the Query name field.
Click Change next to the Output name field. Type internet2010query 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.
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 .
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 01JAN2010, click the Filter Data tab.
Drag and drop Order_Type to the Filter Data tab to start the Basic Filter Wizard.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-11
14. In Step 1, change the operator to Equal to and type 3 in the Value field.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-12 Chapter 4 Creating Simple Queries
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.
Partial Results (8 of 55 rows, 6 of 13 columns)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-13
Data Explorer
The Data Explorer provides an alternative way to
interactively filter and sort data and build a Query task
in the project.
15
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. Examine the Data Explorer, including placing your
cursor over each column header.
What are the two methods that you can use to filter
and sort in the Data Explorer?
16
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-14 Chapter 4 Creating Simple Queries
Data Explorer
Pending updates are queued
and not applied until you
click Apply Updates.
18
Data Explorer
A Query task can be added to the process flow with
the instructions to filter and sort the data.
19
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-15
20
21
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-16 Chapter 4 Creating Simple Queries
23
Sort data
Join tables
Remove duplicates
25
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-17
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)
When you create the filter, remember that Sales is case sensitive.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-18 Chapter 4 Creating Simple Queries
Level 2
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.1 Filtering and Sorting Data 4-19
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
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.
e. Submit the task to create the new table.
Partial Results (8 of 47 rows)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-20 Chapter 4 Creating Simple Queries
Objectives
Define a new column of data in a query by building
an expression.
30
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
31
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns with an Expression 4-21
Computed Columns
New summarized columns, recoded columns, or columns
based on an expression can be added to a query
in the Query Builder.
32
33
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-22 Chapter 4 Creating Simple Queries
SAS Functions
A SAS function is a routine that returns a value
that is determined from specified arguments.
function-name(argument1,argument2, . . .)
Example:
sum(Salary,Bonus)
34
35
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns with an Expression 4-23
Var1+Var2+Var3
36
sum(Var1,Var2,Var3)
38
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-24 Chapter 4 Creating Simple Queries
If you do not have the Chapter4 project, you can create a new project.
2. Type Shipping Detail Query in the Query name field. Click Change and type 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 type a minus sign. Double-click Order_Date to complete the
expression. Click Next.
7. In Step 3, type Days_to_Deliver in the Column Name field. Type Days to Deliver
in the Label field. Click Next.
8. In Step 4, review the summary of the new column’s properties and click Finish.
9. Repeat the process to create the Invoice_Amt column. Begin by clicking .
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns with an Expression 4-25
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, type Invoice_Amt in the Column Name field. Type 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 8 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-26 Chapter 4 Creating Simple Queries
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.2 Creating New Columns with an Expression 4-27
Level 2
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)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-28 Chapter 4 Creating Simple Queries
Challenge
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.
c. Run the query, verify the results, and save the Chapter4 project.
Partial Results (8 of 308 rows)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.3 Grouping and Summarizing Data in a Query 4-29
Objectives
Assign a grouping variable in a query.
Select the analysis variable and the summary statistic
to compute.
Filter grouped data.
45
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
46
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-30 Chapter 4 Creating Simple Queries
Grouping Data
The Query Builder can
be used to group and
summarize data.
47
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.3 Grouping and Summarizing Data in a Query 4-31
Grouping Data
The Select Data tab can be used to group and summarize
data.
Choose a statistic
for columns to
be summarized.
A summarized column can also be created by using the New Computed Column Wizard.
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:
COUNT, FREQ, N (number nonmissing values) STDERR (standard error of the mean)
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-32 Chapter 4 Creating Simple Queries
49
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.
50
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.3 Grouping and Summarizing Data in a Query 4-33
Filtering Data
The Filter Data tab can be used to filter both raw data
and summarized data.
52
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-34 Chapter 4 Creating Simple Queries
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. Type 500 in the Value field and click Finish.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.3 Grouping and Summarizing Data in a Query 4-35
Exercises
Level 1
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
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-36 Chapter 4 Creating Simple Queries
Level 2
Challenge
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-37
Look for the appropriate option by selecting Options Options for this query.
g. Submit the query and view the report. Save the Chapter4 project.
Results
Objectives
Join multiple tables by common columns.
Include only matching rows.
58
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-38 Chapter 4 Creating Simple Queries
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.
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.
60
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-39
61
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.
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.
62
To learn more about the join types, select Help in the Tables and Joins window, and then select
Understanding the types of joins.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-40 Chapter 4 Creating Simple Queries
Join Types
By default, the Query Builder performs an inner join,
which includes matching rows only in the results.
Employee_Payroll Employee_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
63
Join Types
A full outer join includes all rows from both tables.
Employee_Payroll Employee_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
64
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-41
Join Types
A left join includes all rows from Employee_Payroll.
Employee_Payroll Employee_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
65
Employee_Payroll Employee_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
66
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-42 Chapter 4 Creating Simple Queries
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.
68
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 data set.
2. Add the products SAS table to the project.
3. Add the country_lookup Excel file to the project. 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.
4. Right-click topproducts in the project tree or process flow and select Query Builder.
5. Name the query Top Products Info Query and the output table topproductsinfo.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-43
6. Select Add Tables. Verify that the Project icon is selected in the Open Data window. Hold down
the Ctrl key and select the products and country_lookup tables. Select Open.
To view the full table names, you can click and change the view to Details.
7. A message appears and indicates that Enterprise Guide was unable to find matching columns
on which to join in all three tables. Click OK.
8. 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 t3 Country_Key.
9. 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.Supplier_Country = t3.Country_Key.
10. Verify that the three tables are linked as displayed below. Click OK Close to return to the Select
Data tab.
11. 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-44 Chapter 4 Creating Simple Queries
12. Click Run to execute the query. Verify the results and save the Chapter4 project.
Partial Results (8 of 19 rows)
Exercises
Level 1
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 01JAN2009.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.4 Joining Tables 4-45
Level 2
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)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-46 Chapter 4 Creating Simple Queries
f. Submit the query and view the results. Save the Chapter4 project.
Partial Results (8 of 300 rows)
Challenge
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-47
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-48 Chapter 4 Creating Simple Queries
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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) Type Sales Employees Query in the Query name field.
3) Click Change and type 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) Type 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.
d. Run the query and verify the results. Save the Chapter4 project.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-49
1) Click Run.
2) Click on the toolbar.
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter4 in the File name field and select Save.
Partial Results (8 of 189 rows)
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-50 Chapter 4 Creating Simple Queries
5) Click on the second filter and select the Conditional Filter tab.
6) Change is equal to to is less than and type 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.
f. Use Quick Stats to answer the following questions regarding this subset of employees:
1) Select 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? 01JAN1976
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) Select on the toolbar.
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter4 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-51
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.
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) Type 1 for the second argument to indicate that characters in the first position should
be extracted. Enter a comma and then type 3 to indicate to extract three characters.
7) Move the cursor outside the close parenthesis and type ="920" to set the filter condition.
The complete filter should appear as follows:
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-52 Chapter 4 Creating Simple Queries
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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) Type New Salary Query in the Query name field.
3) Click Change to the right of the Output name field.
4) Type New_Salary in the File name field. Select Save.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-53
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, type 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 type . (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.
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, type * (the multiplication operator), and type 1.02
for the operand. The final expression appears as follows:
6) Click Next.
7) In Step 3 of the wizard, type New_Salary in the Column Name field.
8) Click Change next to the Format field.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-54 Chapter 4 Creating Simple Queries
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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, type Total Donations Query.
3) Click Change. In the File name field, type 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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-55
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter4 in the File name field and select Save.
Partial Results (8 of 124 rows)
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-56 Chapter 4 Creating Simple Queries
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, type Years Employed Query.
5) Click Change. Type 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 today's 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.
4) Use the available functions list or enter the following expression:
yrdif(Employee_Hire_Date, today( ), 'age')
5) Click Next. Type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-57
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.
Type Chapter4 in the File name field and select Save.
Partial Results (8 of 308 rows)
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.
1) Select Query Builder in the data grid.
2) Type Average Salary per City Query in the Query name field.
3) Click Change and type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-58 Chapter 4 Creating Simple Queries
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.
Type Chapter4 in the File name field and select Save.
Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-59
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 .
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter4 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-60 Chapter 4 Creating Simple Queries
Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-61
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 type 10.
4) Select Titles in the Selection pane and select the Override the corresponding default
settings in Tools->Options check box.
5) Type Top 10 Average Salaries by Job Title and click OK.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-62 Chapter 4 Creating Simple Queries
g. Submit the query and view the report. Save the Chapter4 project.
Results
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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) Right-click employee_payroll and select Query Builder.
2) Type Payroll Location Join Query in the Query name field.
3) Click Change. Type employee_payroll_location in the File name field. Select Save.
4) Select Add Tables. Verify that the Project icon is active. Select the employee_addresses
table. Select Open.
If you cannot see the full table names in the Open Data window, click Details.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-63
c. Open the Tables and Joins window to verify that the join between the two tables
is on the Employee_ID column.
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 .
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, type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-64 Chapter 4 Creating Simple Queries
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter4 in the File name field and select Save.
Partial Results (8 of 308 rows)
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-65
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.
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 .
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter4 in the File name field and select Save.
Partial Results (8 of 308 rows)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-66 Chapter 4 Creating Simple Queries
3) Click Change and type 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 right-table given
a condition.
3) Click OK Close.
d. Include all columns from the employee_addresses table.
Drag the t2(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.
Type Chapter4 in the File name field and select Save.
Partial Results (8 of 300 rows)
Use the Query Builder to join the data from two sources where the join condition involves
a non-equijoin condition.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-67
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-68 Chapter 4 Creating Simple Queries
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter4 in the File name field and select Save.
Partial Results (8 of 424 rows)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-69
10
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-70 Chapter 4 Creating Simple Queries
17
22
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-71
24
Var1+Var2+Var3
37
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-72 Chapter 4 Creating Simple Queries
sum(Var1,Var2,Var3)
39
with
without grouping
grouping
51
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4.5 Solutions 4-73
Employee_Payroll Employee_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
67
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
4-74 Chapter 4 Creating Simple Queries
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 5 Creating Summarized
Output
5.2 Creating a Summary Report with the Summary Tables Task ................................... 5-11
Demonstration: Creating a Tabular Summary Report .......................................................... 5-12
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-3
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-4 Chapter 5 Creating Summarized Output
Options available in Advanced View that are not available using the wizard include the following:
• 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-5
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-6 Chapter 5 Creating Summarized Output
8. In Step 4, delete the default analysis title and type Summary of Profit by Product Line/Category.
Click Finish.
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. Type Profit by Product Summary.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-7
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. Type 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 by appending the current date and time to the existing
filename.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-8 Chapter 5 Creating Summarized Output
Exercises
Level 1
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. Type 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.
g. As a step in the project, export the output data to an Excel file named SalaryStats.xlsx.
h. Save the Chapter5 project.
Partial Results
Level 2
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.1 Generating Summary Statistics 5-9
d. Type 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.
Partial Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-10 Chapter 5 Creating Summarized Output
Challenge
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.2 Creating a Summary Report with the Summary Tables Task 5-11
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-12 Chapter 5 Creating Summarized Output
Summary Tables
The Summary Tables Wizard or task can be used
to generate a tabular summary report.
14
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.2 Creating a Summary Report with the Summary Tables Task 5-13
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-14 Chapter 5 Creating Summarized Output
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.2 Creating a Summary Report with the Summary Tables Task 5-15
17. In the Heading Properties window, type 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.
18. Change the column heading for the Product_Line subtotals by right-clicking the Total label
and selecting Heading Properties.
19. Type 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 specify a label for missing values, right-click anywhere on the table and select Table Properties.
23. In the Table Properties window, click the General tab. Delete the default label in the Label for
missing values field and type **. Click OK.
24. Click Run to generate the final report. Click Yes when you are prompted to replace the results.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-16 Chapter 5 Creating Summarized Output
Exercises
Level 1
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.
k. Generate the report and save the Chapter5 project.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.2 Creating a Summary Report with the Summary Tables Task 5-17
Level 2
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.
h. Change the task label to AU Salary Report. Generate the report and save the Chapter5 project.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-18 Chapter 5 Creating Summarized Output
Challenge
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-19
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) Type salary_stats in the File name field and select Save.
4) Click Next.
e. Type 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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-20 Chapter 5 Creating Summarized Output
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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.
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. Type Summary Statistics for Salary by Department and State as the title and delete
the footnote.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-21
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.
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, type 1.
4) Click Run Yes when you are prompted to replace the results.
5) Click on the toolbar.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-22 Chapter 5 Creating Summarized Output
6) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter5 in the File name field and select Save.
Partial Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-23
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 Summary Statistics icon under EMPLOYEE_MASTER in the project tree
or process flow and select Open Open in Advanced View.
2) Select Preview Code Insert Code.
3) Scroll down to find the end of the PROC MEANS statement. Double-click to insert custom
code between the N option and the semicolon.
4) In the Enter User Code window, type skewness.
5) Click OK OK and close the Code Preview window.
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.
Type Chapter5 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-24 Chapter 5 Creating Summarized Output
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-25
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, type 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, type 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, type 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 type a hyphen (-) in the Label for
missing value field. Click OK to close the window.
j. Change the task label to Salary Ranges by Country.
1) Select Properties in the Selection pane and click Edit.
2) Type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-26 Chapter 5 Creating Summarized Output
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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.
c. Add the Salary variable as the analysis variable three times and 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-27
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. Type 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 type Summary of Salaries
for Australia by Department.
2) Delete the text in the Footnote field.
3) Click Finish 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.
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.
Type 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.
Type Employee Count in the Label field. Click OK.
2) Right-click either ColPctN statistic under the city variable, and select Heading Properties.
Type Percent of Employees in the Label field. Click OK.
3) Right-click either ColPctSum statistic under the city variable, and select Heading Properties.
Type Percent of Salaries in the Label field. Click OK.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-28 Chapter 5 Creating Summarized Output
4) Right-click the N statistic under the Total column, and select Heading Properties.
Type 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) Type 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.
5) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter5 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5.3 Solutions 5-29
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.
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.
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.
3) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter5 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
5-30 Chapter 5 Creating Summarized Output
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 6 Using Prompts in Tasks
and Queries
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.1 Prompting in Projects 6-3
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 © 2014, 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.1 Prompting in Projects 6-5
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-6 Chapter 6 Using Prompts in Tasks and Queries
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.2 Creating and Using 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
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-8 Chapter 6 Using Prompts in Tasks and Queries
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.
15
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.2 Creating and Using Prompts in Tasks 6-9
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.
18
In the code, macro variables are referenced by preceding the prompt name with & (an ampersand).
Copyright © 2014, 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, type ProfitCategories in the Name field. Type 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 and Product_Name are
not appropriate variables to use in the Bar Chart task, remove them from the list by highlighting both
variables and clicking .
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.2 Creating and Using 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.
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 type Profit by &ProfitCategories.
Copyright © 2014, 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.2 Creating and Using Prompts in Tasks 6-13
Exercises
Level 1
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, type 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.
Copyright © 2014, 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.
Objectives
List prompt types that can be used in query filters.
Retrieve prompt values from a data source.
Use prompts in a query.
24
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Using Prompts in Queries 6-15
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
26
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-16 Chapter 6 Using Prompts in Tasks and Queries
27
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Using Prompts in Queries 6-17
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.
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. Type Choose a Supplier Query in the Query name field. Click Change and type 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, type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-18 Chapter 6 Using Prompts in Tasks and Queries
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Using Prompts in Queries 6-19
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.
13. Select Titles in the Selection pane and select the Override the corresponding default settings in
Tools->Options check box. Type 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.
Exercises
Level 1
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, type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-20 Chapter 6 Using Prompts in Tasks and Queries
h. Click to rerun the query. Select Sydney in the prompt and click Run.
Level 2
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.3 Creating and Using Prompts in Queries 6-21
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-22 Chapter 6 Using Prompts in Tasks and Queries
Challenge
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 in the Program toolbar.
Add the &SelectDept prompt to the properties.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-23
e. Run the program with Engineering as the selected value and verify the results. Save the
Chapter6 project.
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, type 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) Type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-24 Chapter 6 Using Prompts in Tasks and Queries
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.
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, type Average Annual Salary.
5) Click OK Next.
6) In Step 4, delete the default title and type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-25
To use another charting variable, click the Refresh button in the Graph window
and select another variable in the prompt.
Results
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-26 Chapter 6 Using Prompts in Tasks and Queries
1) Right-click the employee_master table in the project tree or process flow and select
Query Builder.
2) Type Select City Query in the Query name field.
3) Click Change. In the File name field, type select_city and select Save.
4) Right-click t1 (employee_master) and select Select All Columns.
c. Use the Prompt Manager to create a new prompt. On the General tab, type 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) Type SelectCity in the Name field.
3) Type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-27
4) Click next to the Value field. Click the Prompts tab and select &SelectCity.
5) Click Next.
6) Review the summary and Click Finish.
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, 9 of 15 columns)
h. Click to rerun the query. Select Sydney in the prompt and select Run.
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter6 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-28 Chapter 6 Using Prompts in Tasks and Queries
If you do not have the Chapter6 project, you can create a new project and add the
employee_master data set.
1) In the project tree, right-click the employee_master data set and select Query Builder.
2) Type Employee Hire Date Query in the Query name field.
3) Click Change and type 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, type DateRange. In the Displayed Text field, type 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-29
e. Submit the query and set the range of dates from January 1, 1976 to December 31, 1989.
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 type 1976. Type December 31, 1989 in the To field.
Partial Results (8 of 113 rows, 5 of 15 columns)
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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, type SelectCities in the Name field and type Select Cities to Include:
in the Display Text field.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-30 Chapter 6 Using Prompts in Tasks and Queries
4) Click Run and verify that the output table has 73 rows.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-31
6) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter6 in the File name field and select Save.
Partial Results (8 of 73 rows, 9 of 15 columns)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-32 Chapter 6 Using Prompts in Tasks and Queries
4) If the Save window appears, navigate to the location that is specified by your instructor.
Type Chapter6 in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6.4 Solutions 6-33
16
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
6-34 Chapter 6 Using Prompts in Tasks and Queries
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 7 Customizing and
Organizing Project Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.1 Combining Results 7-3
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 © 2014, 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 © 2014, 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?
Updating Results
As tasks are rerun and updated, the report automatically
includes the current 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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-6 Chapter 7 Customizing and Organizing Project Results
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.1 Combining Results 7-7
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-8 Chapter 7 Customizing and Organizing Project Results
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-9
Each time that the Export task is run, a new file is created with a date and time.
They are appended to the filename.
Objectives
Demonstrate methods for updating project results.
Run a subset of the process flow diagram.
Build and run a new process flow diagram.
15
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-10 Chapter 7 Customizing and Organizing Project Results
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
Updating Results
Selecting Run enables you to update the following:
the highlighted project item
17
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-11
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
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
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-12 Chapter 7 Customizing and Organizing Project Results
21
22
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-13
7.03 Poll
Double-click the CUSTOMERS table. Does it open?
Yes
No
23
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-14 Chapter 7 Customizing and Organizing Project Results
26
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-15
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
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 type 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 move project items into the Autoexec flow, double-click Process Flow in the project tree to return
to the original process flow.
4. The Assign Project Library and Create Format tasks should run automatically when the project opens.
Drag the cursor across the first two tasks to highlight them. Right-click one of the highlighted items
and select Move To Autoexec.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-16 Chapter 7 Customizing and Organizing Project Results
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.2 Updating and Organizing Projects 7-17
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-18 Chapter 7 Customizing and Organizing Project Results
Exercises
Level 1
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.3 Solutions 7-19
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-20 Chapter 7 Customizing and Organizing Project Results
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.3 Solutions 7-21
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-22 Chapter 7 Customizing and Organizing Project Results
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.3 Solutions 7-23
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, type 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.
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 type ProjectLog1
in the File name field. Save the file as a text (.txt) file. Select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-24 Chapter 7 Customizing and Organizing Project Results
20
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7.3 Solutions 7-25
24
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
7-26 Chapter 7 Customizing and Organizing Project Results
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Chapter 8 Learning More
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8.1 SAS Resources 8-3
Objectives
Identify the areas of support that SAS offers.
Education
Comprehensive training delivers greater value to your
organization.
http://support.sas.com/training/
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8-4 Chapter 8 Learning More
SAS Publishing
SAS offers a complete selection of publications to help
customers use SAS software to its fullest potential.
http://support.sas.com/publishing/
computer-based
certification exams –
typically 60-70 questions
and 2-3 hours in length
preparation materials and
practice exams
worldwide directory of
SAS Certified Professionals
http://support.sas.com/certify/
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8.1 SAS Resources 8-5
Support
SAS provides a variety of self-help and assisted-help
resources.
http://support.sas.com/techsup/
User Groups
SAS supports many local, regional, international,
and special-interest SAS user groups.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8-6 Chapter 8 Learning More
SAS Blogs
SAS provides access to several featured blogs
at http://blogs.sas.com.
SAS Blogs
Visit http://blogs.sas.com/sasdummy to read about
interesting tips and insights regarding SAS Enterprise
Guide.
10
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8.2 Beyond This Course 8-7
11
Objectives
Identify the next set of courses that follow this course.
13
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8-8 Chapter 8 Learning More
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
14
Next Steps
To learn more about this: Enroll in the following:
SAS® Programming 1:
SAS Programming
Essentials
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8.2 Beyond This Course 8-9
Next Steps
In addition, there are prerecorded, short, technical
discussions and demonstrations that are referred
to as e-lectures.
http://support.sas.com/training/
16
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
8-10 Chapter 8 Learning More
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Appendix A Writing and Submitting
SAS® Programs
Exercises ..............................................................................................................................A-19
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-3
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-4 Appendix A Writing and Submitting SAS® Programs
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-5
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-6 Appendix A Writing and Submitting SAS® Programs
Copyright © 2014, 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.
10 e1Aa01.sas
A.02 Quiz
Examine the Program and Log tabs. What differences
do you observe?
12
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-8 Appendix A Writing and Submitting SAS® Programs
14
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 © 2014, 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.
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 © 2014, 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
variable names
19
The autocomplete feature automatically suggests appropriate keywords. You can manually open
the Autocomplete window by using the following shortcut keys:
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 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-11
20
Rearranging Windows
Stacking windows enables you to view two components
in the project simultaneously.
21
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-12 Appendix A Writing and Submitting SAS® Programs
22
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-13
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-14 Appendix A Writing and Submitting SAS® Programs
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.
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
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-15
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. Type 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.
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.
You can view syntax tooltips by positioning the pointer over items in the autocomplete windows.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-16 Appendix A Writing and Submitting SAS® Programs
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;
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-17
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-18 Appendix A Writing and Submitting SAS® Programs
A.04 Poll
Is the project log overwritten or appended when
the project is run the second time?
overwritten
appended
27
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-19
Exercises
Level 1
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.
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.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-20 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)
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.1 Writing and Submitting SAS Programs A-21
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 today’s date.
As you enter the arguments of the functions, notice the syntax tooltips that are provided.
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-22 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) Type 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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.2 Solutions A-23
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-24 Appendix A Writing and Submitting SAS® Programs
2) If the Save window appears, navigate to the location that is specified by your instructor.
Type 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 today’s date.
As you enter the arguments of the functions, notice the syntax tooltips that are provided.
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 © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.2 Solutions A-25
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.
4) If the Save window appears, navigate to the location that is specified by your instructor.
Type AppendixA in the File name field and select Save.
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-26 Appendix A Writing and Submitting SAS® Programs
11 e1Aa01.sas
13
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A.2 Solutions A-27
28
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A-28 Appendix A Writing and Submitting SAS® Programs
Copyright © 2014, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.