You are previewing SAS Macro Programming Made Easy, Third Edition, 3rd Edition.
O'Reilly logo
SAS Macro Programming Made Easy, Third Edition, 3rd Edition

Book Description

This book provides beginners with a thorough foundation in SAS macro programming. The macro facility is a popular part of SAS. Macro programming is a required skill for many SAS programming jobs, and the SAS Advanced Programming Certification Exam tests macro processing concepts. Whether you're looking to become certified, land a job, or increase your skills, you'll benefit from SAS Macro Programming Made Easy, Third Edition. By following Michele Burlew's examples and step-by-step instructions, you'll be able to rapidly perform repetitive programming tasks, to pass information between programming steps more easily, and to make your programming easier to read. Updated for SAS 9.4, this book teaches you the elements of the macro facility (macro variables, macro programs, macro language), how to write a macro program, techniques for macro programming, tips on using the macro facility, how the macro facility fits into SAS, and about the interfaces between the macro facility and other components of SAS. Beginning macro programmers will learn to write SAS macro programs quickly and efficiently. More experienced programmers will find this book useful to refresh their conceptual knowledge and expand on their macro programming skills. Ultimately, any user interested in automating their programs—including analysts, programmers, and report writers—will find Michele Burlew's book an excellent tutorial. This book is part of the SAS Press program.

Table of Contents

  1. About This Book
  2. About The Author
  3. Acknowledgments
    1. Chapter 1 Introduction
      1. What Is the SAS Macro Facility?
      2. What Are the Advantages of the SAS Macro Facility?
      3. Where Can the SAS Macro Facility Be Used?
      4. Examples of the SAS Macro Facility
    2. Chapter 2 Mechanics of Macro Processing
      1. Introduction
      2. The Vocabulary of SAS Processing
      3. SAS Processing without Macro Activity
      4. Understanding Tokens
      5. Tokenizing a SAS Program
      6. Comparing Macro Language Processing and SAS Language Processing
      7. Processing a SAS Program That Contains Macro Language
    3. Chapter 3 Macro Variables
      1. Introduction
      2. Basic Concepts of Macro Variables
      3. Referencing Macro Variables
      4. Understanding Macro Variable Resolution and the Use of Single and Double Quotation Marks
      5. Displaying Macro Variable Values
        1. Using the %PUT Statement
        2. Displaying Macro Variable Values As They Resolve by Enabling the SYMBOLGEN System Option
      6. Understanding Automatic Macro Variables
      7. Understanding User-Defined Macro Variables
        1. Creating Macro Variables with the %LET Statement
      8. Combining Macro Variables with Text
        1. Placing Text before a Macro Variable Reference
        2. Placing Text after a Macro Variable Reference
        3. Concatenating Permanent SAS Data Set Names and Catalog Names with Macro Variables
      9. Referencing Macro Variables Indirectly
    4. Chapter 4 Macro Programs
      1. Introduction
      2. Creating Macro Programs
      3. Executing a Macro Program
      4. Displaying Notes about Macro Program Compilation in the SAS Log
      5. Displaying Messages about Macro Program Processing in the SAS Log
        1. Using MPRINT to Display the SAS Statements Submitted by a Macro Program
        2. Using the MLOGIC Option to Trace Execution of a Macro Program
      6. Passing Values to a Macro Program through Macro Parameters
        1. Specifying Positional Parameters in Macro Programs
        2. Specifying Keyword Parameters in Macro Programs
        3. Specifying Mixed Parameter Lists in Macro Programs
        4. Defining a Macro Program That Can Accept a Varying Number of Parameter Values
    5. Chapter 5 Understanding Macro Symbol Tables and the Processing of Macro Programs
      1. Understanding Macro Symbol Tables
        1. Understanding the Global Macro Symbol Table
        2. Understanding Local Macro Symbol Tables
        3. Working with Global Macro Variables and Local Macro Variables
        4. Defining the Domain of a Macro Variable by Using the %GLOBAL or %LOCAL Macro Language Statements
      2. Processing of Macro Programs
        1. How a Macro Program Is Compiled
        2. How a Macro Program Executes
    6. Chapter 6 Macro Language Functions
      1. Introduction
      2. Macro Character Functions
      3. Macro Evaluation Functions
      4. Macro Quoting Functions
      5. Macro Variable Attribute Functions
      6. Other Macro Functions
      7. SAS Supplied Autocall Macro Programs Used Like Functions
    7. Chapter 7 Macro Expressions and Macro Programming Statements
      1. Introduction
      2. Macro Language Statements
      3. Constructing Macro Expressions
        1. Understanding Arithmetic Expressions
        2. Understanding Logical Expressions
        3. Understanding the IN Operator As Used in Macro Language Statements
      4. Conditional Processing with the Macro Language
      5. Iterative Processing with the Macro Language
        1. Writing Iterative %DO Loops in the Macro Language
        2. Conditional Iteration with %DO %UNTIL
        3. Conditional Iteration with %DO %WHILE
      6. Branching in Macro Processing
    8. Chapter 8 Masking Special Characters and Mnemonic Operators
      1. Introduction
      2. Why Are Quoting Functions Called Quoting Functions?
      3. Illustrating the Need for Macro Quoting Functions
      4. Describing the Commonly Used Macro Quoting Functions
      5. Understanding How Macro Quoting Functions Work
      6. Applying Macro Quoting Functions
      7. Specifying Macro Program Parameters That Contain Special Characters or Mnemonic Operators
      8. Unmasking Text and the %UNQUOTE Function
      9. Using Quoting Versions of Macro Character Functions and Autocall Macro Programs
    9. Chapter 9 Interfaces to the Macro Facility
      1. Introduction
      2. Understanding DATA Step Interfaces to the Macro Facility
        1. Understanding the SYMGET Function
        2. Understanding the SYMPUT and SYMPUTX Call Routines
        3. Understanding the CALL EXECUTE Routine
        4. Understanding the RESOLVE Function
      3. Using Macro Facility Features in PROC SQL
        1. Creating and Updating Macro Variables with PROC SQL
        2. Using the Macro Variables Created by PROC SQL
        3. Displaying Macro Option Settings with PROC SQL and Dictionary Tables
    1. Chapter 10 Storing and Reusing Macro Programs
      1. Introduction
      2. Saving Macro Programs with the Autocall Facility
        1. Creating an Autocall Library
        2. Making Autocall Libraries Available to Your Programs
        3. Maintaining Access to the Autocall Macro Programs That Ship with SAS
        4. Using the Autocall Facility under UNIX and z/OS Systems
      3. Saving Macro Programs with the Stored Compiled Macro Facility
        1. Setting SAS Options to Create Stored Compiled Macro Programs
        2. Creating Stored Compiled Macro Programs
        3. Saving and Retrieving the Source Code of a Stored Compiled Macro Program
        4. Encrypting a Stored Compiled Macro Program
      4. Resolving Macro Program References When Using the Autocall Facility and the Stored Compiled Macro Facility
    2. Chapter 11 Building a Library of Utilities
      1. Introduction
      2. Writing a Macro Program to Behave Like a Function
      3. Programming Routine Tasks
    3. Chapter 12 Debugging Macro Programming and Adding Error Checking to Macro Programs
      1. Introduction
      2. Understanding the Types of Errors That Can Occur in Macro Programming
      3. Minimizing Errors in Developing SAS Programs That Contain Macro Language
      4. Categorizing and Checking for Common Problems in Macro Programming
      5. Understanding the Tools That Can Debug Macro Programming
        1. Using SAS System Options to Debug Macro Programming
        2. Using Macro Language Statements to Debug Macro Programming
        3. Using Macro Functions to Debug Macro Programming
        4. Using Automatic Macro Variables to Debug Macro Programming
      6. Examples of Solving Errors in Macro Programming
      7. Improving Your Macro Programming by Including Error Checking
    4. Chapter 13 A Stepwise Method for Writing Macro Programs
      1. Introduction
      2. Building a Macro Program in Four Steps
      3. Applying the Four Steps to an Example
        1. Step 1: Write, test, and debug the SAS program(s) that you want the macro program to build
        2. Step 2: Remove hard-coded programming constants from the program(s) in Step 1 and replace these constants with macro variables
        3. Step 3: Create macro program(s) from the program(s) in Step 2
        4. Step 4: Refine and generalize the macro program(s) in Step 3 by adding macro language statements like %IF-%THEN and %DO groups
        5. Executing the REPORT Macro Program
        6. Enhancing the Macro Program REPORT
    1. Appendix A Sample Data Set
    2. Appendix B Reference to Examples in This Book
  4. Index