sas/iml 9 - · pdf filewhat’s new in sas/iml 9 and 9.1 overview new to sas/iml are the...
TRANSCRIPT
SAS/IML 9.1Users Guide
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2004. SAS/IML 9.1 Users Guide.Cary, NC: SAS Institute Inc.
SAS/IML 9.1 Users Guide
Copyright 2004, SAS Institute Inc., Cary, NC, USA
ISBN 1-59047-236-5
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 trademarks of their respective companies.
Contents
Whats New in SAS/IML 9 and 9.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 1. Introduction to SAS/IML Software . . . . . . . . . . . . . . . . . . . . . . 5
Chapter 2. Understanding the Language . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Chapter 3. Tutorial: A Module for Linear Regression . . . . . . . . . . . . . . . . . . . 27
Chapter 4. Working with Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Chapter 5. Programming Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Chapter 6. Working with SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . 85
Chapter 7. File Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Chapter 8. General Statistics Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Chapter 9. Robust Regression Examples . . . . . . . . . . . . . . . . . . . . . . . . . 183
Chapter 10. Time Series Analysis and Examples . . . . . . . . . . . . . . . . . . . . . 235
Chapter 11. Nonlinear Optimization Examples . . . . . . . . . . . . . . . . . . . . . . 319
Chapter 12. Graphics Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Chapter 13. Window and Display Features . . . . . . . . . . . . . . . . . . . . . . . . 431
Chapter 14. Storage Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
Chapter 15. Using SAS/IML Software to Generate IML Statements . . . . . . . . . . . 451
Chapter 16. Wavelet Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Chapter 17. Genetic Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
Chapter 18. Sparse Matrix Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . 525
Chapter 19. Further Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
Chapter 20. Language Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
Chapter 21. Module Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009
Subject Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1021
Syntax Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1029
iv
Whats New in SAS/IML 9 and 9.1
Contents
OVERVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
ITERATIVE METHODS FOR LARGE SPARSE SYSTEMS OF LINEAREQUATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
DIRECT ALGORITHMS FOR LARGE SPARSE SYSTEMS OF LINEAREQUATIONS: CHOLESKY FACTORIZATION . . . . . . . . . . . . 3
GENETIC ALGORITHMS . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
NEW FUNCTIONS AND CALLS . . . . . . . . . . . . . . . . . . . . . . . 4BY Group Processing for Matrices . . . . . . . . . . . . . . . . . . . . . . 4SORT and SORTNDX Calls . . . . . . . . . . . . . . . . . . . . . . . . . . 4RANDSEED and RANDGEN Calls . . . . . . . . . . . . . . . . . . . . . 4
NEW PROGRAMMING FEATURE . . . . . . . . . . . . . . . . . . . . . . 4Subscripting by Row or Column Names . . . . . . . . . . . . . . . . . . . 4
2 Whats New in SAS/IML 9 and 9.1
Whats New in SAS/IML 9 and 9.1Overview
New to SAS/IML are the following:
A set of new iterative methods for large sparse systems of linear equations A set of new direct algorithms utilizing Cholesky factorization for large sparse
systems of linear equations
A new chapter on Genetic Algorithms A set of new functions and calls for grouping and sorting A set of new calls for random number generation A new programming feature that extends the matrix subscripting functionality
Iterative Methods for Large Sparse Systems ofLinear Equations
Iterative methods create a new direction in IML: the capability to handle large, sparse 9.1matrices and systems. With sparsity exploitation and iterative approximation algo-rithms, IML can solve linear systems containing as many as 106 variables on a regu-lar PC. The new methods that are used are Conjugate Gradient, Minimum Residual,and Biconjugate Gradient. The collection of preconditioners include fast incompleteCholesky factorization and Jacobi.
Direct Algorithms for Large Sparse Systems ofLinear Equations: CholeskyFactorization
The Cholesky algorithm comprises a minimum degree ordering heuristic and sym- 9.1bolic factorization. The implementation is based on a quotient graph model.
4 Whats New in SAS/IML 9 and 9.1
Genetic Algorithms
Genetic algorithms are a family of search algorithms that seek optimal solutions toproblems using an approach that parallels the principles of natural selection and evo-lution in nature. There are several new experimental subroutines and functions thatenable you to formulate and implement genetic algorithm optimizations. You havethe flexibility either to write your own modules to specify the objective function andgenetic operators or to use standard functions and operators provided by IML.
New Functions and Calls
BY Group Processing for Matrices
A new function, UNIQUEBY, has been added to IML that makes it easier to retrieveand process BY groups in a sorted matrix. You can use the SORT and SORTNDXcalls to sort a matrix, and then call the UNIQUEBY function to get a vector of indicesof the first row of each unique BY group in the input matrix. See the LanguageReference section for full details.
SORT and SORTNDX Calls
Two new subroutines have been added to make sorting of matrices easier. The SORTcall sorts a matrix in place, sorting the rows by specified columns. The SORTNDXfunction creates an index matrix, without rearranging the input matrix, which enablesyou to access the rows of the input matrix in sorted order. The SORTNDX call willnormally be faster than the SORT call, and you can use it to create multiple indexesinto the same input matrix. See the Language Reference section for full details.
RANDSEED and RANDGEN Calls
Two new subroutines have been added to improve the efficiency of random number9.1generation. RANDSEED and RANDGEN use the same algorithm as the data func-tions STREAMINIT and RAND, with changes to maximize performance in IML.See the Language Reference section for full details.
New Programming Feature
Subscripting by Row or Column Names
Matrix subscripting functionality has been extended, so that you can specify a setof rows or columns by the names given in a MATTRIB statement or assigned by adata set statement. This is done by using a character matrix as one or both of thesubscripts. IML will attempt to match character string elements to column or rownames assigned to the matrix. See the Language Reference section for full detailsand examples.
Chapter 1Introduction to SAS/IML Software
Chapter Contents
OVERVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
SAS/IML SOFTWARE: AN OVERVIEW . . . . . . . . . . . . . . . . . . . 7
AN INTRODUCTORY INTERACTIVE SESSION . . . . . . . . . . . . . . 9
PROC IML STATEMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
6 Chapter 1. Introduction to SAS/IML Software
Chapter 1Introduction to SAS/IML SoftwareOverview
SAS/IML software gives you access to a powerful and flexible programming lan-guage (Interactive Matrix Language) in a dynamic, interactive environment. Thefundamental object of the language is a data matrix. You can use SAS/IML soft-ware interactively (at the statement level) to see results immediately, or you can storestatements in a module and execute them later. The programming is dynamic be-cause necessary activities such as memory allocation and dimensioning of matricesare performed automatically.
SAS/IML software is powerful. You can access built-in operators and call routinesto perform complex tasks such as matrix inversion or eigenvector generation. Youcan define your own functions and subroutines using SAS/IML modules. You canoperate on a single value or take advan