Transcription of SAS 9.3 Macro Language Reference - SAS Technical …
1 SAS Macro LanguageReferenceSAS DocumentationThe correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2011. SAS Macro Language : Reference . Cary, NC: SASI nstitute Macro Language : ReferenceCopyright 2011, SAS Institute Inc., Cary, NC, USAISBN 978-1-60764-894-9 All rights reserved. Produced in the United States of a hardcopy book: No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means,electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute a Web download or e-book:Your use of this publication shall be governed by the terms established by the vendor at the time you acquire scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the publisher is illegal andpunishable by law. Please purchase only authorized electronic editions and do not participate in or encourage electronic piracy of copyrightedmaterials.
2 Your support of others' rights is Government Restricted Rights Notice: Use, duplication, or disclosure of this software and related documentation by the government issubject to the Agreement with SAS Institute and the restrictions set forth in FAR 19 Commercial Computer Software-Restricted Rights(June 1987).SAS Institute Inc., SAS Campus Drive, Cary, North Carolina electronic book, July 20111st printing, July 2011 SAS Publishing provides a complete selection of books and electronic products to help customers use SAS software to its fullest potential. Formore information about our e-books, e-learning products, CDs, and hard-copy books, visit the SAS Publishing Web site or call and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and othercountries. indicates USA brand and product names are registered trademarks or trademarks of their respective This Book .. viiWhat's New in the SAS Macro Language Facility.
3 IxRecommended Reading .. xiPART 1 Understanding and Using the Macro Facility1 Chapter 1 Introduction to the Macro Facility .. 3 Getting Started with the Macro Facility .. 3 Replacing Text Strings Using Macro Variables .. 4 Generating SAS Code Using Macros .. 5 More Advanced Macro Techniques .. 9 Other Features of the Macro Language .. 10 Chapter 2 SAS Programs and Macro Processing .. 11 SAS Programs and Macro Processing .. 11 How SAS Processes Statements without Macro Activity .. 12 How SAS Processes Statements with Macro Activity .. 14 Chapter 3 Macro Variables .. 19 Macro Variables .. 19 Macro Variables Defined by the Macro Processor .. 20 Macro Variables Defined by Users .. 23 Using Macro Variables .. 27 Displaying Macro Variable Values .. 29 Referencing Macro Variables Indirectly .. 30 Manipulating Macro Variable Values with Macro Functions .. 32 Chapter 4 Macro Processing .. 33 Macro Processing .. 33 Defining and Calling Macros .. 33 How the Macro Processor Compiles a Macro Definition.
4 34 How the Macro Processor Executes a Compiled Macro .. 36 Summary of Macro Processing .. 41 Chapter 5 Scopes of Macro Variables .. 43 Scopes of Macro Variables .. 43 Global Macro Variables .. 44 Local Macro Variables .. 46 Writing the Contents of Symbol Tables to the SAS Log .. 48 How Macro Variables Are Assigned and Resolved .. 49 Examples of Macro Variable Scopes .. 52 Special Cases of Scope with the CALL SYMPUT Routine .. 63 Chapter 6 Macro Expressions .. 71 Macro Expressions .. 71 Defining Arithmetic and Logical Expressions .. 72 How the Macro Processor Evaluates Arithmetic Expressions .. 74 How the Macro Processor Evaluates Logical Expressions .. 76 Chapter 7 Macro Quoting .. 79 Macro Quoting .. 80 Deciding When to Use a Macro Quoting Function and Which Function to Use .. 83%STR and %NRSTR Functions .. 85%BQUOTE and %NRBQUOTE Functions .. 89 Referring to Already Quoted Variables .. 90 Deciding How Much Text to Mask with a Macro Quoting Function .. 91%SUPERQ Function.
5 91 Summary of Macro Quoting Functions and the Characters that They Mask .. 94 Unquoting Text .. 95 How Macro Quoting Works .. 97 Other Functions That Perform Macro Quoting .. 98 Chapter 8 Interfaces with the Macro Facility .. 101 Interfaces with the Macro Facility .. 101 DATA Step Interfaces .. 102 Using SAS Language Functions in the DATA Step and Macro Facility .. 105 Interfaces with the SQL Procedure .. 106 Interfaces with the SAS Component Language .. 107 SAS/CONNECT Interfaces .. 110 Chapter 9 Storing and Reusing Macros .. 113 Storing and Reusing Macros .. 113 Saving Macros in an Autocall Library .. 114 Saving Macros Using the Stored Compiled Macro Facility .. 117 Chapter 10 Macro Facility Error Messages and Debugging .. 119 General Macro Debugging Information .. 120 Troubleshooting Your Macros .. 121 Debugging Techniques .. 134 Chapter 11 Writing Efficient and Portable Macros .. 141 Writing Efficient and Portable Macros .. 141 Keeping Efficiency in Perspective.
6 142 Writing Efficient Macros .. 142 Writing Portable Macros .. 148 Chapter 12 Macro Language Elements .. 155 Macro Language Elements .. 155 Macro Statements .. 156 Macro Functions .. 158 Automatic Macro Variables .. 164 Interfaces with the Macro Facility .. 167 Selected Autocall Macros Provided with SAS Software .. 168 Selected System Options Used in the Macro Facility .. 170 PART 2 Macro Language Dictionary173 Chapter 13 AutoCall Macros .. 175 AutoCall Macros .. 175 Dictionary .. 175ivContentsChapter 14 Automatic Macro Variables .. 191 Automatic Macro Variables .. 192 Dictionary .. 192 Chapter 15 DATA Step Call Routines for Macros .. 221 DATA Step Call Routines for Macros .. 221 Dictionary .. 221 Chapter 16 DATA Step Functions for Macros .. 231 DATA Step Functions for Macros .. 231 Dictionary .. 231 Chapter 17 Macro Functions .. 241 Macro Functions .. 241 Dictionary .. 242 Chapter 18 SQL Clauses for Macros .. 277 SQL Clauses for Macros .. 277 Dictionary .. 277 Chapter 19 Macro Statements.
7 281 Macro Statements .. 281 Dictionary .. 282 Chapter 20 System Options for Macros .. 329 System Options for Macros .. 329 Dictionary .. 330 PART 3 Appendices361 Appendix 1 Reserved Words in the Macro Facility .. 363 Macro Facility Word Rules .. 363 Reserved Words .. 363 Appendix 2 SAS Tokens .. 365 SAS Tokens .. 365 List of Tokens .. 365 Appendix 3 Syntax for Selected Functions Used with the %SYSFUNC Function .. 367 Summary Descriptions and Syntax .. 367 Functions and Arguments for %SYSFUNC .. 367 Glossary .. 373 Index .. 379 ContentsvviContentsAbout This BookSyntax Conventions for the SAS LanguageOverview of Syntax Conventions for the SAS LanguageSAS uses standard conventions in the documentation of syntax for SAS languageelements. These conventions enable you to easily identify the components of SASsyntax. The conventions can be divided into these parts: syntax components style conventions references to SAS libraries and external filesSyntax ComponentsThe components of the syntax for most Language elements include a keyword andarguments.
8 For some Language elements only a keyword is necessary. For other languageelements the keyword is followed by an equal sign (=).Note:In most cases, example code in SAS documentation is written in lowercase with amonospace font. You can use uppercase, lowercase, or mixed case in the code thatyou ConventionsThe style conventions that are used in documenting SAS syntax include uppercase bold,uppercase, and italic:UPPERCASE BOLD identifies SAS keywords such as the names of functions or statements. In thefollowing example, the keyword ERROR is written in uppercase bold:ERROR<message>;UPPERCASE identifies arguments that are literals. In the following example of the CMPMODEL=system option, the literals include BOTH, CATALOG, and XML:CMPMODEL = BOTH | CATALOG | XMLviiitalicsidentifies arguments or values that you supply. Items in italics represent user-supplied values that are either non-literal arguments or nonliteral values that areassigned to an in italics can also be the generic name for a list of arguments from which youcan choose (for example, attribute-list).
9 If more than one of an item in italics can beused, the items are expressed as item-1, .., to SAS Libraries and External FilesMany SAS statements and other Language elements refer to SAS libraries and externalfiles. You can choose whether to make the Reference through a logical name (a libref orfileref) or use the physical filename enclosed in quotation marks. If you use a logicalname, you usually have a choice of using a SAS statement (LIBNAME or FILENAME)or the operating environment's control Language to make the association. Severalmethods of referring to SAS libraries and external files are available, and some of thesemethods depend on your operating the examples that use external files, SAS documentation uses the italicized phrasefile-specification. In the examples that use SAS libraries, SAS documentation uses theitalicized phrase SAS-library. Note that SAS-library is enclosed in quotation marks:infile file-specification obs = 100;libname libref 'SAS-library';viiiAbout This BookWhat's New in the SAS MacroLanguage FacilityOverviewThe Macro Language Facility has the following enhancements: new automatic Macro variables that enable you to reduce the amount of text that isneeded to perform common tasks new Macro functions new Macro statements new Macro system options that enable you to define and redefine macros and tobetter control their executionAutomatic Macro VariablesSYSADDRBITS contains the number of bits of an an indication of the byte order of the current session.
10 The possible valuesare LITTLE or the number of observations read from the last data set that was closed by theprevious procedure or DATA the value of the ODS ESCAPECHAR= from within the the length in bytes of a long integer in the current the size in bytes of a the length in bytes of a Unicode character in the current Functions%SYSMACEXEC indicates whether a Macro is currently whether there is a Macro definition in the the depth of nesting from the point of the name of the Macro executing at a nesting Statements%SYSMSTORECLEAR closes stored compiled macros and clears the SASMSTORE= a Macro definition from the System OptionsMAUTOCOMPLOC displays in the SAS log the source location of the autocall macros when the autocallmacro is whether the Macro processor prepends the full pathname of the autocallsource file to the description field of the catalog entry of compiled auto call macrodefinition in the the generation of coverage analysis the location of the coverage analysis data Macro LanguageRecommended Reading Carpenter's Complete Guide to the SAS Macro Language Debugging SAS Programs: A Handbook of Tools and Techniques SAS Macro Programming Made Easy Base SAS Procedures Guide SAS Language Reference : Concepts SAS Functions and CALL Routines: ReferenceFor a complete list of SAS publications, go to If you havequestions about which titles you need, please contact a SAS Publishing SalesRepresentative:SAS Publishing SalesSAS Campus DriveCary, NC 27513-2414 Phone: 1-800-727-3228 Fax: 1-919-677-8166E-mail: address: ReadingPart 1 Understanding and Using theMacro FacilityChapter 1 Introduction to the Macro Facility.
