Book description
Explains how to increase the modularity, flexibility, and maintainability of your SAS code using the SAS macro facility. Provides complete information about macro language elements, interfaces between the SAS macro facility and other parts of SAS software, and macro processing in general.Table of contents
- Contents
- What’s New in the SAS 9.4 Macro Facility
-
Understanding and Using the Macro Facility
- Introduction to the Macro Facility
- SAS Programs and Macro Processing
- Macro Variables
- Macro Processing
-
Scopes of Macro Variables
- Scopes of Macro Variables
- Global Macro Variables
- Local Macro Variables
- Writing the Contents of Symbol Tables to the SAS Log
- How Macro Variables Are Assigned and Resolved
- Examples of Macro Variable Scopes (1/2)
- Examples of Macro Variable Scopes (2/2)
- Special Cases of Scope with the CALL SYMPUT Routine (1/2)
-
Special Cases of Scope with the CALL SYMPUT Routine (2/2)
- Overview of CALL SYMPUT Routine
- Example Using CALL SYMPUT with Complete DATA Step and a Nonempty Local Symbol Table
- Example Using CALL SYMPUT with an Incomplete DATA Step
- Example Using CALL SYMPUT with a Complete DATA Step and an Empty Local Symbol Table
- Example Using CALL SYMPUT with SYSPBUFF and an Empty Local Symbol Table
- Macro Expressions
-
Macro Quoting
- Macro Quoting
- Deciding When to Use a Macro Quoting Function and Which Function to Use
- %STR and %NRSTR Functions
- %BQUOTE and %NRBQUOTE Functions
- Referring to Already Quoted Variables
- Deciding How Much Text to Mask with a Macro Quoting Function
- %SUPERQ Function
- Summary of Macro Quoting Functions and the Characters That They Mask
- Unquoting Text
- How Macro Quoting Works
- Other Functions That Perform Macro Quoting
- Interfaces with the Macro Facility
- Storing and Reusing Macros
-
Macro Facility Error Messages and Debugging
- General Macro Debugging Information
- Troubleshooting Your Macros (1/3)
- Troubleshooting Your Macros (2/3)
-
Troubleshooting Your Macros (3/3)
- Solving Common Macro Problems
- Solving Macro Variable Resolution Problems
- Solving Problems with Macro Variable Scope
- Solving Open Code Statement Recursion Problems
- Solving Problems with Macro Functions
- Solving Unresolved Macro Problems
- Solving the “Black Hole” Macro Problem
- Resolving Timing Issues
- Example of a Macro Statement Executing Immediately
- Resolving Macro Resolution Problems Occurring during DATA Step Compilation
- Solving Problems with the Autocall Facility
- Fixing Autocall Library Specifications
- Fixing Autocall Macro Definition Errors
- File and Macro Names for Autocall
- Displaying Information about Stored Compiled Macros
- Solving Problems with Expression Evaluation
- Debugging Techniques (1/2)
-
Debugging Techniques (2/2)
- Using System Options to Track Problems
- Tracing the Flow of Execution with MLOGIC
- Nesting Information Generated by MLOGICNEST
- Examining the Generated SAS Statements with MPRINT
- Nesting Information Generated by MPRINTNEST
- Storing MPRINT Output in an External File
- Examining Macro Variable Resolution with SYMBOLGEN
- Using the %PUT Statement to Track Problems
-
Writing Efficient and Portable Macros
- Writing Efficient and Portable Macros
- Keeping Efficiency in Perspective
-
Writing Efficient Macros
- Use Macros Wisely
- Use Name Style Macros
- Avoid Nested Macro Definitions
- Assign Function Results to Macro Variables
- Turn Off System Options When Appropriate
- Use the Stored Compiled Macro Facility
- Centrally Store Autocall Macros
- Other Useful Efficiency Tips
- Storing Only One Copy of a Long Macro Variable Value
- Writing Portable Macros (1/2)
-
Writing Portable Macros (2/2)
- Using Portable SAS Language Functions with %SYSFUNC
- Example Using %SYSFUNC
- Using Automatic Variables with Host-Specific Values
- Example Using SYSPARM
- SYSPARM Details
- SYSRC Details
- Macro Language Elements with System Dependencies
- Host-Specific Macro Variables
- Naming Macros and External Files for Use with the Autocall Facility
- Macro Language Elements
-
Macro Language Dictionary
-
AutoCall Macros
- AutoCall Macros
-
Dictionary
- %CMPRES and %QCMPRES Autocall Macros
- %COMPSTOR Autocall Macro
- %DATATYP Autocall Macro
- %KVERIFY Autocall Macro
- %LEFT Autocall Macro
- %LOWCASE and %QLOWCASE Autocall Macros
- %QCMPRES Autocall Macro
- %QLEFT Autocall Macro
- %QLOWCASE Autocall Macro
- %QTRIM Autocall Macro
- %SYSRC Autocall Macro
- %TRIM and %QTRIM Autocall Macro
- %VERIFY Autocall Macro
-
Automatic Macro Variables
- Automatic Macro Variables
-
Dictionary
- SYSADDRBITS Automatic Macro Variable
- SYSBUFFR Automatic Macro Variable
- SYSCC Automatic Macro Variable
- SYSCHARWIDTH Automatic Macro Variable
- SYSCMD Automatic Macro Variable
- SYSDATASTEPPHASE Automatic Macro Variable
- SYSDATE Automatic Macro Variable
- SYSDATE9 Automatic Macro Variable
- SYSDAY Automatic Macro Variable
- SYSDEVIC Automatic Macro Variable
- SYSDMG Automatic Macro Variable
- SYSDSN Automatic Macro Variable
- SYSENCODING Automatic Macro Variable
- SYSENDIAN Automatic Macro Variable
- SYSENV Automatic Macro Variable
- SYSERR Automatic Macro Variable
- SYSERRORTEXT Automatic Macro Variable
- SYSFILRC Automatic Macro Variable
- SYSHOSTINFOLONG Automatic Macro Variable
- SYSHOSTNAME Automatic Macro Variable
- SYSINCLUDEFILEDEVICE Automatic Macro Variable
- SYSINCLUDEFILEDIR Automatic Macro Variable
- SYSINCLUDEFILEFILEREF Automatic Macro Variable
- SYSINCLUDEFILENAME Automatic Macro Variable
- SYSINDEX Automatic Macro Variable
- SYSINFO Automatic Macro Variable
- SYSJOBID Automatic Macro Variable
- SYSLAST Automatic Macro Variable
- SYSLCKRC Automatic Macro Variable
- SYSLIBRC Automatic Macro Variable
- SYSLOGAPPLNAME Automatic Macro Variable
- SYSMACRONAME Automatic Macro Variable
- SYSMAXLONG Automatic Macro Variable
- SYSMENV Automatic Macro Variable
- SYSMSG Automatic Macro Variable
- SYSNCPU Automatic Macro Variable
- SYSNOBS Automatic Macro Variable
- SYSODSESCAPECHAR Automatic Macro Variable
- SYSODSGRAPHICS Automatic Macro Variable
- SYSODSPATH Automatic Macro Variable
- SYSPARM Automatic Macro Variable
- SYSPBUFF Automatic Macro Variable
- SYSPRINTTOLIST Automatic Macro Variable
- SYSPRINTTOLOG Automatic Macro Variable
- SYSPROCESSID Automatic Macro Variable
- SYSPROCESSMODE Automatic Macro Variable
- SYSPROCESSNAME Automatic Macro Variable
- SYSPROCNAME Automatic Macro Variable
- SYSRC Automatic Macro Variable
- SYSSCP and SYSSCPL Automatic Macro Variables
- SYSSCPL Automatic Macro Variable
- SYSSITE Automatic Macro Variable
- SYSSIZEOFLONG Automatic Macro Variable
- SYSSIZEOFPTR Automatic Macro Variable
- SYSSIZEOFUNICODE Automatic Macro Variable
- SYSSTARTID Automatic Macro Variable
- SYSSTARTNAME Automatic Macro Variable
- SYSTCPIPHOSTNAME Automatic Macro Variable
- SYSTIME Automatic Macro Variable
- SYSTIMEZONE Automatic Macro Variable
- SYSTIMEZONEIDENT Automatic Macro Variable
- SYSTIMEZONEOFFSET Automatic Macro Variable
- SYSUSERID Automatic Macro Variable
- SYSVER Automatic Macro Variable
- SYSVLONG Automatic Macro Variable
- SYSVLONG4 Automatic Macro Variable
- SYSWARNINGTEXT Automatic Macro Variable
- DATA Step Call Routines for Macros
- DATA Step Functions for Macros
-
Macro Functions
- Macro Functions
- Dictionary (1/8)
- Dictionary (2/8)
- Dictionary (3/8)
- Dictionary (4/8)
- Dictionary (5/8)
- Dictionary (6/8)
- Dictionary (7/8)
-
Dictionary (8/8)
- %BQUOTE and %NRBQUOTE Functions
- %EVAL Function
- %INDEX Function
- %LENGTH Function
- %NRBQUOTE Function
- %NRQUOTE Function
- %NRSTR Function
- %QSCAN Function
- %QSUBSTR Function
- %QSYSFUNC Function
- %QUOTE and %NRQUOTE Functions
- %QUPCASE Function
- %SCAN and %QSCAN Functions
- %STR and %NRSTR Functions
- %SUBSTR and %QSUBSTR Functions
- %SUPERQ Function
- %SYMEXIST Function
- %SYMGLOBL Function
- %SYMLOCAL Function
- %SYSEVALF Function
- %SYSFUNC and %QSYSFUNC Functions
- %SYSGET Function
- %SYSMACEXEC Function
- %SYSMACEXIST Function
- %SYSMEXECDEPTH Function
- %SYSMEXECNAME Function
- %SYSPROD Function
- %UNQUOTE Function
- %UPCASE and %QUPCASE Functions
- SQL Clauses for Macros
-
Macro Statements
- Macro Statements
- Dictionary (1/11)
- Dictionary (2/11)
- Dictionary (3/11)
- Dictionary (4/11)
- Dictionary (5/11)
- Dictionary (6/11)
- Dictionary (7/11)
- Dictionary (8/11)
- Dictionary (9/11)
- Dictionary (10/11)
-
Dictionary (11/11)
- %ABORT Statement
- %* Macro Comment Statement
- %COPY Statement
- %DISPLAY Statement
- %DO Statement
- %DO, Iterative Statement
- %DO %UNTIL Statement
- %DO %WHILE Statement
- %END Statement
- %GLOBAL Statement
- %GOTO Statement
- %IF-%THEN/%ELSE Statement
- %INPUT Statement
- %label Statement
- %LET Statement
- %LOCAL Statement
- %MACRO Statement
- %MEND Statement
- %PUT Statement
- %RETURN Statement
- %SYMDEL Statement
- %SYSCALL Statement
- %SYSEXEC Statement
- %SYSLPUT Statement
- %SYSMACDELETE Statement
- %SYSMSTORECLEAR Statement
- %SYSRPUT Statement
- %WINDOW Statement
-
System Options for Macros
- System Options for Macros
- Dictionary (1/7)
- Dictionary (2/7)
- Dictionary (3/7)
- Dictionary (4/7)
- Dictionary (5/7)
- Dictionary (6/7)
-
Dictionary (7/7)
- CMDMAC System Option
- IMPLMAC System Option
- MACRO System Option
- MAUTOCOMPLOC System Option
- MAUTOLOCDISPLAY System Option
- MAUTOLOCINDES System Option
- MAUTOSOURCE System Option
- MCOMPILE System Option
- MCOMPILENOTE System Option
- MCOVERAGE System Options
- MCOVERAGELOC= System Option
- MERROR System Option
- MEXECNOTE System Option
- MEXECSIZE System Option
- MFILE System Option
- MINDELIMITER= System Option
- MINOPERATOR System Option
- MLOGIC System Option
- MLOGICNEST System Option
- MPRINT System Option
- MPRINTNEST System Option
- MRECALL System Option
- MREPLACE System Option
- MSTORED System Option
- MSYMTABMAX= System Option
- MVARSIZE= System Option
- SASAUTOS= System Option
- SASMSTORE= System Option
- SERROR System Option
- SYMBOLGEN System Option
- SYSPARM= System Option
-
AutoCall Macros
-
Appendixes
- Reserved Words in the Macro Facility
- SAS Macro Facility Error and Warning Messages
- SAS Tokens
- Syntax for Selected Functions Used with the %SYSFUNC Function
-
SAS Macro Examples
- Example 1: Import All CSV Files That Exist within a Directory
- Example 2: List All Files within a Directory Including Subdirectories
- Example 3: How to Increment a Macro DO Loop by a Non-integer Value
- Example 4: How to Use Character Values on a Macro %DO Loop
- Example 5: Place All SAS Data Set Variables into a Macro Variable
- Example 6: How to Retrieve the Program Name That Is Currently Running in Batch Mode or Interactively
- Example 7: Using a Macro to Create New Variable Names from Variable Values
- Example 8: Dynamically Determine the Number of Observations and Variables in a SAS Data Set
- Example 9: Use Macro Logic to Determine If an External File Is Empty
- Example 10: Retrieve Each Word from a Macro Variable List
- Example 11: Loop through Dates Using a Macro %DO Loop
- Example 12: Using Macro Variables within a CARDS or DATALINES Statement
- Example 13: Print Information to the Output Window If a Data Set Is Empty
- Example 14: Create a Quoted List Separated by Spaces
- Example 15: Delete a File If It Exists
- Example 16: Retrieve the File Size, Create Time, and Last Modified Date of an External File
- Example 17: Delete All User-defined Macro Variables
- Recommended Reading
- Glossary (1/2)
- Glossary (2/2)
- Index (1/4)
- Index (2/4)
- Index (3/4)
- Index (4/4)
Product information
- Title: SAS 9.4 Macro Language, 5th Edition
- Author(s):
- Release date: July 2018
- Publisher(s): SAS Institute
- ISBN: 9781629608082
You might also like
book
SAS 9.4 Macro Language: Reference, Fourth Edition, 4th Edition
Explains how to increase the modularity, flexibility, and maintainability of your SAS code using the SAS …
book
SAS 9.4 Language Reference, 6th Edition
Provides conceptual information for the Base SAS language. Major topics include SAS keywords and naming conventions, …
book
SAS 9.4 Output Delivery System, 4th Edition
Provides usage information and examples for Output Delivery System (ODS) capabilities. The document describes a wide …
book
SAS 9.4 ODS Graphics, 2nd Edition
Provides comprehensive reference information for the statistical graphics (SG) family of procedures. These procedures include the …