Home Page Icon
Home Page
Table of Contents for
III. Applications
Close
III. Applications
by Rick Wicklin
Statistical Programming with SAS/IML Software
Copyright
Acknowledgments
I. Programming in the SAS/IML Language
1. An Introduction to SAS/IML Software
1.1 Overview of the SAS/IML Language
1.2 Comparing the SAS/IML Language and the DATA Step
1.3 Overview of SAS/IML Software
1.3.1 Overview of the IML Procedure
1.3.2 Running a PROC IML Program
1.3.3 Overview of SAS/IML Studio
1.3.4 Installing and Invoking SAS/IML Studio
1.3.5 Running a Program in SAS/IML Studio
1.3.6 Using SAS/IML Studio for Exploratory Data Analysis
1.4 Who Should Read This Book?
1.5 Overview of This Book
1.6 Possible Roadmaps through This Book
1.7 How to Read the Programs in This Book
1.8 Data and Programs Used in This Book
1.8.1 Installing the Example Data on a Local SAS Server
1.8.2 Installing the Example Data on a Remote SAS Server
2. Getting Started with the SAS/IML Matrix Programming Language
2.1 Overview of the SAS/IML Language
2.2 Creating Matrices
2.2.1 Printing a Matrix
2.2.2 The Dimensions of a Matrix
2.2.3 The Type of a Matrix
2.2.4 The Length of a Character Matrix
2.3 Using Functions to Create Matrices
2.3.1 Constant Matrices
2.3.2 Vectors of Sequential Values
2.3.3 Pseudorandom Matrices
2.4 Transposing a Matrix
2.5 Changing the Shape of Matrices
2.6 Extracting Data from Matrices
2.6.1 Extracting Rows and Columns
2.6.2 Matrix Diagonals
2.6.3 Printing a Submatrix or Expression
2.7 Comparision Operators
2.8 Control Statements
2.8.1 The IF-THEN/ELSE Statement
2.8.2 The Iterative DO Statement
2.9 Concatenation Operators
2.10 Logical Operators
2.11 Operations on Sets
2.12 Matrix Operators
2.12.1 Elementwise Operators
2.12.2 Matrix Computations
2.13 Managing the SAS/IML Workspace
3. Programming Techniques for Data Analysis
3.1 Overview of Programming Techniques
3.2 Reading and Writing Data
3.2.1 Creating Matrices from SAS Data Sets
3.2.2 Creating SAS Data Sets from Matrices
3.3 Frequently Used Techniques in Data Analysis
3.3.1 Applying a Variable Transformation
3.3.2 Locating Observations That Satisfy a Criterion
3.3.3 Assigning Values to Observations That Satisfy a Criterion
3.3.4 Handling Missing Values
3.3.5 Analyzing Observations by Categories
3.4 Defining SAS/IML Modules
3.4.1 Function and Subroutine Modules
3.4.2 Local Variables
3.4.3 Global Symbols
3.4.4 Passing Arguments by Reference
3.4.5 Evaluation of Arguments
3.4.6 Storing Modules
3.4.7 The IMLMLIB Library of Modules
3.5 Writing Efficient SAS/IML Programs
3.5.1 Avoid Loops to Improve Performance
3.5.2 Use Subscript Reduction Operators
3.5.3 Case Study: Standardizing the Columns of a Matrix
3.6 Case Study: Finding the Minimum of a Function
3.7 References
4. Calling SAS Procedures
4.1 Overview of Calling SAS Procedures
4.2 Calling a SAS Procedure from IMLPlus
4.3 Transferring Data between Matrices and Procedures
4.4 Passing Parameters to SAS Procedures
4.5 Case Study: Computing a Kernel Density Estimate
4.6 Creating Names for Output Variables
4.7 Creating Macro Variables from Matrices
4.8 Handling Errors When Calling a Procedure
4.9 Calling SAS Functions That Require Lists of Values
II. Programming in SAS/IML Studio
5. IMLPlus: Programming in SAS/IML Studio
5.1 Overview of the IMLPlus Language
5.2 Calling SAS Procedures
5.2.1 Passing Parameters to a SAS Procedure
5.2.2 Checking the Return Code from a SAS Procedure
5.3 Calling R Functions
5.4 IMLPlus Graphs
5.5 Managing Data in Memory
5.6 Using Expressions When Reading or Writing Data
5.7 IMLPlus Modules
5.7.1 Storing and Loading IMLPlus Modules
5.7.1.1 Conventions for Saving Modules
5.7.1.2 Loading IMLPlus Modules
5.7.2 Local Variables in Modules
5.7.3 Creating an Alias for a Module
5.8 The IMLPlus Module Library
5.9 Features for Debugging Programs
5.9.1 Jumping to the Location of an Error
5.9.2 Jumping to Errors in Modules
5.9.3 Using the Auxiliary Input Window as a Debugging Aid
5.9.4 Using the PAUSE Statement as a Debugging Aid
5.10 Querying for User Input
5.11 Differences between IMLPlus and the IML Procedure
6. Understanding IMLPlus Classes
6.1 Overview of Understanding IMLPlus Classes
6.2 Object-Oriented Terminology
6.3 The DataObject Class
6.4 Base and Derived Classes
6.5 Creating a Graph
6.6 Creating Dynamically Linked Graphs
6.7 The Plot Class: A Base Class for Graphs
6.8 The Data Table Class
6.9 The DataView Class: A Base Class for Graphs and Data Tables
6.10 Passing Objects to IMLPlus Modules
6.11 Using a Base Class in a Module
7. Creating Statistical Graphs
7.1 Overview of Creating Statistical Graphs
7.2 The Source of Data for a Graph
7.3 Bar Charts
7.3.1 Creating a Bar Chart from a Vector
7.3.2 Creating a Bar Chart from a Data Object
7.3.3 Modifying the Appearance of a Graph
7.3.4 Frequently Used Bar Chart Methods
7.4 Histograms
7.4.1 Creating a Histogram from a Vector
7.4.2 Creating a Histogram from a Data Object
7.4.3 Frequently Used Histogram Methods
7.5 Scatter Plots
7.5.1 Creating a Scatter Plot from Vectors
7.5.2 Creating a Scatter Plot from a Data Object
7.6 Line Plots
7.6.1 Creating a Line Plot for a Single Variable
7.6.1.1 Creating a Line Plot from Vectors
7.6.1.2 Creating a Line Plot from a Data Object
7.6.2 Creating a Line Plot for Several Variables
7.6.2.1 Creating a Line Plot from Vectors
7.6.2.2 Creating a Line Plot from a Data Object
7.6.3 Creating a Line Plot with a Classification Variable
7.6.3.1 Creating a Line Plot from Vectors
7.6.3.2 Creating a Line Plot from a Data Object
7.6.4 Frequently Used Line Plot Methods
7.7 Box Plots
7.7.1 Creating a Box Plot
7.7.1.1 Creating a Box Plot from a Vector
7.7.1.2 Creating a Box Plot from a Data Object
7.7.2 Creating a Grouped Box Plot
7.7.2.1 Creating a Grouped Box Plot from Vectors
7.7.2.2 Creating a Grouped Box Plot from a Data Object
7.7.3 Frequently Used Box Plot Methods
7.8 Summary of Graph Types
7.9 Displaying the Data Used to Create a Graph
7.10 Changing the Format of a Graph Axis
7.11 Summary of Creating Graphs
7.12 References
8. Managing Data in IMLPlus
8.1 Overview of Managing Data in IMLPlus
8.2 Creating a Data Object
8.3 Creating a Data Object from a SAS Data Set
8.4 Creating Linked Graphs from a Data Object
8.5 Creating a Data Object from a Matrix
8.6 Creating a SAS Data Set from a Data Object
8.7 Creating a Matrix from a Data Object
8.8 Adding New Variables to a Data Object
8.8.1 Variable Transformations
8.8.2 Adding Variables for Predicted and Residual Values
8.8.3 A Module to Add Variables from a SAS Data Set
8.9 Review: The Purpose of the DataObject Class
9. Drawing on Graphs
9.1 Drawing on a Graph
9.1.1 Example: Overlaying a Regression Curve on a Scatter Plot
9.1.2 Graph Coordinate Systems and Drawing Regions
9.1.2.1 Drawing in the Coordinate System of the Data
9.1.2.2 Drawing on a Graph That Displays a Categorical Variable
9.1.3 Drawing in the Foreground and Background
9.1.4 Case Study: Adding a Prediction Band to a Scatter Plot
9.1.5 Practical Differences between the Coordinate Systems
9.2 Drawing Legends and Insets
9.2.1 Drawing a Legend
9.2.2 Drawing an Inset
9.3 Adjusting Graph Margins
9.4 A Module to Add Lines to a Graph
9.5 Case Study: A Module to Draw a Rug Plot on a Graph
9.6 Case Study: Plotting a Density Estimate
9.7 Case Study: Plotting a Loess Curve
9.8 Changing Tick Positions for a Date Axis
9.9 Case Study: Drawing Arbitrary Figures and Diagrams
9.10 A Comparison between Drawing in IMLPlus and PROC IML
10. Marker Shapes, Colors, and Other Attributes of Data
10.1 Overview of Data Attributes
10.2 Changing Marker Properties
10.2.1 Using Marker Shapes to Indicate Values of a Categorical Variable
10.2.2 Using Marker Colors to Indicate Values of a Continuous Variable
10.2.2.1 Color Representation in IMLPlus
10.2.2.2 Using Color to Mark Outliers
10.2.3 Coloring by Values of a Continuous Variable
10.3 Changing the Display Order of Categories
10.3.1 Setting the Display Order of a Categorical Variable
10.3.2 Using a Statistic to Set the Display Order of a Categorical Variable
10.4 Selecting Observations
10.5 Getting and Setting Attributes of Data
10.5.1 Properties of Variables
10.5.2 Attributes of Observations
III. Applications
11. Calling Functions in the R Language
11.1 Overview of Calling Functions in the R Language
11.2 Introduction to the R Language
11.3 Calling R Functions from IMLPlus
11.4 Data Frames and Matrices: Passing Data to R
11.4.1 Transferring SAS Data to R
11.4.2 What Happens to the Data Attributes?
11.4.3 Transferring Data from R to SAS Software
11.5 Importing Complicated R Objects
11.6 Handling Missing Values
11.6.1 R Functions and Missing Values
11.6.2 Merging R Results with Data That Contain Missing Values
11.7 Calling R Packages
11.7.1 Installing a Package
11.7.2 Calling Functions in a Package
11.8 Case Study: Optimizing a Smoothing Parameter
11.8.1 Computing a Loess Smoother in R
11.8.2 Computing an AICC Statistic in R
11.8.3 Encapsulating R Statements into a SAS/IML Module
11.8.4 Finding the Best Smoother by Minimizing the AICC Statistic
11.8.5 Conclusions
11.9 Creating Graphics in R
11.10 References
12. Regression Diagnostics
12.1 Overview of Regression Diagnostics
12.2 Fitting a Regression Model
12.3 Identifying Influential Observations
12.4 Identifying Outliers and High-Leverage Observations
12.5 Examining the Distribution of Residuals
12.6 Regression Diagnostics for Models with Classification Variables
12.7 Comparing Two Regression Models
12.7.1 Comparing Analyses in Different Workspaces
12.7.2 Comparing Analyses in the Same Workspace
12.8 Case Study: Comparing Least Squares and Robust Regression Models
12.9 Logistic Regression Diagnostics
12.10 Viewing ODS Statistical Graphics
12.11 References
13. Sampling and Simulation
13.1 Overview of Sampling and Simulation
13.2 Simulate Tossing a Coin
13.3 Simulate a Coin-Tossing Game
13.3.1 Distribution of Outcomes
13.3.2 Compute Statistics for the Simulation
13.3.2.1 What is the expected number of coin tosses in a game?
13.3.2.2 What is the expected gain (loss) for playing the game?
13.3.3 Efficiency of the Simulation
13.4 Simulate Rolling Dice
13.5 Simulate a Game of Craps
13.5.1 A First Approach
13.5.2 A More Efficient Approach
13.6 Random Sampling with Unequal Probability
13.7 A Module for Sampling with Replacement
13.8 The Birthday Matching Problem
13.8.1 A Probability-Based Solution for a Simplified Problem
13.8.2 Simulate the Birthday Matching Problem
13.9 Case Study: The Birthday Matching Problem for Real Data
13.9.1 An Analysis of US Births in 2002
13.9.2 The Birthday Problem for People Born in 2002
13.9.3 The Matching Birth Day-of-the-Week Problem
13.9.3.1 A Probability-Based Estimate
13.9.3.2 A Simulation-Based Estimate
13.9.3.3 Compare the Probability-based and Simulation-Based Estimates
13.9.4 The 2002 Matching Birthday Problem
13.10 Calling C Functions from SAS/IML Studio
13.11 References
14. Bootstrap Methods
14.1 An Introduction to Bootstrap Methods
14.2 The Bootstrap Distribution for a Mean
14.2.1 Obtaining a Random Sample
14.2.2 Creating a Bootstrap Distribution
14.2.3 Computing Bootstrap Estimates
14.3 Comparing Two Groups
14.4 Using SAS Procedures in Bootstrap Computations
14.4.1 Resampling by Using the SURVEYSELECT Procedure
14.4.2 Computing Bootstrap Statistics with a SAS Procedure
14.5 Case Study: Bootstrap Principal Component Statistics
14.5.1 Plotting Confidence Intervals on a Scree Plot
14.5.2 Plotting the Bootstrap Distributions
14.6 References
15. Timing Computations and the Performance of Algorithms
15.1 Overview of Timing Computations
15.2 Timing a Computation
15.3 Comparing the Performance of Algorithms
15.3.1 Two Algorithms That Delete Missing Values
15.3.2 Performance as the Size of the Data Varies
15.3.3 Performance as Characteristics of the Data Vary
15.4 Replicating Timings: Measuring Mean Performance
15.5 Timing Algorithms in PROC IML
15.6 Tips for Timing Algorithms
15.7 References
16. Interactive Techniques
16.1 Overview of Interactive Techniques
16.2 Pausing a Program to Enable Interaction
16.3 Attaching Menus to Graphs
16.4 Linking Related Data
16.5 Dialog Boxes in SAS/IML Studio
16.5.1 Displaying Simple Dialog Boxes
16.5.2 Displaying a List in a Dialog Box
16.6 Creating a Dialog Box with Java
16.7 Creating a Dialog Box with R
16.7.1 The Main Idea
16.7.2 A First Modal Dialog Box
16.7.3 A Modal Dialog Box with a Checkbox
16.7.4 Case Study: A Modal Dialog Box for a Correlation Analysis
16.8 References
IV. Appendixes
A. Description of Data Sets
A.1 Installing the Data
A.2 Vehicles Data
A.3 Movies Data
A.4 Birthdays2002 Data
B. SAS/IML Operators, Functions, and Statements
B.1 Overview of the SAS/IML Language
B.2 A Summary of Frequently Used SAS/IML Operators
B.3 A Summary of Functions and Subroutines
B.3.1 Mathematical Functions
B.3.2 Probability Functions
B.3.3 Descriptive Statistical Functions
B.3.4 Matrix Query Functions
B.3.5 Matrix Reshaping Functions
B.3.6 Linear Algebra Functions
B.3.7 Set Functions
B.3.8 Formatting Functions
B.3.9 Module Statements
B.3.10 Control Statements
B.3.11 Statements for Reading and Writing SAS Data Sets
B.3.12 Options for Printing Matrices
C. IMLPlus Classes, Methods, and Statements
C.1 Overview of IMLPlus Classes, Methods, and Statements
C.2 The DataObject Class
C.3 The DataView Class
C.4 The Plot Class
C.5 Methods for Creating and Modifying Plots
C.5.1 Bar Chart Methods
C.5.2 Box Plot Methods
C.5.3 Histogram Methods
C.5.4 Line Plot Methods
C.5.5 Scatter Plot Methods
C.6 Calling SAS Procedures
C.7 Calling R Functions
D. Modules for Compatability with SAS/IML 9.22
D.1 Overview of SAS/IML 9.22 Modules
D.2 The Mean Module
D.3 The Var Module
D.4 The Qntl Module
E. ODS Statements
E.1 Overview of ODS Statements
E.2 Finding the Names of ODS Tables
E.3 Selecting and Excluding ODS Tables
E.4 Creating Data Sets from ODS Tables
E.5 Creating ODS Statistical Graphics
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
10. Marker Shapes, Colors, and Other Attributes of Data
Next
Next Chapter
11. Calling Functions in the R Language
Part III. Applications
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset