Description
Statistical Programming in SAS Second Edition provides a foundation for programming to implement statistical solutions using SAS, a system that has been used to solve data analytic problems for more than 40 years. The author includes motivating examples to inspire readers to generate programming solutions. Upper-level undergraduates, beginning graduate students, and professionals involved in generating programming solutions for data-analytic problems will benefit from this book. The ideal background for a reader is some background in regression modeling and introductory experience with computer programming.
Key Features
- Getting data into the SAS system, engineering new features, and formatting variables
- Writing readable and well-documented code
- Structuring, implementing, and debugging programs that are well documented
- Creating solutions to novel problems
- Combining data sources, extracting parts of data sets, and reshaping data sets as needed for other analyses
- Generating general solutions using macros
- Customizing output
- Producing insight-inspiring data visualizations
- Parsing, processing, and analyzing text
- Programming solutions using matrices and connecting to R
- Processing text
- Programming with matrices
- Connecting SAS with R
- Covering topics that are part of both base and certification exams.
Table of Contents
- Preface …………………………………………………………………………………………………………………………….ix
- Acknowledgments ………………………………………………………………………………………………………. xiii
- Author ……………………………………………………………………………………………………………………………xv
- 1. Structuring, Implementing, and Debugging Programs to Learn about Data ………..1
- Statistical Programming ……………………………………………………………………………………1
- Learning from Constructed, Artificial Data ………………………………………………………2
- Processing a Particular Data Set—Extracting Variable Names from a
- Column of an Input Data Set……………………………………………………………………………..2
- Learning More about Unfamiliar Statistical Methods—Linear Mixed
- Effects Models …………………………………………………………………………………………………..5
- Improving Your Intuition about Statistical Theory— Sampling Distribution
- of Means ……………………………………………………………………………………………………………8
- Good Programming Practice ………………………………………………………………………….. 11
- Document Your Programs! ……………………………………………………………………………… 11
- Use Meaningful Variable Names …………………………………………………………………….. 13
- Use a Variety of CaSeS in Program Statements ……………………………………………….. 14
- Indent Program Statements That Naturally Go Together ………………………………… 14
- SAS Program Structure …………………………………………………………………………………… 15
- What Is a SAS Data Set? ………………………………………………………………………………….. 21
- Internally Documenting SAS Programs …………………………………………………………..22
- Basic Debugging ……………………………………………………………………………………………..23
- Getting Help ……………………………………………………………………………………………………27
- Using Help in SAS …………………………………………………………………………………………..27
- Getting Help from a Web Browser Search ………………………………………………………..29
- Exercises ………………………………………………………………………………………………………….29
- 2. Reading, Creating, and Formatting Data Sets ………………………………………………………. 31
- What Does a SAS DATA Step Do? …………………………………………………………………… 31
- Reading Data from External Files ……………………………………………………………………33
- Reading Data Directly as Part of a Program—Anyone for Datalines? ……………..34
- Reading Data Sets Saved as Text—INFILE Can Be Your Friend (PROC
- IMPORT Too!) ………………………………………………………………………………………………….38
- Sometimes, Variables Are in Particular Columns or in Particular Formats ………40
- Reading CSV, Excel, and TEXT Files ……………………………………………………………….. 41
- Temporary versus Permanent Status of Data Sets ……………………………………………43
- Formatting and Labeling Variables ………………………………………………………………….46
- Using Formats to Read and Display Variable Values ……………………………………….46
- Internal Representations and Output Displays ………………………………………………..49
- Character, Numeric, Time, and Date Formats ………………………………………………….53
- User-Defined Formatting …………………………………………………………………………………58
- Saving Formats for Later Use …………………………………………………………………………..63
- Recoding and Transforming Variables in a DATA Step ………………………………….66
- Indicator Variables …………………………………………………………………………………………68
- Writing Out a File or Making a Simple Report ………………………………………………73
- Simple Report Generation ……………………………………………………………………………..73
- Exporting a File ……………………………………………………………………………………………..77
- Exercises ………………………………………………………………………………………………………..80
- 3. Programming a DATA Step ……………………………………………………………………………………83
- Writing Programs by Subdividing Tasks ……………………………………………………….83
- Estimate the Probability That a Randomly Selected 30- to 39-Year-Old
- Male Is Taller than a Randomly Selected Female of the Same Age …………………83
- Conditional Execution ……………………………………………………………………………….84
- Looping to Repeat a Task …………………………………………………………………………..86
- Returning to the Height Probability Simulation ……………………………………….. 87
- Ordering How Tasks Are Done ……………………………………………………………………..90
- Missing Data in Functions ……………………………………………………………………………..92
- Indexable Lists of Variables (Also Known as Arrays) …………………………………….93
- Defining Values in the Variable List ……………………………………………………………….93
- Inputting Values in the Variable List ………………………………………………………………94
- Reassign Missing Value Codes for Numeric Variables “.” ……………………………..95
- Recoding Missing Values for All Numeric and Character Variables ………………95
- Functions Associated with Statistical Distributions ………………………………………96
- Generating Variables Using Random Number Generators ………………………….. 102
- Remembering Variable Values across Observations ……………………………………. 105
- Processing Multiple Observations for a Single Observation ………………………… 106
- Case Study 1: Is the Two-Sample t-Test Robust to Violations of the
- Heterogeneous Variance Assumption? ……………………………………………………….. 109
- Case Study 1 (Revisited with DATA Step Programming) ……………………………. 118
- Efficiency Considerations—How Long Does It Take? …………………………………..122
- Case Study 2: Monte Carlo Integration to Estimate an Integral …………………… 123
- Case Study 3: Simple Percentile-Based Bootstrap ………………………………………… 128
- Case Study 4: Randomization Test for the Equality of Two Populations ……… 130
- Exercises ……………………………………………………………………………………………………… 134
- 4. Combining, Extracting, and Reshaping Data ……………………………………………………… 137
- Adding Observations by SET-ing Data Sets…………………………………………………. 137
- Adding Variables by MERGE-ing Data Sets ………………………………………………… 140
- Working with Tables in PROC SQL …………………………………………………………….. 148
- Converting Wide to Long Formats ………………………………………………………………. 161
- Converting Long to Wide Formats ………………………………………………………………. 164
- Case Study: Reshaping a World Bank Data Set ……………………………………………. 166
- Building Training and Validation Data Sets ………………………………………………… 175
- Exercises ……………………………………………………………………………………………………… 179
- Self-study Lab ……………………………………………………………………………………………… 180
- 5. Macro Programming ……………………………………………………………………………………………. 191
- What Is a Macro and Why Would You Use It? …………………………………………….. 191
- Motivation for Macros: Numerical Integration to Determine
- P(0 < Z < 1.645) …………………………………………………………………………………………… 191
- Processing Macros ………………………………………………………………………………………. 195
- Macro Variables, Parameters, and Functions……………………………………………….. 195
- Conditional Execution, Looping, and Macros ……………………………………………… 198
- More Complicated Macro Variable Construction …………………………………………203
- Changing Locations in a Macro during Execution ……………………………………….204
- Debugging Macro Code and Programs………………………………………………………..206
- Write Out Values of Macro Variables ……………………………………………………………206
- Useful SAS Options for Debugging Macros ………………………………………………… 207
- Saving Macros …………………………………………………………………………………………….. 211
- Functions and Routines for Macros …………………………………………………………….. 211
- Case Study: Macro for Constructing Training and Test Data Set for Model
- Comparison ………………………………………………………………………………………………… 216
- Case Study: Processing Multiple Data Sets …………………………………………………..223
- Exercises ………………………………………………………………………………………………………227
- 6. Customizing Output and Generating Data Visualizations …………………………………229
- Using the Output Delivery System ………………………………………………………………229
- Basic Ideas ……………………………………………………………………………………………………229
- Destinations—RTF, HTML, PDF, and More! …………………………………………………230
- What’s Produced and How to Select It …………………………………………………………235
- Another Destination That Stat Programmers Should Visit—OUTPUT ………… 243
- Graphics in SAS …………………………………………………………………………………………… 249
- ODS Statistical Graphics ………………………………………………………………………………250
- Modifying Graphics Using the ODS Graphics Editor ………………………………….. 257
- Graphing with Styles and Templates ……………………………………………………………260
- Statistical Graphics—Entering the Land of SG Procedures …………………………. 266
- SGPLOT ………………………………………………………………………………………………………. 266
- SGPANEL ……………………………………………………………………………………………………. 269
- SGSCATTER ……………………………………………………………………………………………….. 271
- Case Study: Using the SG Procedures …………………………………………………………. 273
- Enhancing SG Displays—Options with SG Procedure Statements ……………… 279
- Using Annotate Data Sets to Enhance SG Displays ……………………………………..284
- Using Attribute Maps to Enhance SG Displays …………………………………………… 287
- Exercises ………………………………………………………………………………………………………290
- 7. Processing Text …………………………………………………………………………………………………….. 293
- Cleaning and Processing Text Data …………………………………………………………….. 293
- Starting with Character Functions ………………………………………………………………. 293
- Processing Text ……………………………………………………………………………………………. 298
- Case Study: Sentiment in State of the Union Addresses ……………………………….302
- Case Study: Reading Text from a Web Page …………………………………………………309
- Regular Expressions ……………………………………………………………………………………. 315
- Case Study (Revisited)—Applying Regular Expressions …………………………….. 319
- Exercises ……………………………………………………………………………………………………… 321
- 8. Programming with Matrices and Vectors …………………………………………………………… 323
- Defining a Matrix and Subscripting ……………………………………………………………. 323
- Using Diagonal Matrices and Stacking Matrices …………………………………………. 329
- Using Elementwise Operations, Repeating, and Multiplying Matrices ……….. 332
- Importing a Data Set into SAS/IML and Exporting Matrices from
- SAS/IML to a Data Set …………………………………………………………………………………333
- Creating Matrices from SAS Data Sets and Vice Versa ………………………………….333
- Case Study 1: Monte Carlo Integration to Estimate π ……………………………………336
- Case Study 2: Bisection Root Finder ……………………………………………………………. 337
- Case Study 3: Randomization Test Using Matrices Imported from PROC
- PLAN …………………………………………………………………………………………………………..340
- Case Study 4: SAS/IML Module to Implement Monte Carlo Integration
- to Estimate π ………………………………………………………………………………………………..342
- Storing and Loading SAS/IML Modules ……………………………………………………..344
- SAS/IML and R ……………………………………………………………………………………………345
- Exercises ………………………………………………………………………………………………………350
- References …………………………………………………………………………………………………………………..355
- Index …………………………………………………………………………………………………………………………… 357
Reviews
“This book is useful for people who want to learn SAS programing, and assumes the students have knowledge of multiple linear regression and one-way ANOVA models.…The second edition has added a chapter on text processing, and reorganized the chapter order…Some topics that are relevant for the SAS Base and Certifications exams are covered, and a nice feature is the highlighting of programing tips in gray.”
~Technometrics
“This is a very complete book for programming SAS in statistical analyses. This second edition offers the possibility to debug some programs and provides new examples and applications, which are very useful. This book is a very useful companion tool for students or beginners in SAS, or for more experienced statisticians who already use SAS for statistical analyses.”
~ISCB News
Author Biography
A. John Bailer, PhD, PStat®, is a University Distinguished Professor and a founding chair of the Department of Statistics and an affiliate member of the Departments of Biology and Sociology and Gerontology as well as the Institute for the Environment and Sustainability at the Miami University in Oxford, Ohio. He is President of the International Statistical Institute (2019–2021). He previously served on the Board of Directors of the American Statistical Association. He is a Fellow of the American Statistical Association, the Society for Risk Analysis, and the American Association for the Advancement of Science. His research has focused on the quantitative risk estimation but has collaborations addressing problems in toxicology, environmental health, and occupational safety. He received the E. Phillips Knox Distinguished Teaching Award in 2018 after previously receiving the Distinguished Teaching Award for Excellence in Graduate Instruction and Mentoring and the College of Arts and Science Distinguished Teaching Award
Additional information
| Weight | 0.680 kg |
|---|
Only logged in customers who have purchased this product may leave a review.
Related Products









Reviews
There are no reviews yet.