Book description
For SAS programmers or analysts who need to generalize their programs or improve programming efficiency, Art Carpenter thoroughly updates his highly successful second edition of Carpenter's Complete Guide to the SAS Macro Language with an extensive collection of new macro language techniques and examples.Addressing the composition and operation of the SAS macro facility and the SAS macro language, this third edition offers nearly 400 ready-to-use macros, macro functions, and macro tools that enable you to convert SAS code to macros, define macro variables, and more! Users with a basic understanding of Base SAS who are new to the SAS macro language will find more detail, utilities, and references to additional learning opportunities; advanced macro language programmers who need help with data-driven macros and dynamic application development will find greatly expanded treatment of these topics.
This revised and enlarged edition includes the following topics:
- New and expanded introduction to the macro language
- Functions, automatic macro variables, and macro statements new to the macro language
- Expanded macro language tools that interface with the operating system
- Expanded data-driven methodologies used to build dynamic applications
- Expanded discussion of list processing, with four alternative approaches presented
- Additional file and data management examples
- Expanded discussion of CALL EXECUTE and DOSUBL
- New discussion of using the macro language on remote servers
- Expanded discussion and examples of macro quoting
Far beyond a reference manual issued from an “ivory tower,” this book is pragmatic and example-driven: Yes, you will find syntax examples; yes, the code is explained. But the focus of this book is on actual code used to solve real-world business problems. In fact, an entire appendix is dedicated to listing the nearly 70 classes of problems that are solved by programs covered in this edition. Discussion of the examples elucidates the pros and cons of the particular solution and often suggests alternative approaches. Therefore, this book provides you both a compendium of reusable and adaptable code, and opportunities for deepening your understanding and growing as a SAS programmer.
Table of contents
- Acknowledgments
- About This Book
- About The Author
- Part 1: Macro Basics
- Chapter 1: What the Language Is, What It Does, and What It Can Do
- 1.1 Introduction
- 1.2 Stages of Macro Language Learning
- 1.3 Terminology
- 1.4 Sequencing Events—It’s All about the Timing
- 1.5 Scopes or Referencing Environments
- Chapter 2: Defining and Using Macro Variables
- 2.1 Naming Macro Variables
- 2.2 Defining Macro Variables
- 2.3 Using Macro Variables
- 2.4 Displaying Macro Variables by Using the %PUT Statement
- 2.5 Resolving Macro Variables
- 2.6 Using Automatic Macro Variables
- 2.7 Removing Macro Variables
- 2.8 Testing Your Knowledge with Chapter Exercises
- Chapter 3: Defining and Using Macros
- 3.1 Creating a Macro
- 3.2 Invoking a Macro
- 3.3 Using System Options with the Macro Facility
- 3.4 Testing Your Knowledge with Chapter Exercises
- Chapter 4: Using Macro Parameters
- 4.1 Introducing Macro Parameters
- 4.2 Using Positional Parameters
- 4.3 Using Keyword Parameters
- 4.4 Choosing between Keyword and Positional Parameters
- 4.5 Testing Your Knowledge with Chapter Exercises
- Part 2: Using Macros
- Chapter 5: Controlling Programs with Macros
- 5.1 Macros That Invoke Macros
- 5.2 Conditional Execution Using %IF-%THEN/%ELSE Statements
- 5.3 Iterative Execution of Macro Statements
- 5.4 Additional Macro Program Statements
- 5.5 Testing Your Knowledge with Chapter Exercises
- Chapter 6: Interfacing with Data Set Values
- 6.1 Using the SYMPUTX Routine to Create Macro Variables
- 6.2 Defining Macro Variables in a PROC SQL Step
- 6.3 Moving Text from Macro Variables into Code
- 6.4 Using Data to Control Program Flow
- 6.5 Executing Macro Code Using CALL EXECUTE
- 6.6 Testing Your Knowledge with Chapter Exercises
- Chapter 7: Using Macro Functions
-
7.1 Quoting Functions
- 7.1.1 Using the %BQUOTE Function
- 7.1.2 %STR
- 7.1.3 Considerations When Quoting
- 7.1.4 Basic Types of Quoting Functions and Why We Care
- 7.1.5 A Bit about the %QUOTE and %NRQUOTE Functions
- 7.1.6 Removing Masking Characters
- 7.1.7 The %SUPERQ Quoting Function
- 7.1.8 Quoting Function Summary
- 7.1.9 Quoting Mismatched Symbols with the %STR and %QUOTE Functions
- 7.2 Text Functions
- 7.3 Evaluation Functions
- 7.4 Using DATA Step Functions and Routines
- 7.5 Building Your Own Macro Functions
- 7.6 Other Useful User-Written Macro Functions
- 7.7 Testing Your Knowledge with Chapter Exercises
- Chapter 8: Discovering Even More Macro Language Elements
- 8.1 Even More Macro Functions
- 8.2 Even More Macro Statements
- 8.3 Even More Automatic Macro Variables
- 8.4 Even More System Options
- 8.5 Even More DATA Step Functions and Statements
- Chapter 9: Exploring Some Less Common Intermediate Topics
- 9.1 Building Macro Calls
- 9.2 Working with Macro Variables
- 9.3 Using the Macro Language to Form Simple Hash Tables
- 9.4 Using the Macro Language for Formatted Table LookUps
- 9.5 Making Comparisons to Null Values—Some Considerations
- 9.6 Evaluating Expressions Stored in a Data Set
- 9.7 Using Macro Language Elements on Remote Servers
- 9.8 Working with Macro Variables That Contain Special Characters
- Chapter 10: Building and Using Macro Libraries
- 10.1 Establishing Macro Libraries
- 10.2 Using %INCLUDE as a Macro Library
-
10.3 Using Stored Compiled Macro Libraries
- 10.3.1 Stored Compiled Macro Library Overview
- 10.3.2 Defining and Using a Stored Compiled Macro Library
- 10.3.3 Storing and Retrieving the Source Code for Compiled Macros
- 10.3.4 Recovering Compiled Macro Source Code
- 10.3.5 Using the %SYSMACDELETE Statement
- 10.3.6 Changing the SASMSTORE= libref Location
- 10.4 Using the Autocall Facility
- 10.5 Macro Library Essentials
- 10.6 Autocall Macros Supplied by SAS
- Part 3: Dynamic Macro Coding Techniques
- Chapter 11: Writing Dynamic Programs
-
11.1 Dynamic Programming Introduction and Design Elements
- 11.1.1 A Short Macro Language Review from the Perspective of a Dynamic Programmer
- 11.1.2 Elements of a Dynamic Program
- 11.1.3 Creating Data Independence
- 11.1.4 Elements for Making a Program Dynamic
- 11.1.5 Controlling the Program with Data
- 11.1.6 List Processing Basics
- 11.1.7 Iterative Step Execution
- 11.1.8 Building Statements
-
11.2 Information Sources
- 11.2.1 Using SASHELP Views
- 11.2.2 Using SQL DICTIONARY Tables
- 11.2.3 Automatic Macro Variables
- 11.2.4 %SYSFUNC and DATA Step Functions
- 11.2.5 Retrieving Operating System Information
- 11.2.6 Using Data Set Metadata
- 11.2.7 Using Data Tables to Control a Process
- 11.2.8 Creating and Using Control Files
- 11.2.9 Using SET Statement Options
- 11.3 Using &&VAR&I Constructs as Vertical Macro Arrays
- 11.4 Horizontal Lists
- 11.5 Using CALL EXECUTE
- 11.6 Writing %INCLUDE Programs
- 11.7 Writing Applications without Hardcoded Data Dependencies
- 11.8 Building SAS Statements Dynamically
- 11.9 More Than Just the Macro Coding
- Chapter 12: Examples of Dynamic Programs
- 12.1 File Management
- 12.2 Controlling Output
- 12.3 Adapting Your SAS Environment
-
12.4 Working with Data Sets and Variables
- 12.4.1 Splitting a Data Set Vertically
- 12.4.2 Creating a List of Variable Names from Procedure Output
- 12.4.3 Parsing Individual Values from an Existing Horizontal List
- 12.4.4 Placing Commas between Words
- 12.4.5 Quoting Words in a List
- 12.4.6 Checking for Existence of Variables
- 12.4.7 Removing Repeated Words from a List
- 12.4.8 Controlled Data Corrections and Manipulations
- Part 4: Miscellaneous Topics and Examples
- Chapter 13: Examples and Utilities to Perform Various Tasks
- 13.1 Working with Operating System Operations
- 13.2 Working with the Output Delivery System
- 13.3 Working with Data
- Chapter 14: Miscellaneous Topics
- 14.1 More on Triple Ampersand Macro Variables
- 14.2 Doubly Subscripted Macro Arrays
- 14.3 Programming Smarter
- 14.4 Understanding Recursion in the Macro Language
- 14.5 Determining Macro Variable Scopes
- 14.6 Controlling System Initialization and Termination
- 14.7 Protecting Macros and Controlling Their Execution
- Appendix 1: Exercise Solutions
- Chapter 2
- Chapter 3
- Chapter 4
- Chapter 5
- Chapter 6
- Chapter 7
- Section 14.3.6 Quizlette
- Appendix 2: Using the Macro Language with Compiled Programs
- A2.1 The Problem: Macro Variable Resolution during Compilation
- A2.2 Using Macro Variables
- A2.3 Calling Macros from within Compiled Programs
- A2.4 Using the Macro Language with FCMP Functions
- Appendix 3: Utilities and Examples Locator
- Data Set / File Manipulation
- Data Variable Manipulation
- Data Value Manipulation
- Date / Time
- Library / Directory Tools
- Macro Techniques
- Macro Variable Tools
- SAS Execution
- SAS/GRAPH Tools
- System and Environment
- Text Manipulation
- Appendix 4: Code Sample Locator
- A4.1 Macro Variable Constructs
- A4.2 Macro Language Statements, Functions, and Autocall Macros
- A4.3 %MACRO Statement Options
- A4.4 Automatic Macro Variables
- A4.5 DATA Step and Other Non-Macro-Language Elements
- A4.6 SASHELP Views and DICTIONARY Tables
- Appendix 5: Glossary
- Bibliography
- Index
Product information
- Title: Carpenter's Complete Guide to the SAS Macro Language, Third Edition, 3rd Edition
- Author(s):
- Release date: August 2016
- Publisher(s): SAS Institute
- ISBN: 9781629602370
You might also like
book
The SAS Programmer's PROC REPORT Handbook: Basic to Advanced Reporting Techniques
The SAS Programmer's PROC REPORT Handbook: Basic to Advanced Reporting Techniques is intended for programmers of …
book
The Book of R
The Book of R is a comprehensive, beginner-friendly guide to R, the world's most popular programming …
video
Microsoft Power BI - The Complete Masterclass [2023 EDITION]
Microsoft Power BI is an interactive data visualization software primarily focusing on business intelligence, part of …
book
The SAS Programmer's PROC REPORT Handbook
Generate reports with style! The SAS Programmer's PROC REPORT Handbook: ODS Companion explains how to use …