Transcription of SAS/IML 9.22 User's Guide
1 SAS/IML s GuideSAS DocumentationThe correct bibliographic citation for this manual is as follows: SAS Institute Inc. user s , NC: SAS Institute user s GuideCopyright 2010, SAS Institute Inc., Cary, NC, USAAll rights reserved. Produced in the United States of a hard-copy book: No part of this publication may be reproduced, stored in a retrieval system, or transmitted, inany form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission ofthe publisher, SAS Institute a Web download or e-book: Your use of this publication shall be governed by the terms established by the vendorat the time you acquire this Government Restricted Rights Notice: Use, duplication, or disclosure of this software and related documentationby the government is subject to the Agreement with SAS Institute and the restrictions set forth in FAR ,Commercial Computer Software-Restricted Rights (June 1987).SAS Institute Inc., SAS Campus Drive, Cary, North Carolina electronic book, November 2010 SAS Publishing provides a complete selection of books and electronic products to help customers use SAS software toits fullest potential.
2 For more information about our e-books, e-learning products, CDs, and hard-copy books, visit theSAS Publishing Web site call and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS InstituteInc. in the USA and other countries. indicates USA brand and product names are registered trademarks or trademarks of their respective s New in SAS/IML ..1 Chapter to SAS/IML Software..7 Chapter the SAS/IML Language..13 Chapter : A Module for Linear Regression..27 Chapter with Matrices..39 Chapter Statements..63 Chapter with SAS Data Sets..85 Chapter Access..109 Chapter Statistics Examples..125 Chapter 10. Submitting SAS Statements..183 Chapter 11. Calling Functions in the R Language..195 Chapter 12. Robust Regression Examples..211 Chapter 13. Time Series Analysis and Examples..255 Chapter 14. Nonlinear Optimization Examples..341 Chapter 15. Graphics Examples..417 Chapter 16. Window and Display Features.
3 447 Chapter 17. Storage Features..461 Chapter 18. Using SAS/IML Software to Generate SAS/IML Statements..467 Chapter 19. Wavelet Analysis..483 Chapter 20. Genetic Algorithms..505 Chapter 21. Sparse Matrix Algorithms..535 Chapter 22. Further Notes..545 Chapter 23. Language Reference..553 Chapter 24. Module Library..1067 Subject Index1085 Syntax Index1095ivChapter 1 What s New in SAS/IML ..1 New Features..2 New Functions and Subroutines..2 CORR Function..3 COV Function..3 COUNTN Function..3 COUNTMISS Function..3 COUNTUNIQUE Function..3 CUPROD Function..3 DIF Function..3 FULL Function..4 LAG Function..4 MEAN Function..4 PROD Function..4 QNTL Call..4 SPARSE Function..4 VAR Function..4 Changes to the IMLMLIB Library..5 Documentation Enhancements..5 Highlights of Enhancements in SAS/IML ..5 Related Software..6 OverviewSAS/IML includes two new features and many new functions and subroutines. The followingfeatures are new: the ability to call SAS procedures and DATA steps from within the IML procedure.
4 The ability to call functions and packages in the R statistical programming language fromwithin the IML procedure. You can use new SAS/IML subroutines to transfer data betweenSAS data formats and R data 1: What s New in SAS/IML FeaturesSAS/IML supports theSUBMITandENDSUBMIT statements. These statements delimit ablock of statements that are sent to another language for SUBMIT and ENDSUBMIT statements enable you to call SAS procedures and DATA stepswithout leaving the IML procedure. This feature has been very popular in SAS/IML Studio sinceit was introduced in 2002, and it is now available in PROC can use SAS data sets to transfer data between SAS/IML matrices and SAS procedures. SASprocedures require that data be in a SAS data SUBMIT and ENDSUBMIT statements also provide an interface to the R statistical program-ming language, so that you can to submit R statements from within your SAS/IML program. Tosubmit statements to R, specify the R option in the SUBMIT can transfer data from SAS/IML matrices and SAS data sets into R matrices and R data frames,and vice versa.
5 Specifically, the subroutines shown inTable available to transfer data from aSAS format into an R interface to R is supported only on computers that run the Windows or Linux operating from a SAS Source to an R DestinationSubroutineSAS SourceR DestinationExportDataSetToRSAS data setR data frameExportMatrixToRSAS/IML matrixR matrixIn addition, the subroutines shown in Table available to transfer data from an R format intoa SAS from an R Source to a SAS DestinationSubroutineR SourceSAS DestinationImportDataSetFromRR expressionSAS data setImportMatrixFromRR expressionSAS/IML matrixIn Table , an R expression can be the name of a data frame, the name of a matrix, or anexpression that results in either of these data Functions and SubroutinesSAS/IML provides the new functions and subroutines described in the following FunctionF3 CORR FunctionTheCORR functioncomputes a sample correlation matrix for data. The function supports Pearsonproduct-moment correlations, Hoeffding sDstatistics, Kendall s tau-bcoefficients, and Spearmancorrelation coefficients based on the ranks of the variables.
6 The function supports two differentmethods for dealing with missing values in the FunctionThe COV function computes a sample variance-covariance matrix for data. The function supportstwo different methods for dealing with missing values in the FunctionThe COUNTN functioncounts the number of nonmissing values in a FunctionThe COUNTMISS functioncounts the number of missing values in a FunctionTheCOUNTUNIQUE functioncounts the number of unique values in a FunctionThe CUPROD functioncomputes the cumulative product of elements in a FunctionThe DIF function computes the differences between data values and one or more lagged (shifted)values for time series 1: What s New in SAS/IML FunctionTheFULL functionconverts a matrix stored in a sparse format into a matrix stored in a denseformat. See theSPARSE functionfor a description of how sparse matrices are FunctionThe LAG functioncomputes one or more lagged (shifted) values for time series FunctionThe MEAN functioncomputes a sample mean of data.
7 The function can compute arithmetic means,trimmed means, and Winsorized FunctionThe PROD functioncomputes the product of elements in one or more CallTheQNTL subroutinecomputes sample quantiles for FunctionThe SPARSE functionconverts a matrix that contains many zeros into a matrix stored in a sparseformat which suitable for use with theITSOLVER subroutineor theSOLVELIN FunctionThe VAR functioncomputes a sample variance for each column of a data to the IMLMLIB LibraryF5 Changes to the IMLMLIB LibraryThe CORR module has been removed from the IMLMLIB library. In its place is the MEDIAN, QUARTILE, and STANDARD modules now support missing values in the EnhancementsThe first six chapters of this documentation have been completely rewritten in order to providenew users with a gentle introduction to the SAS/IML language. Two new chapters have been writ-ten: Chapter 10, Submitting SAS Statements, describes how to call SAS procedures from withinPROC IML, and Chapter 11, Calling Functions in the R Language, describes how to call R func-tions from within PROC of Enhancements in SAS/IML following are some of the major enhancements that were introduced in SAS/IML : A new programming syntax to specify vector-matrix operations was introduced.
8 New modules for sampling from multivariate distributions were added to the IMLMLIB li-brary. The following functions and subroutines were introduced: the ODSGRAPH subroutine, which provides an interface with ODS Statistical Graphicsand the TEMPLATE procedure the BSPLINE function, which computes a B-spline basis for a given numeric inputvector, degree, and knot specification the GEOMEAN andHARMEAN functions, which compute the geometric mean andthe harmonic mean, respectively, of a matrix of positive numbers6 FChapter 1: What s New in SAS/IML SoftwareSAS/STAT and SAS/IML users might be interested in SAS/IML Studio, which is software for dataexploration, model building, simulation, and analysis. SAS/IML Studio is distributed with theSAS/IML Studio provides a highly flexible programming environment in which you can create andrun programs and display the results with dynamically linked graphics and data tables. SAS/IMLS tudio is intended for data analysts who write SAS programs to solve statistical problems but needmore versatility for data exploration and model building.
9 The programming language in SAS/IMLS tudio, which is called IMLPlus, is an enhanced version of the SAS/IML programming extends the SAS/IML language to provide new features, including the ability to create andmanipulate statistical graphics, call SAS procedures as functions, call functions in the R language,and call computational programs written in C, C++, Java, and Fortran. SAS/IML Studio runs on aPC in the Microsoft Windows operating more information about SAS/IML Studio, see theSAS/IML Studio user s GuideandSAS/IMLS tudio for SAS/STAT 2 Introduction to SAS/IML SoftwareContentsOverview of SAS/IML Software..7 Highlights of SAS/IML Software..8An Introductory SAS/IML Program..9 PROC IML Statement..10 Conventions Used in This Book..10 Typographical Conventions..10 Output of Examples..11 Overview of SAS/IML SoftwareSAS/IML software gives you access to a powerful and flexible programming language in a dynamic,interactive environment. The acronym IML stands for interactive matrix language.
10 The fundamental object of the language is a data matrix. You can use SAS/IML software interac-tively (at the statement level) to see results immediately, or you can submit blocks of statements oran entire program. You can also encapsulate a series of statements by defining a module; you cancall the module later to execute all of the statements in the software is powerful. SAS/IML software enables you to concentrate on solving prob-lems because necessary (but distracting) activities such as memory allocation and dimensioning ofmatrices are performed automatically. You can use built-in operators and call routines to performcomplex tasks in numerical linear algebra such as matrix inversion or the computation of eigen-values. You can define your own functions and subroutines by using SAS/IML modules. You canperform operations on a single value or take advantage of matrix operators to perform operations onan entire data matrix. For example, the following statement adds 1 to every element of the matrixx, regardless of the dimensions ofx:x = x+1;The SAS/IML language contains statements that enable you to manage data.