Table of Contents
Acknowledgements
Preface
About the Author
About This Book
PART I - MACRO BASICS
Chapter 1 -- Introduction
- 1.1 Macro Facility Overview
- 1.2 Terminology
- 1.3 Macro Execution Phases
- 1.4 Referencing Environments
- 1.5 Chapter Summary
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
- 2.5 Resolving Macro Variables
- 2.5.1 Using the macro variable as a suffix
- 2.5.2 Using the macro variable as a prefix
- 2.5.3 Appending two macro variables to each other
- 2.6 Automatic Macro Variables
- 2.6.1 &sysdate, &sysday, &systime
- 2.6.2 &syslast
- 2.6.3 &syserr
- 2.6.4 &sysparm
- 2.6.5 &sysrc
- 2.6.6 &syssite, &sysscp, and &sysscpl
- 2.7 Using Macro Variables in a PROC SQL Step
- 2.7.1 Counting observations in a data set
- 2.7.2 Building a list of values
- 2.8 Chapter Summary
- 2.9 Chapter Exercises
Chapter 3 -- Defining and Using Macros
- 3.1 Defining a Macro
- 3.1.1 Creating a macro
- 3.1.2 Using a macro to comment a block of code
- 3.2 Invoking a Macro
- 3.3 System Options Used with the Macro Facility
- 3.3.1 General macro options
- 3.3.2 Debugging options
- 3.3.3 Autocall facility options
- 3.3.4 Compiled stored macros
- 3.4 Display Manager Command-Line Macros
- 3.5 Statement- and Command-Style Macros
- 3.5.1 Turning on system options
- 3.5.2 Defining statement- and command-style macros
- 3.6 Chapter Summary.
- 3.7 Chapter Exercises
Chapter 4 -- Macro Parameters
- 4.1 Introducing Macro Parameters
- 4.2 Positional Parameters
- 4.2.1 Defining positional parameters
- 4.2.2 Passing positional parameters
- 4.3 Keyword Parameters
- 4.3.1 Defining keyword parameters
- 4.3.2 Passing keyword parameters
- 4.4 Using Keyword and Positional Parameters Together
- 4.5 Chapter Summary.
- 4.6 Chapter Exercises
- Introduction
- Overview of SAS Procedures Used in Survey Research
- SAS Functions and Automatic Variables
PART II - USING MACROS
Chapter 5 -- Program Control through Macros
- 5.1 Macros That Invoke Macros
- 5.1.1 Passing parameters between macros
- 5.1.2 Controlling macro calls
- 5.2 Using Conditional Macro Statements
- 5.2.1 Executing macro statements
- 5.2.2 Building SAS code dynamically
- 5.3 Iterative Execution Using Macro Statements
- 5.3.1 %DO block.
- 5.3.2 Iterative %DO loops
- 5.3.3 %DO %UNTIL loops
- 5.3.4 %DO %WHILE loops
- 5.4 Macro Program Statements
- 5.4.1 Macro comments
- 5.4.2 %GLOBAL and %LOCAL
- 5.4.3 %GOTO and %label
- 5.4.4 Using %SYSEXEC
- 5.5 Chapter Summary
- 5.6 Chapter Exercises
Chapter 6 -- Interfacing with the DATA Step
- 6.1 Using the SYMPUT Routine
- 6.1.1 First argument of SYMPUT
- 6.1.2 Second argument of SYMPUT
- 6.1.3 SYMPUT Example
- 6.2 Using a SAS Data Set
- 6.2.1 Macro variable values
- 6.2.2 Assigning macro variable names as well as values
- 6.3 Using a Flat File
- 6.4 && Macro Variables and Dynamic Coding
- 6.4.1 Defining complete steps dynamically
- 6.4.2 Dynamically building SAS statements
- 6.5 Moving Text from Macro to DATA Step Variables
- 6.5.1 Assignment statement
- 6.5.2 Using the SYMGET function
- 6.5.3 Using the RESOLVE function
- 6.6 Chapter Summary.
- 6.7 Chapter Exercises
Chapter 7 -- Using Macro Functions
- 7.1 Quoting Functions
- 7.1.1 Simple quoting function examples
- 7.1.2 %STR
- 7.1.3 %NRSTR
- 7.1.4 %QUOTE
- 7.1.5 %BQUOTE
- 7.1.6 %UNQUOTE
- 7.1.7 %SUPERQ
- 7.1.8 Quoting function summary
- 7.1.9 Marking and quoting mismatched symbols
- 7.2 Character Functions
- 7.2.1 %INDEX
- 7.2.2 %LENGTH
- 7.2.3 %SCAN and %QSCAN
- 7.2.4 %SUBSTR and %QSUBSTR
- 7.2.5 %UPCASE
- 7.3 Evaluation Functions
- 7.3.1 Explicit use of %EVAL
- 7.3.2 Implicit use of %EVAL
- 7.3.3 Using %SYSEVALF.
- 7.4 Using DATA Step Functions and Routines
- 7.4.1 Using %SYSCALL
- 7.4.2 Using %SYSFUNC and %QSYSFUNC
- 7.5 Chapter Summary
- 7.6 Chapter Exercises
Chapter 8 -- Using Macro References with Screen Control Language (SCL)
- 8.1 The Problem Is .....
- 8.2 Using Macro Variables
- 8.2.1 Defining macro variables
- 8.2.2 Macro variables in SUBMIT blocks
- 8.2.3 Using automatic macro variables
- 8.2.4 Passing macro values between SCL entries
- 8.3 Calling Macros from within SCL Programs.
- 8.3.1 Run-time macros
- 8.3.2 Compile-time macros
- 8.4 Chapter Summary
PART III -- ADVANCED MACRO TOPICS, UTILITIES, and EXAMPLES
Chapter 9 -- Writing Dynamic Code
- 9.1 Logical Branches
- 9.2 Iterative Step Execution
- 9.3 Building Statements
Chapter 10 -- Controlling Your Environment
- 10.1 Operating System Operations
- 10.1.1 Copy members of a catalog
- 10.1.2 Write the first N lines of a series of flat files
- 10.1.3 Storing system clock values in macro variables
- 10.1.4 Checking for write access
- 10.1.5 Appending unknown data sets
- 10.2 Working with Listings and Reports
- 10.2.1 Combining titles
- 10.2.2 Renumbering listing pages
Chapter 11 -- Working with SAS Data Sets
- 11.1 Creating Flat Files
- 11.1.1 Column specified flat file
- 11.1.2 Creating comma-delimited files
- 11.2 Subsetting a SAS Data Set
- 11.2.1 Selection of top percentage using SQL
- 11.2.2 Selection of top percentage using the POINT option
- 11.2.3 Random selection of observations
- 11.3 Checking the Existence of SAS Data Sets
- 11.4 Working with Lists of Data Set Variables
- 11.4.1 Create a list of variable names from the PDV
- 11.4.2 Create a list of variable names from an ID variable
- 11.4.3 Create individual macro variables from an existing list
- 11.5 Counting Observations in a Data Set
- 11.5.1 Using %SYSFUNC and ATTRN
- 11.5.2 Controlling observations in PRINT listings
Chapter 12 -- SAS System Autocall Macros
- 12.1 Selected Macros - What They Are
- 12.2 Selected Macros - How They Work
- 12.2.1 %VERIFY
- 12.2.2 %LEFT
- 12.2.3 %CMPRES
- 12.2.4 %LOWCASE
Chapter 13 -- Miscellaneous Macro Topics
- 13.1 &&&var - Using Triple Ampersand Macro Variables
- 13.1.1 Counting observations
- 13.1.2 Working with a list of class variables
- 13.1.3 Totals based on a list of macro variables
- 13.1.4 Selecting elements from macro arrays
- 13.1.5 Checking if a macro variable exists
- 13.2 Doubly Subscripted Macro Arrays
- 13.3 Programming Smarter Ð Efficiency Issues
Appendix 1 - Exercise Solutions
Appendix 2 - Utilities Locator
Appendix 3 - Example Locator
Appendix 4 - Example Data Sets
References
Glossary
Index