Macro Language Reference.pdf

(2232 KB) Pobierz
SAS 9.1 Macro Language
SAS ® 9.1 Macro Language
Reference
400762135.023.png 400762135.024.png 400762135.025.png 400762135.026.png 400762135.001.png 400762135.002.png
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2004.
SAS ® 9.1 Macro Language: Reference . Cary, NC: SAS Institute Inc.
SAS ® 9.1 Macro Language: Reference
Copyright © 2004, SAS Institute Inc., Cary, NC, USA
ISBN 1-59047-212-8
All rights reserved. Produced in the United States of America. 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 Inc.
U.S. Government Restricted Rights Notice. Use, duplication, or disclosure of this
software and related documentation by the U.S. government is subject to the Agreement
with SAS Institute and the restrictions set forth in FAR 52.227–19 Commercial Computer
Software-Restricted Rights (June 1987).
SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513.
1st printing, January 2004
SAS Publishing provides a complete selection of books and electronic products to help
customers use SAS software to its fullest potential. For more information about our
e-books, e-learning products, CDs, and hard-copy books, visit the SAS Publishing Web site
at support.sas.com/pubs or call 1-800-727-3228.
SAS ® and all other SAS Institute Inc. product or service names are registered trademarks
or trademarks of SAS Institute Inc. in the USA and other countries.
indicates USA
registration.
Other brand and product names are registered trademarks or trademarks of their
respective companies.
®
Contents
What’s New vii
Overview vii
New Automatic Macro Variable vii
New Comparison Operators vii
New SAS System Options viii
New Macro Statements viii
New Macro Functions viii
New Option for the %MACRO Statement viii
PART 1 Understanding and Using the Macro Facility 1
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 8
Other Features of the Macro Language 10
Chapter 2 SAS Programs and Macro Processing 11
Introduction to 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
Introduction to Macro Variables 19
Macro Variables Defined by SAS 20
Macro Variables Defined by Users 22
Using Macro Variables 25
Displaying Macro Variable Values 28
Referencing Macro Variables Indirectly 29
Manipulating Macro Variable Values with Macro Functions 30
Chapter 4 Macro Processing 33
Introduction to Macro Processing 33
Defining and Calling Macros 33
How the Macro Processor Compiles a Macro Definition 34
How the Macro Processor Executes a Compiled Macro 36
Summary of Macro Processing 40
Chapter 5 Scopes of Macro Variables 41
Introduction to the Scopes of Macro Variables 41
Global Macro Variables 42
Local Macro Variables 43
400762135.003.png 400762135.004.png 400762135.005.png 400762135.006.png 400762135.007.png 400762135.008.png
iv
Writing the Contents of Symbol Tables to the SAS Log 45
How Macro Variables Are Assigned and Resolved 45
Examples of Macro Variable Scopes 48
Chapter 6 Macro Expressions 67
Introduction to Macro Expressions 67
Defining Arithmetic and Logical Expressions 68
How the Macro Processor Evaluates Arithmetic Expressions 70
How the Macro Processor Evaluates Logical Expressions 71
Chapter 7 Macro Quoting 75
Introduction to Macro Quoting 75
Deciding When to Use a Macro Quoting Function and Which Function to Use 78
Using the %STR and %NRSTR Functions 80
Using the %BQUOTE and %NRBQUOTE Functions 84
Referring to Already Quoted Variables 85
Deciding How Much Text to Mask with a Macro Quoting Function 85
Using %SUPERQ 86
Summary of Macro Quoting Functions and the Characters They Mask 88
Unquoting Text 89
How Macro Quoting Works 91
Other Functions That Perform Macro Quoting 92
Chapter 8 Interfaces with the Macro Facility 95
Introduction to Interfaces with the Macro Facility 95
DATA Step Interfaces 96
Using SAS Language Functions in the DATA Step and Macro Facility 99
Interfaces with the SQL Procedure 100
Interfaces with the SAS Component Language 101
SAS/CONNECT Interfaces 103
Chapter 9 Storing and Reusing Macros 105
Introduction to Storing and Reusing Macros 105
Saving Macros in an Autocall Library 106
Saving Macros Using the Stored Compiled Macro Facility 108
Chapter 10 Macro Facility Error Messages and Debugging 111
General Macro Debugging Information 111
Troubleshooting Your Macros 113
Debugging Techniques 126
Chapter 11 Writing Efficient and Portable Macros 133
Introduction to Writing Efficient and Portable Macros 133
Keeping Efficiency in Perspective 133
Writing Efficient Macros 134
Writing Portable Macros 140
400762135.009.png 400762135.010.png 400762135.011.png 400762135.012.png 400762135.013.png 400762135.014.png 400762135.015.png
v
Chapter 12 Macro Language Elements 147
Introduction to Macro Language Elements 147
Macro Statements 147
Macro Functions 149
Automatic Macro Variables 154
Interfaces with the Macro Facility 156
Selected Autocall Macros Provided with SAS Software 157
Selected System Options Used in the Macro Facility 158
PART 2 Macro Language Dictionary 161
Chapter 13 Macro Language Dictionary 163
PART 3 Appendixes 315
Appendix 1 Reserved Words in the Macro Facility 317
Macro Facility Word Rules 317
Reserved Words 317
Appendix 2 SAS Tokens 319
What Are SAS Tokens? 319
List of Tokens 319
Appendix 3 Syntax for Selected Functions Used with the %SYSFUNC Function 321
Summary Descriptions and Syntax 321
Appendix 4 Recommended Reading 325
Recommended Reading 325
Glossary 327
Index 333
400762135.016.png 400762135.017.png 400762135.018.png 400762135.019.png 400762135.020.png 400762135.021.png 400762135.022.png
Zgłoś jeśli naruszono regulamin