sas/access 9.2 for relational databases: reference, fourth...

984
SAS/ACCESS ® 9.2 for Relational Databases Reference Fourth Edition

Upload: lamkien

Post on 07-Feb-2018

274 views

Category:

Documents


11 download

TRANSCRIPT

  • SAS/ACCESS 9.2for Relational DatabasesReferenceFourth Edition

  • Here is the correct bibliographic citation for this document: SAS Institute Inc. 2010.SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition. Cary, NC: SASInstitute Inc.

    SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth EditionCopyright 2010, SAS Institute Inc., Cary, NC, USAISBN 978-1-60764-619-8All rights reserved. Produced in the United States of America.For a hard-copy book: No part of this publication may be reproduced, stored in aretrieval system, or transmitted, in any form or by any means, electronic, mechanical,photocopying, or otherwise, without the prior written permission of the publisher, SASInstitute Inc.For a Web download or e-book: Your use of this publication shall be governed by theterms established by the vendor at the time you acquire this publication.U.S. Government Restricted Rights Notice. Use, duplication, or disclosure of thissoftware and related documentation by the U.S. government is subject to the Agreementwith SAS Institute and the restrictions set forth in FAR 52.227-19 Commercial ComputerSoftware-Restricted Rights (June 1987).SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513.1st electronic book, November 2010

    1st printing, November 2010SAS Publishing provides a complete selection of books and electronic products to helpcustomers use SAS software to its fullest potential. For more information about oure-books, e-learning products, CDs, and hard-copy books, visit the SAS Publishing Web siteat support.sas.com/publishing or call 1-800-727-3228.SAS and all other SAS Institute Inc. product or service names are registered trademarksor trademarks of SAS Institute Inc. in the USA and other countries. indicates USAregistration.Other brand and product names are registered trademarks or trademarks of theirrespective companies.

  • Contents

    Whats New xiiiOverview xiiiAll Supported SAS/ACCESS Interfaces to Relational Databases xivSAS/ACCESS Interface to Aster nCluster xivSAS/ACCESS Interface to DB2 under UNIX and PC Hosts xivSAS/ACCESS Interface to DB2 under z/OS xvSAS/ACCESS Interface to Greenplum xviSAS/ACCESS Interface to HP Neoview xviSAS/ACCESS Interface to Informix xviiSAS/ACCESS Interface to MySQL xviiSAS/ACCESS Interface to Netezza xviiSAS/ACCESS Interface to ODBC xviiSAS/ACCESS Interface to OLE DB xviiSAS/ACCESS Interface to Oracle xviiiSAS/ACCESS Interface to Sybase xviiiSAS/ACCESS Interface to Sybase IQ xviiiSAS/ACCESS Interface to Teradata xixDocumentation Enhancements xx

    P A R T 1 Concepts 1Chapter 1 Overview of SAS/ACCESS Interface to Relational Databases 3About This Document 3Methods for Accessing Relational Database Data 4Selecting a SAS/ACCESS Method 4SAS Views of DBMS Data 6Choosing Your Degree of Numeric Precision 7

    Chapter 2 SAS Names and Support for DBMS Names 11Introduction to SAS/ACCESS Naming 11SAS Naming Conventions 12SAS/ACCESS Default Naming Behaviors 13Renaming DBMS Data 14Options That Affect SAS/ACCESS Naming Behavior 15Naming Behavior When Retrieving DBMS Data 15Naming Behavior When Creating DBMS Objects 16SAS/ACCESS Naming Examples 17

    Chapter 3 Data Integrity and Security 25Introduction to Data Integrity and Security 25DBMS Security 25SAS Security 26

  • iv

    Potential Result Set Differences When Processing Null Data 31

    Chapter 4 Performance Considerations 35Increasing Throughput of the SAS Server 35Limiting Retrieval 35Repeatedly Accessing Data 37Sorting DBMS Data 37Temporary Table Support for SAS/ACCESS 38

    Chapter 5 Optimizing Your SQL Usage 41Overview of Optimizing Your SQL Usage 41Passing Functions to the DBMS Using PROC SQL 42Passing Joins to the DBMS 43Passing the DELETE Statement to Empty a Table 45When Passing Joins to the DBMS Will Fail 45Passing DISTINCT and UNION Processing to the DBMS 46Optimizing the Passing of WHERE Clauses to the DBMS 47Using the DBINDEX=, DBKEY=, and MULTI_DATASRC_OPT= Options 48

    Chapter 6 Threaded Reads 51Overview of Threaded Reads in SAS/ACCESS 51Underlying Technology of Threaded Reads 51SAS/ACCESS Interfaces and Threaded Reads 52Scope of Threaded Reads 52Options That Affect Threaded Reads 53Generating Trace Information for Threaded Reads 54Performance Impact of Threaded Reads 57Autopartitioning Techniques in SAS/ACCESS 57Data Ordering in SAS/ACCESS 58Two-Pass Processing for SAS Threaded Applications 58When Threaded Reads Do Not Occur 59Summary of Threaded Reads 59

    Chapter 7 How SAS/ACCESS Works 61Introduction to How SAS/ACCESS Works 61How the SAS/ACCESS LIBNAME Statement Works 62How the SQL Pass-Through Facility Works 63How the ACCESS Procedure Works 64How the DBLOAD Procedure Works 65

    Chapter 8 Overview of In-Database Procedures 67Introduction to In-Database Procedures 67Running In-Database Procedures 69In-Database Procedure Considerations and Limitations 70Using MSGLEVEL Option to Control Messaging 72

    P A R T 2 General Reference 73

  • v

    Chapter 9 SAS/ACCESS Features by Host 75Introduction 75SAS/ACCESS Interface to Aster nCluster: Supported Features 75SAS/ACCESS Interface to DB2 Under UNIX and PC Hosts: Supported Features 76SAS/ACCESS Interface to DB2 Under z/OS: Supported Features 77SAS/ACCESS Interface to Greenplum: Supported Features 77SAS/ACCESS Interface to HP Neoview: Supported Features 78SAS/ACCESS Interface to Informix: Supported Features 78SAS/ACCESS Interface to Microsoft SQL Server: Supported Features 79SAS/ACCESS Interface to MySQL: Supported Features 79SAS/ACCESS Interface to Netezza: Supported Features 80SAS/ACCESS Interface to ODBC: Supported Features 81SAS/ACCESS Interface to OLE DB: Supported Features 82SAS/ACCESS Interface to Oracle: Supported Features 82SAS/ACCESS Interface to Sybase: Supported Features 83SAS/ACCESS Interface to Sybase IQ: Supported Features 84SAS/ACCESS Interface to Teradata: Supported Features 85

    Chapter 10 The LIBNAME Statement for Relational Databases 87Overview of the LIBNAME Statement for Relational Databases 87Assigning a Libref Interactively 88LIBNAME Options for Relational Databases 92

    Chapter 11 Data Set Options for Relational Databases 203About the Data Set Options for Relational Databases 207

    Chapter 12 Macro Variables and System Options for Relational Databases 401Introduction to Macro Variables and System Options 401Macro Variables for Relational Databases 401System Options for Relational Databases 403

    Chapter 13 The SQL Pass-Through Facility for Relational Databases 425About SQL Procedure Interactions 425Syntax for the SQL Pass-Through Facility for Relational Databases 426

    P A R T 3 DBMS-Specific Reference 437Chapter 14 SAS/ACCESS Interface to Aster nCluster 439Introduction to SAS/ACCESS Interface to Aster nCluster 439LIBNAME Statement Specifics for Aster nCluster 440Data Set Options for Aster nCluster 443SQL Pass-Through Facility Specifics for Aster nCluster 445Autopartitioning Scheme for Aster nCluster 446Passing SAS Functions to Aster nCluster 448Passing Joins to Aster nCluster 449Bulk Loading for Aster nCluster 450

  • vi

    Naming Conventions for Aster nCluster 451Data Types for Aster nCluster 452

    Chapter 15 SAS/ACCESS Interface to DB2 Under UNIX and PC Hosts 455Introduction to SAS/ACCESS Interface to DB2 Under UNIX and PC Hosts 456LIBNAME Statement Specifics for DB2 Under UNIX and PC Hosts 456Data Set Options for DB2 Under UNIX and PC Hosts 460SQL Pass-Through Facility Specifics for DB2 Under UNIX and PC Hosts 462Autopartitioning Scheme for DB2 Under UNIX and PC Hosts 464Temporary Table Support for DB2 Under UNIX and PC Hosts 467DBLOAD Procedure Specifics for DB2 Under UNIX and PC Hosts 468Passing SAS Functions to DB2 Under UNIX and PC Hosts 470Passing Joins to DB2 Under UNIX and PC Hosts 472Bulk Loading for DB2 Under UNIX and PC Hosts 472In-Database Procedures in DB2 under UNIX and PC Hosts 475Locking in the DB2 Under UNIX and PC Hosts Interface 475Naming Conventions for DB2 Under UNIX and PC Hosts 477Data Types for DB2 Under UNIX and PC Hosts 477

    Chapter 16 SAS/ACCESS Interface to DB2 Under z/OS 483Introduction to SAS/ACCESS Interface to DB2 Under z/OS 485LIBNAME Statement Specifics for DB2 Under z/OS 485Data Set Options for DB2 Under z/OS 487SQL Pass-Through Facility Specifics for DB2 Under z/OS 489Autopartitioning Scheme for DB2 Under z/OS 491Temporary Table Support for DB2 Under z/OS 492Calling Stored Procedures in DB2 Under z/OS 494ACCESS Procedure Specifics for DB2 Under z/OS 496DBLOAD Procedure Specifics for DB2 Under z/OS 498The DB2EXT Procedure 500The DB2UTIL Procedure 502Maximizing DB2 Under z/OS Performance 507Passing SAS Functions to DB2 Under z/OS 510Passing Joins to DB2 Under z/OS 511SAS System Options, Settings, and Macros for DB2 Under z/OS 512Bulk Loading for DB2 Under z/OS 515Locking in the DB2 Under z/OS Interface 520Naming Conventions for DB2 Under z/OS 521Data Types for DB2 Under z/OS 521Understanding DB2 Under z/OS Client/Server Authorization 527DB2 Under z/OS Information for the Database Administrator 529

    Chapter 17 SAS/ACCESS Interface to Greenplum 533Introduction to SAS/ACCESS Interface to Greenplum 534LIBNAME Statement Specifics for Greenplum 534Data Set Options for Greenplum 537

  • vii

    SQL Pass-Through Facility Specifics for Greenplum 539Autopartitioning Scheme for Greenplum 540Passing SAS Functions to Greenplum 542Passing Joins to Greenplum 544Bulk Loading for Greenplum 544Naming Conventions for Greenplum 547Data Types for Greenplum 548

    Chapter 18 SAS/ACCESS Interface to HP Neoview 553Introduction to SAS/ACCESS Interface to HP Neoview 554LIBNAME Statement Specifics for HP Neoview 554Data Set Options for HP Neoview 557SQL Pass-Through Facility Specifics for HP Neoview 559Autopartitioning Scheme for HP Neoview 561Temporary Table Support for HP Neoview 562Passing SAS Functions to HP Neoview 564Passing Joins to HP Neoview 565Bulk Loading and Extracting for HP Neoview 565Naming Conventions for HP Neoview 568Data Types for HP Neoview 568

    Chapter 19 SAS/ACCESS Interface for Informix 573Introduction to SAS/ACCESS Interface to Informix 574LIBNAME Statement Specifics for Informix 574Data Set Options for Informix 576SQL Pass-Through Facility Specifics for Informix 577Autopartitioning Scheme for Informix 580Temporary Table Support for Informix 581Passing SAS Functions to Informix 582Passing Joins to Informix 583Locking in the Informix Interface 584Naming Conventions for Informix 585Data Types for Informix 585Overview of Informix Servers 588

    Chapter 20 SAS/ACCESS Interface to Microsoft SQL Server 591Introduction to SAS/ACCESS Interface to Microsoft SQL Server 591LIBNAME Statement Specifics for Microsoft SQL Server 592Data Set Options for Microsoft SQL Server 595SQL Pass-Through Facility Specifics for Microsoft SQL Server 597DBLOAD Procedure Specifics for Microsoft SQL Server 598Passing SAS Functions to Microsoft SQL Server 600Locking in the Microsoft SQL Server Interface 600Naming Conventions for Microsoft SQL Server 601Data Types for Microsoft SQL Server 602

  • viii

    Chapter 21 SAS/ACCESS Interface for MySQL 605Introduction to SAS/ACCESS Interface to MySQL 605LIBNAME Statement Specifics for MySQL 605Data Set Options for MySQL 608SQL Pass-Through Facility Specifics for MySQL 609Autocommit and Table Types 610Understanding MySQL Update and Delete Rules 611Passing SAS Functions to MySQL 612Passing Joins to MySQL 613Naming Conventions for MySQL 614Data Types for MySQL 615Case Sensitivity for MySQL 619

    Chapter 22 SAS/ACCESS Interface to Netezza 621Introduction to SAS/ACCESS Interface to Netezza 622LIBNAME Statement Specifics for Netezza 622Data Set Options for Netezza 625SQL Pass-Through Facility Specifics for Netezza 626Temporary Table Support for Netezza 628Passing SAS Functions to Netezza 630Passing Joins to Netezza 631Bulk Loading and Unloading for Netezza 632Deploying and Using SAS Formats in Netezza 634Naming Conventions for Netezza 648Data Types for Netezza 648

    Chapter 23 SAS/ACCESS Interface to ODBC 653Introduction to SAS/ACCESS Interface to ODBC 654LIBNAME Statement Specifics for ODBC 656Data Set Options for ODBC 660SQL Pass-Through Facility Specifics for ODBC 662Autopartitioning Scheme for ODBC 666DBLOAD Procedure Specifics for ODBC 670Temporary Table Support for ODBC 672Passing SAS Functions to ODBC 674Passing Joins to ODBC 675Bulk Loading for ODBC 676Locking in the ODBC Interface 676Naming Conventions for ODBC 677Data Types for ODBC 678

    Chapter 24 SAS/ACCESS Interface to OLE DB 681Introduction to SAS/ACCESS Interface to OLE DB 681LIBNAME Statement Specifics for OLE DB 682Data Set Options for OLE DB 689SQL Pass-Through Facility Specifics for OLE DB 690

  • ix

    Temporary Table Support for OLE DB 695Passing SAS Functions to OLE DB 697Passing Joins to OLE DB 698Bulk Loading for OLE DB 699Locking in the OLE DB Interface 699Accessing OLE DB for OLAP Data 700Naming Conventions for OLE DB 703Data Types for OLE DB 704

    Chapter 25 SAS/ACCESS Interface to Oracle 707Introduction to SAS/ACCESS Interface to Oracle 708LIBNAME Statement Specifics for Oracle 708Data Set Options for Oracle 711SQL Pass-Through Facility Specifics for Oracle 713Autopartitioning Scheme for Oracle 715Temporary Table Support for Oracle 718ACCESS Procedure Specifics for Oracle 719DBLOAD Procedure Specifics for Oracle 721Maximizing Oracle Performance 723Passing SAS Functions to Oracle 723Passing Joins to Oracle 725Bulk Loading for Oracle 725In-Database Procedures in Oracle 727Locking in the Oracle Interface 728Naming Conventions for Oracle 729Data Types for Oracle 729

    Chapter 26 SAS/ACCESS Interface to Sybase 739Introduction to SAS/ACCESS Interface to Sybase 740LIBNAME Statement Specifics for Sybase 740Data Set Options for Sybase 743SQL Pass-Through Facility Specifics for Sybase 744Autopartitioning Scheme for Sybase 745Temporary Table Support for Sybase 747ACCESS Procedure Specifics for Sybase 748DBLOAD Procedure Specifics for Sybase 750Passing SAS Functions to Sybase 751Passing Joins to Sybase 753Reading Multiple Sybase Tables 753Locking in the Sybase Interface 754Naming Conventions for Sybase 755Data Types for Sybase 755Case Sensitivity in Sybase 761National Language Support for Sybase 762

    Chapter 27 SAS/ACCESS Interface to Sybase IQ 763

  • x

    Introduction to SAS/ACCESS Interface to Sybase IQ 763LIBNAME Statement Specifics for Sybase IQ 764Data Set Options for Sybase IQ 767SQL Pass-Through Facility Specifics for Sybase IQ 768Autopartitioning Scheme for Sybase IQ 770Passing SAS Functions to Sybase IQ 771Passing Joins to Sybase IQ 772Bulk Loading for Sybase IQ 773Locking in the Sybase IQ Interface 774Naming Conventions for Sybase IQ 775Data Types for Sybase IQ 776

    Chapter 28 SAS/ACCESS Interface to Teradata 781Introduction to SAS/ACCESS Interface to Teradata 783LIBNAME Statement Specifics for Teradata 784Data Set Options for Teradata 788SQL Pass-Through Facility Specifics for Teradata 790Autopartitioning Scheme for Teradata 792Temporary Table Support for Teradata 796Passing SAS Functions to Teradata 798Passing Joins to Teradata 800Maximizing Teradata Read Performance 800Maximizing Teradata Load Performance 804Teradata Processing Tips for SAS Users 812Deploying and Using SAS Formats in Teradata 816In-Database Procedures in Teradata 831Locking in the Teradata Interface 832Naming Conventions for Teradata 837Data Types for Teradata 838

    P A R T 4 Sample Code 845Chapter 29 Accessing DBMS Data with the LIBNAME Statement 847About the LIBNAME Statement Sample Code 847Creating SAS Data Sets from DBMS Data 848Using the SQL Procedure with DBMS Data 851Using Other SAS Procedures with DBMS Data 859Calculating Statistics from DBMS Data 864Selecting and Combining DBMS Data 865Joining DBMS and SAS Data 866

    Chapter 30 Accessing DBMS Data with the SQL Pass-Through Facility 867About the SQL Pass-Through Facility Sample Code 867Retrieving DBMS Data with a Pass-Through Query 867Combining an SQL View with a SAS Data Set 870Using a Pass-Through Query in a Subquery 871

  • xi

    Chapter 31 Sample Data for SAS/ACCESS for Relational Databases 875Introduction to the Sample Data 875Descriptions of the Sample Data 875

    P A R T 5 Converting SAS/ACCESS Descriptors to PROC SQL Views 879Chapter 32 The CV2VIEW Procedure 881Overview of the CV2VIEW Procedure 881Syntax: PROC CV2VIEW 882Examples: CV2VIEW Procedure 886

    P A R T 6 Appendixes 891Appendix 1 The ACCESS Procedure for Relational Databases 893Overview: ACCESS Procedure 893Syntax: ACCESS Procedure 895Using Descriptors with the ACCESS Procedure 907Examples: ACCESS Procedure 909

    Appendix 2 The DBLOAD Procedure for Relational Databases 911Overview: DBLOAD Procedure 911Syntax: DBLOAD Procedure 913Example: Append a Data Set to a DBMS Table 924

    Appendix 3 Recommended Reading 925Recommended Reading 925

    Glossary 927

    Index 933

  • xii

  • xiii

    Whats New

    OverviewSAS/ACCESS 9.2 for Relational Databases has these new features and enhancements: In the second maintenance release for SAS 9.2, SAS/ACCESS Interface to

    Greenplum on page xvi and SAS/ACCESS Interface to Sybase IQ on page xviiiare new. In the December 2009 release, SAS/ACCESS Interface to AsternCluster on page xiv is new.

    Pass-through support is available for database management systems (DBMSs) fornew or additional SAS functions. This support includes new or enhanced functionfor the SQL_FUNCTIONS= LIBNAME option, a new SQL_FUNCTIONS_COPY=LIBNAME option for specific DBMSs, and new or enhanced hyperbolic,trigonometric, and dynamic SQL dictionary functions. For more information, seethe SQL_FUNCTIONS= LIBNAME Option on page 186,SQL_FUNCTIONS_COPY= LIBNAME Option on page 189, and PassingFunctions to the DBMS Using PROC SQL on page 42.

    You can create temporary tables using DBMS-specific syntax with the newDBMSTEMP= LIBNAME option for most DBMSs. For more information, see theDBMSTEMP= LIBNAME Option on page 131.

    SAS/ACCESS supports additional hosts for existing DBMSs. For moreinformation, see Chapter 9, SAS/ACCESS Features by Host, on page 75.

    You can use the new SAS In-Database technology to generate a SAS_PUT()function that lets you execute PUT function calls inside Teradata, Netezza, andDB2 under UNIX. You can also reference the custom formats that you create byusing PROC FORMAT and most formats that SAS supplies. For more information,see Deploying and Using SAS Formats in Teradata on page 816, Deploying andUsing SAS Formats in Netezza on page 634, and .

    In the second maintenance release for SAS 9.2, you can use the new SASIn-Database technology to run some Base SAS and SAS/STAT procedures insideTeradata, DB2 under UNIX and PC Hosts, and Oracle. For more information, seeChapter 8, Overview of In-Database Procedures, on page 67.

    In the third maintenance release for SAS 9.2, three additional Base SASprocedures have been enhanced to run inside the database: REPORT, SORT, andTABULATE. Three additional SAS/STAT procedures have been enhanced to run

  • xiv Whats New

    inside the database: CORR, CANCORR, and FACTOR. In addition, the Base SASprocedures can be run now inside Oracle and DB2 UNIX and PC Hosts. For moreinformation, see Chapter 8, Overview of In-Database Procedures, on page 67.

    The second maintenance release for SAS 9.2 contains DocumentationEnhancements on page xx.

    All Supported SAS/ACCESS Interfaces to Relational DatabasesThese options are new. AUTHDOMAIN= LIBNAME option DBIDIRECTEXEC= system option, including DELETE statements brief trace capability (,,,db flag) on the SASTRACE= system option

    To boost performance when reading large tables, you can set the OBS= option to limitthe number of rows that the DBMS returns to SAS across the network.

    Implicit pass-through tries to reconstruct the textual representation of a SAS SQLquery in database SQL syntax. In the second maintenance release for SAS 9.2, implicitpass-through is significantly improved so that you can pass more SQL code down to thedatabase. These textualization improvements have been made.

    aliases for: inline views SQL views tables aliased expressions expressions that use the CALCULATED keyword SELECT, WHERE, HAVING, ON, GROUP BY, and ORDER BY clauses

    more deeply nested queries or queries involving multiple data sources PROC SQL and ANSI SQL syntax

    SAS/ACCESS Interface to Aster nClusterIn the December 2009 release for SAS 9.2, SAS/ACCESS Interface to Aster nCluster

    is a new database engine that runs on specific UNIX and Windows platforms.SAS/ACCESS Interface to Aster nCluster provides direct, transparent access to AsternCluster databases through LIBNAME statements and the SQL pass-through facility.You can use various LIBNAME statement options and data set options that theLIBNAME engine supports to control the data that is returned to SAS.

    For more information, see Chapter 14, SAS/ACCESS Interface to Aster nCluster, onpage 439 and SAS/ACCESS Interface to Aster nCluster: Supported Features on page75.

    In the third maintenance release for SAS 9.2, these options are new or enhanced: PARTITION_KEY= LIBNAME (new) and data set (enhanced) option

    SAS/ACCESS Interface to DB2 under UNIX and PC HostsThese options are new or enhanced. FETCH_IDENTITY= LIBNAME and data set options automatically calculated INSERTBUFF= and READBUFF= LIBNAME options for

    use with pass-through

  • Whats New xv

    SQLGENERATION= LIBNAME and system option (in the third maintenancerelease for SAS 9.2)

    These bulk-load data set options are new: BL_ALLOW_READ_ACCESS= BL_ALLOW_WRITE_ACCESS= BL_CPU_PARALLELISM= BL_DATA_BUFFER_SIZE= BL_DELETE_DATAFILE= BL_DISK_PARALLELISM= BL_EXCEPTION= BL_PORT_MAX= BL_PORT_MIN=

    BLOB and CLOB data types are new.In the third maintenance release for SAS 9.2, this new feature is available. You can use the new SAS In-Database technology to run these Base SAS

    procedures inside DB2 under UNIX and PC Hosts: FREQ RANK REPORT SORT SUMMARY/MEANS TABULATE

    These procedures dynamically generate SQL queries that reference DB2 SQLfunctions. Queries are processed and only the result set is returned to SAS for theremaining analysis.

    For more information, see Chapter 8, Overview of In-Database Procedures, onpage 67 and the specific procedure in the Base SAS Procedures Guide.

    SAS/ACCESS Interface to DB2 under z/OSThese options are new or enhanced. DB2CATALOG= system option support for multivolume SMS-managed and non-SMS-managed data sets through

    BL_DB2DATACLAS= , BL_DB2MGMTCLAS=, BL_DB2STORCLAS=, andBL_DB2UNITCOUNT= data set options

    DB2 parallelism through the DEGREE= data set option LOCATION= connection, LIBNAME, and data set options

    The BLOB and CLOB data types are new.In the third maintenance release for SAS 9.2, SAS/ACCESS Interface to DB2 under

    z/OS included many important overall enhancements, such as: significant performance improvements reduced overall memory consumption improved buffered reads improved bulk-loading capability improved error management, including more extensive tracing and the ability to

    retrieve multiple error messages for a single statement at once

  • xvi Whats New

    extended SQL function support dynamic SQL dictionary EXPLAIN functionality database read-only access support

    IBM z/OS is the successor to the IBM OS/390 (formerly MVS) operating system.SAS/ACCESS 9.1 and later for z/OS is supported on both OS/390 and z/OS operatingsystems. Throughout this document, any reference to z/OS also applies to OS/390unless otherwise stated.

    SAS/ACCESS Interface to GreenplumIn the October 2009 release for SAS 9.2, SAS/ACCESS Interface to Greenplum is a

    new database engine that runs on specific UNIX and Windows platforms. SAS/ACCESSInterface to Greenplum provides direct, transparent access to Greenplum databasesthrough LIBNAME statements and the SQL pass-through facility. You can use variousLIBNAME statement options and data set options that the LIBNAME engine supportsto control the data that is returned to SAS.

    For more information, see Chapter 17, SAS/ACCESS Interface to Greenplum, onpage 533 and SAS/ACCESS Interface to Greenplum: Supported Features on page 77.

    SAS/ACCESS Interface to HP NeoviewYou can use the new BULKEXTRACT= LIBNAME and data set options, as well as

    these new data set options for bulk loading and extracting: BL_BADDATA_FILE= BL_DATAFILE= BL_DELIMITER= BL_DISCARDS= BL_ERRORS= BL_DELETE_DATAFILE= BL_FAILEDDATA= BL_HOSTNAME= BL_NUM_ROW_SEPS= LIBNAME and data set options (in the third maintenance

    release for SAS 9.2) BL_PORT= BL_RETRIES= BL_ROWSETSIZE= BL_STREAMS= BL_SYNCHRONOUS= BL_SYSTEM= BL_TENACITY= BL_TRIGGER= BL_TRUNCATE= BL_USE_PIPE= BULKEXTRACT=

  • Whats New xvii

    BULKLOAD=

    SAS/ACCESS Interface to InformixThese items are new. AUTOCOMMIT= LIBNAME option GLOBAL and SHARED options for the CONNECTION= LIBNAME option DBSASTYPE= data set option DBDATASRC environmental variable DATEPART and TIMEPART SAS functions support for special characters in naming conventions

    SAS/ACCESS Interface to MySQLThe ESCAPE_BACKSLASH= data set and LIBNAME options are new.

    SAS/ACCESS Interface to NetezzaThe BULKUNLOAD= LIBNAME option is new.In the third maintenance release for SAS 9.2, you can specify a database other than

    SASLIB in which to publish the SAS_COMPILEUDF function. If you publish theSAS_COMPILEUDF function to a database other than SASLIB, you must specify thatdatabase in the new COMPILEDB argument for the %INDNZ_PUBLISH_FORMATSmacro.

    In the third maintenance release for SAS 9.2, the SAS_PUT( ) function supportsUNICODE (UTF8) encoding.

    In the June 2010 release, the SAS/ACCESS Interface to Netezza supports theNetezza TwinFin system. The new Netezza TwinFin system adds supports for sharedlibraries. The shared library technology makes the scoring functions more efficient androbust. In addition, the use of SFTP for file transfer during the format publishingprocess has been replaced with the Netezza External Table Interface.

    SAS/ACCESS Interface to ODBCThese items are new. LOGIN_TIMEOUT= LIBNAME option READBUFF= data set option, LIBNAME option, and pass-through support for

    improved performance

    SAS/ACCESS Interface to OLE DBThese items are new. GLOBAL and SHARED options for the CONNECTION= LIBNAME option BULKLOAD= data set option DBTYPE_GUID and DBTYPE_VARIANT input data types

  • xviii Whats New

    SAS/ACCESS Interface to OracleThese items are new. ADJUST_BYTE_SEMANTIC_COLUMN_LENGTHS=,

    ADJUST_NCHAR_COLUMN_LENGTHS=, DB_LENGTH_SEMANTICS_BYTE=,DBCLIENT_MAX_BYTES=, and DBSERVER_MAX_BYTES= LIBNAME optionsfor more flexible adjustment of column lengths with CHAR, NCHAR, VARCHAR,and NVARCHAR data types to match encoding on both database and client servers

    BL_DELETE_ONLY_DATAFILE= data set option GLOBAL and SHARED options for the CONNECTION= LIBNAME option OR_ENABLE_INTERRUPT= LIBNAME option BL_DEFAULT_DIR= data set option BL_USE_PIPE= data set option function and default value for SHOW_SYNONYMS LIBNAME option SQLGENERATION= LIBNAME and system option (in the third maintenance

    release for SAS 9.2) In the third maintenance release for SAS 9.2, you can use the new SAS

    In-Database technology feature to run these Base SAS procedures inside Oracle: FREQ RANK REPORT SORT SUMMARY/MEANS TABULATE

    These procedures dynamically generate SQL queries that reference Oracle SQLfunctions. Queries are processed and only the result set is returned to SAS for theremaining analysis.

    For more information, see Chapter 8, Overview of In-Database Procedures, onpage 67 and the specific procedure in the Base SAS Procedures Guide.

    SAS/ACCESS Interface to SybaseThese LIBNAME options are new or enhanced. GLOBAL and SHARED options for CONNECTION= SQL_FUNCTIONS= and SQL_FUNCTIONS_COPY= SQL_OJ_ANSI=

    Pass-through support is available for new or additional SAS functions, includinghyperbolic, trigonometric, and dynamic SQL dictionary functions.

    SAS/ACCESS Interface to Sybase IQIn the December 2009 release for SAS 9.2, SAS/ACCESS Interface to Sybase IQ is a

    new database engine that runs on specific UNIX and Windows platforms. SAS/ACCESSInterface to Sybase IQ provides direct, transparent access to Sybase IQ databasesthrough LIBNAME statements and the SQL pass-through facility. You can use various

  • Whats New xix

    LIBNAME statement options and data set options that the LIBNAME engine supportsto control the data that is returned to SAS.

    For more information, see Chapter 27, SAS/ACCESS Interface to Sybase IQ, onpage 763 and SAS/ACCESS Interface to Sybase IQ: Supported Features on page 84.

    SAS/ACCESS Interface to TeradataThese options are new or enhanced. BL_CONTROL= and BL_DATAFILE= data set options GLOBAL and SHARED options for the CONNECTION= LIBNAME option DBFMTIGNORE= system option for bypassing Teradata data type hints based on

    numeric formats for output processing (in the second maintenance release for SAS9.2)

    DBSASTYPE= data set option FASTEXPORT= LIBNAME options MODE= LIBNAME option (in the second maintenance release for SAS 9.2) MULTISTMT= LIBNAME and data set option QUERY_BAND= LIBNAME and data set options SQLGENERATION= LIBNAME and system option (in the second maintenance

    release for SAS 9.2) The Teradata Parallel Transporter (TPT) application programming interface (API)

    is now supported for loading and reading data using Teradata load, update,stream, and export drivers. This support includes these new options:

    TPT= LIBNAME and data set options TPT_APPL_PHASE= data set option TPT_BUFFER_SIZE= data set option TPT_CHECKPOINT= data set option TPT_DATA_ENCRYPTION= data set option TPT_ERROR_TABLE_1= data set option TPT_ERROR_TABLE_2= data set option TPT_LOG_TABLE= data set option TPT_MAX_SESSIONS= data set option TPT_MIN_SESSIONS= data set option TPT_PACK= data set option TPT_PACKMAXIMUM= data set option TPT_RESTART= data set option TPT_TRACE_LEVEL= data set option TPT_TRACE_LEVEL_INF= data set option TPT_TRACE_OUTPUT= data set option TPT_WORK_TABLE= data set option

    LDAP function for the USER= and PASSWORD= connection options in theLIBNAME statement

    You can use a new SAS formats publishing macro, %INDTD_PUBLISH_FORMATS,and a new system option, SQLMAPPUTTO, to generate a SAS_PUT() function thatenables you to execute PUT function calls inside the Teradata EDW. You can also

  • xx Whats New

    reference the custom formats that you create by using PROC FORMAT and most of theformats that SAS supplies.

    In the second maintenance release for SAS 9.2, this new feature is available. You can use the new SAS In-Database technology to run these Base SAS and

    SAS/STAT procedures inside the Teradata Enterprise Data Warehouse (EDW): FREQ PRINCOMP RANK REG SCORE SUMMARY/MEANS VARCLUS

    These procedures dynamically generate SQL queries that reference TeradataSQL functions and, in some cases, SAS functions that are deployed insideTeradata. Queries are processed and only the result set is returned to SAS for theremaining analysis.

    For more information, see Chapter 8, Overview of In-Database Procedures, onpage 67 and the specific procedure in either the Base SAS Procedures Guide or theSAS Analytics Accelerator for Teradata: Users Guide.

    In the third maintenance release for SAS 9.2, these procedures have been enhancedto run inside the Teradata EDW:

    CORR CANCORR FACTOR REPORT SORT TABULATE

    In the third maintenance release for SAS 9.2, the SAS_PUT( ) function supportsUNICODE (UCS2) encoding.

    Documentation EnhancementsIn addition to information about new and updated features, this edition of

    SAS/ACCESS for Relational Databases: Reference includes information about theseitems:

    BL_RETURN_WARNINGS_AS_ERRORS= data set option DB_ONE_CONNECT_PER_THREAD data set option for Oracle (in the third

    maintenance release for SAS 9.2) DBSERVER_MAX_BYTES= LIBNAME option for Oracle and Sybase SESSIONS= and LIBNAME and data set options for Teradata special queries for data sources and DBMS info for DB2 under UNIX and PC

    Hosts and ODBCSpecial Catalog Queries on page 664 significant performance improvement when you work with large tables by using

    the OBS= option to transmit a limited number of rows across the network the importance of choosing the degree of numeric precision that best suits your

    business needs

  • 1

    P A R T1

    Concepts

    Chapter 1. . . . . . . . . .Overview of SAS/ACCESS Interface to RelationalDatabases 3

    Chapter 2. . . . . . . . . .SAS Names and Support for DBMS Names 11

    Chapter 3. . . . . . . . . .Data Integrity and Security 25

    Chapter 4. . . . . . . . . .Performance Considerations 35

    Chapter 5. . . . . . . . . .Optimizing Your SQL Usage 41

    Chapter 6. . . . . . . . . .Threaded Reads 51

    Chapter 7. . . . . . . . . .How SAS/ACCESS Works 61

    Chapter 8. . . . . . . . . .Overview of In-Database Procedures 67

  • 2

  • 3

    C H A P T E R

    1Overview of SAS/ACCESSInterface to RelationalDatabases

    About This Document 3Methods for Accessing Relational Database Data 4Selecting a SAS/ACCESS Method 4

    Methods for Accessing DBMS Tables and Views 4SAS/ACCESS LIBNAME Statement Advantages

    4SQL Pass-Through Facility Advantages 5SAS/ACCESS Features for Common Tasks 5

    SAS Views of DBMS Data 6Choosing Your Degree of Numeric Precision 7

    Factors That Can Cause Calculation Differences 7Examples of Problems That Result in Numeric Imprecision 7

    Representing Data 7Rounding Data 8Displaying Data 8Selectively Extracting Data 8

    Your Options When Choosing the Degree of Precision That You Need 9References 10

    About This Document

    This document provides conceptual, reference, and usage information for theSAS/ACCESS interface to relational database management systems (DBMSs). Theinformation in this document applies generally to all relational DBMSs thatSAS/ACCESS software supports.

    Because availability and behavior of SAS/ACCESS features vary from one interfaceto another, you should use the general information in this document with theDBMS-specific information in reference section of this document for your SAS/ACCESSinterface.

    This document is intended for applications programmers and end users with theseskills:

    They are familiar with the basics of their DBMS and its SQL (Structured QueryLanguage).

    They know how to use their operating environment.

    They can use basic SAS commands and statements.

    Database administrators might also want to read this document to understand howto implement and administer a specific interface.

  • 4 Methods for Accessing Relational Database Data Chapter 1

    Methods for Accessing Relational Database DataSAS/ACCESS Interface to Relational Databases is a family of interfaceseach

    licensed separatelywith which you can interact with data in other vendor databasesfrom within SAS. SAS/ACCESS provides these methods for accessing relational DBMSdata.

    You can use the LIBNAME statement to assign SAS librefs to DBMS objects suchas schemas and databases. After you associate a database with a libref, you canuse a SAS two-level name to specify any table or view in the database. You canthen work with the table or view as you would with a SAS data set.

    You can use the SQL pass-through facility to interact with a data source using itsnative SQL syntax without leaving your SAS session. SQL statements are passeddirectly to the data source for processing.

    You can use ACCESS and DBLOAD procedures for indirect access to DBMS data.Although SAS still supports these procedures for database systems andenvironments on which they were available for SAS 6, they are no longer therecommended method for accessing DBMS data.

    See Selecting a SAS/ACCESS Method on page 4 for information about when to useeach method.

    Not all SAS/ACCESS interfaces support all of these features. To determine whichfeatures are available in your environment, see Introduction on page 75.

    Selecting a SAS/ACCESS Method

    Methods for Accessing DBMS Tables and ViewsIn SAS/ACCESS, you can often complete a task in several ways. For example, you

    can access DBMS tables and views by using the LIBNAME statement or the SQLpass-through facility. Before processing complex or data-intensive operations, you mightwant to test several methods first to determine the most efficient one for your particulartask.

    SAS/ACCESS LIBNAME Statement Advantages

    You should use the SAS/ACCESS LIBNAME statement for the fastest and mostdirect method of accessing your DBMS data except when you need to use SQL that isnot ANSI-standard. ANSI-standard SQL is required when you use the SAS/ACCESSlibrary engine in the SQL procedure. However, the SQL pass-through facility acceptsall SQL extensions that your DBMS provides.

    Here are the advantages of using the SAS/ACCESS LIBNAME statement. Significantly fewer lines of SAS code are required to perform operations on your

    DBMS. For example, a single LIBNAME statement establishes a connection toyour DBMS, lets you specify how data is processed, and lets you easily view yourDBMS tables in SAS.

    You do not need to know the SQL language of your DBMS to access andmanipulate data on your DBMS. You can use such SAS procedures as PROC SQL

  • Overview of SAS/ACCESS Interface to Relational Databases SAS/ACCESS Features for Common Tasks 5

    or DATA step programming on any libref that references DBMS data. You canread, insert, update, delete, and append data. You can also create and drop DBMStables by using SAS syntax.

    The LIBNAME statement gives you more control over DBMS operations such aslocking, spooling, and data type conversion through the use of LIBNAME and dataset options.

    The engine can optimize processing of joins and WHERE clauses by passing themdirectly to the DBMS, which takes advantage of the indexing and other processingcapabilities of your DBMS. For more information, see Overview of OptimizingYour SQL Usage on page 41.

    The engine can pass some functions directly to the DBMS for processing.

    SQL Pass-Through Facility AdvantagesHere are the advantages of using the SQL pass-through facility.

    You can use SQL pass-through facility statements so the DBMS can optimizequeries, particularly when you join tables. The DBMS optimizer can takeadvantage of indexes on DBMS columns to process a query more quickly andefficiently.

    SQL pass-through facility statements let the DBMS optimize queries when querieshave summary functions (such as AVG and COUNT), GROUP BY clauses, orcolumns that expressions create (such as the COMPUTED function). The DBMSoptimizer can use indexes on DBMS columns to process queries more rapidly.

    On some DBMSs, you can use SQL pass-through facility statements with SAS/AFapplications to handle transaction processing of DBMS data. Using a SAS/AFapplication gives you complete control of COMMIT and ROLLBACK transactions.SQL pass-through facility statements give you better access to DBMS return codes.

    The SQL pass-through facility accepts all extensions to ANSI SQL that yourDBMS provides.

    SAS/ACCESS Features for Common TasksHere is a list of tasks and the features that you can use to accomplish them.

    Table 1.1 SAS/ACCESS Features for Common Tasks

    Task SAS/ACCESS Features

    LIBNAME statement*

    SQL Pass-Through Facility

    Read DBMStables or views

    View descriptors**

    LIBNAME statement*

    DBLOAD procedure

    Create DBMSobjects, such astables

    SQL Pass-Through Facility EXECUTE statement

    LIBNAME statement*

    View descriptors**

    Update, delete,or insert rowsinto DBMStables SQL Pass-Through Facility EXECUTE statement

  • 6 SAS Views of DBMS Data Chapter 1

    Task SAS/ACCESS Features

    DBLOAD procedure with APPEND option

    LIBNAME statement and APPEND procedure*

    SQL Pass-Through Facility EXECUTE statement

    Append data toDBMS tables

    SQL Pass-Through Facility INSERT statement

    LIBNAME statement and SAS Explorer window*

    LIBNAME statement and DATASETS procedure*

    LIBNAME statement and CONTENTS procedure*

    List DBMStables

    LIBNAME statement and SQL procedure dictionary tables*

    LIBNAME statement and SQL procedure DROP TABLE statement*

    LIBNAME statement and DATASETS procedure DELETE statement*

    DBLOAD procedure with SQL DROP TABLE statement

    Delete DBMStables or views

    SQL Pass-Through Facility EXECUTE statement

    * LIBNAME statement refers to the SAS/ACCESS LIBNAME statement.** View descriptors refer to view descriptors that are created in the ACCESS procedure.

    SAS Views of DBMS DataSAS/ACCESS enables you to create a SAS view of data that exists in a relational

    database management system. A SAS data view defines a virtual data set that isnamed and stored for later use. A view contains no data, but rather describes data thatis stored elsewhere. There are three types of SAS data views:

    DATA step views are stored, compiled DATA step programs. SQL views are stored query expressions that read data values from their

    underlying files, which can include SAS data files, SAS/ACCESS views, DATA stepviews, other SQL views, or relational database data.

    SAS/ACCESS views (also called view descriptors) describe data that is stored inDBMS tables. This is no longer a recommended method for accessing relationalDBMS data. Use the CV2VIEW procedure to convert existing view descriptors intoSQL views.

    You can use all types of views as inputs into DATA steps and procedures. You canspecify views in queries as if they were tables. A view derives its data from the tablesor views that are listed in its FROM clause. The data accessed by a view is a subset orsuperset of the data in its underlying table(s) or view(s).

    You can use SQL views and SAS/ACCESS views to update their underlying data ifthe view is based on only one DBMS table or if it is based on a DBMS view that isbased on only one DBMS table and if the view has no calculated fields. You cannot useDATA step views to update the underlying data; you can use them only to read the data.

    Your options for creating a SAS view of DBMS data are determined by theSAS/ACCESS feature that you are using to access the DBMS data. This table lists therecommended methods for creating SAS views.

  • Overview of SAS/ACCESS Interface to Relational Databases Examples of Problems That Result in Numeric Imprecision 7

    Table 1.2 Creating SAS Views

    Feature You Use to Access DBMS Data SAS View Technology You Can Use

    SAS/ACCESS LIBNAME statement SQL view or DATA step view of the DBMS table

    SQL Pass-Through Facility SQL view with CONNECTION TO component

    Choosing Your Degree of Numeric Precision

    Factors That Can Cause Calculation DifferencesDifferent factors affect numeric precision. This issue is common for many people,

    including SAS users. Though computers and software can help, you are limited in howprecisely you can calculate, compare, and represent data. Therefore, only those peoplewho generate and use data can determine the exact degree of precision that suits theirenterprise needs.

    As you decide the degree of precision that you want, you need to consider that thesesystem factors can cause calculation differences:

    hardware limitations differences among operating systems different software or different versions of the same software different database management systems (DBMSs)

    These factors can also cause differences: the use of finite number sets to represent infinite real numbers how numbers are stored, because storage sizes can vary

    You also need to consider how conversions are performedon, between, or across anyof these system or calculation factors.

    Examples of Problems That Result in Numeric ImprecisionDepending on the degree of precision that you want, calculating the value of r can

    result in a tiny residual in a floating-point unit. When you compare the value of r to0.0, you might find that r0.0. The numbers are very close but not equal. This type ofdiscrepancy in results can stem from problems in representing, rounding, displaying,and selectively extracting data.

    Representing DataSome numbers can be represented exactly, but others cannot. As shown in this

    example, the number 10.25, which terminates in binary, can be represented exactly.

    data x;x=10.25;put x hex16.;

    run;

    The output from this DATA step is an exact number: 4024800000000000. However,the number 10.1 cannot be represented exactly, as this example shows.

  • 8 Examples of Problems That Result in Numeric Imprecision Chapter 1

    data x;x=10.1;put x hex16.;

    run;

    The output from this DATA step is an inexact number: 4024333333333333.

    Rounding DataAs this example shows, rounding errors can result from platform-specific differences.

    No solution exists for such situations.

    data x;x=10.1;put x hex16.;y=100000;newx=(x+y)-y;put newx hex16.;

    run;

    In Windows and Linux environments, the output from this DATA step is4024333333333333 (8/10-byte hardware double). In the Solaris x64 environment, theoutput is 4024333333334000 (8/8-byte hardware double).

    Displaying DataFor certain numbers such as x.5, the precision of displayed data depends on whether

    you round up or down. Low-precision formatting (rounding down) can produce differentresults on different platforms. In this example, the same high-precision (rounding up)result occurs for X=8.3, X=8.5, or X=hex16. However, a different result occurs for X=8.1because this number does not yield the same level of precision.

    data;x=input(C047DFFFFFFFFFFF, hex16.);put x= 8.1 x= 8.3 x= 8.5 x= hex16.;

    run;

    Here is the output under Windows or Linux (high-precision formatting).

    x=-47.8x=-47.750 x=-47.7500x=C047DFFFFFFFFFFF

    Here is the output under Solaris x64 (low-precision formatting).

    x=-47.7x=-47.750 x=-47.7500x=C047DFFFFFFFFFFF

    To fix the problem that this example illustrates, you must select a number that yieldsthe next precision levelin this case, 8.2.

    Selectively Extracting DataResults can also vary when you access data that is stored on one system by using a

    client on a different system. This example illustrates running a DATA step from aWindows client to access SAS data in the z/OS environment.

    data z(keep=x);x=5.2;

  • Overview of SAS/ACCESS Interface to Relational Databases Choosing the Degree of Precision That You Need 9

    output;y=1000;x=(x+y)-y; /*almost 5.2 */output;

    run;

    proc print data=z;run;

    Here is the output this DATA step produces.

    Obs x1 5.22 5.2

    The next example illustrates the output that you receive when you execute the DATAstep interactively under Windows or under z/OS.

    data z1;set z(where=(x=5.2));

    run;

    Here is the corresponding z/OS output.

    NOTE: There were 1 observations read from the data set WORK.Z.WHERE x=5.2;NOTE: The data set WORK.Z1 has 1 observations and 1 variables.The DATA statement used 0.00 CPU seconds and 14476K.

    In the above example, the expected count was not returned correctly under z/OSbecause the imperfection of the data and finite precision are not taken into account.You cannot use equality to obtain a correct count because it does not include thealmost 5.2 cases in that count. To obtain the correct results under z/OS, you must runthis DATA step:

    data z1;set z(where=(compfuzz(x,5.2,1e-10)=0));

    run;

    Here is the z/OS output from this DATA step.

    NOTE: There were 2 observations read from the data set WORK.Z.WHERE COMPFUZZ(x, 5.2, 1E-10)=0;NOTE: The data set WORK.Z1 has 2 observations and 1 variables.

    Your Options When Choosing the Degree of Precision That You NeedAfter you determine the degree of precision that your enterprise needs, you can refine

    your software. You can use macros, sensitivity analyses, or fuzzy comparisons such asextractions or filters to extract data from databases or from different versions of SAS.

    If you are running SAS 9.2, use the COMPFUZZ (fuzzy comparison) function.Otherwise, use this macro.

    /*****************************************************************************//* This macro defines an EQFUZZ operator. The subsequent DATA step shows *//* how to use this operator to test for equality within a certain tolerance. *//*****************************************************************************/%macro eqfuzz(var1, var2, fuzz=1e-12);abs((&var1 - &var2) / &var1) < &fuzz

  • 10 References Chapter 1

    %mend;

    data _null_;x=0;y=1;do i=1 to 10;

    x+0.1;end;if x=y then put x exactly equal to y;else if %eqfuzz(x,y) then put x close to y;else put x nowhere close to y;

    run;

    When you read numbers in from an external DBMS that supports precision beyond15 digits, you can lose that precision. You cannot do anything about this for existingdatabases. However, when you design new databases, you can set constraints to limitprecision to about 15 digits or you can select a numeric DBMS data type to match thenumeric SAS data type. For example, select the BINARY_DOUBLE type in Oracle(precise up to 15 digits) instead of the NUMBER type (precise up to 38 digits).

    When you read numbers in from an external DBMS for noncomputational purposes,use the DBSASTYPE= data set option, as shown in this example.

    libname ora oracle user=scott password=tiger path=path;data sasdata;

    set ora.catalina2( dbsastype= ( c1=char(20)) ) ;run;

    This option retrieves numbers as character strings and preserves precision beyond 15digits. For details, see the DBSASTYPE= data set option.

    ReferencesSee these resources for more detail about numeric precision, including variables that

    can affect precision.

    The Aggregate. 2008. "Numerical Precision, Accuracy, and Range." Aggregate.Org:Unbridled Computing. Lexington, KY: University of Kentucky. Available http://aggregate.org/NPAR.

    IEEE. 2008. IEEE 754: Standard for Binary Floating-Point Arithmetic. Availablehttp://grouper.ieee.org/groups/754/index.html. This standard defines 32-bit and64-bit floating-point representations and computational results.

    SAS Institute Inc. 2007. TS-230. Dealing with Numeric Representation Error in SASApplications. Cary, NC: SAS Institute Inc. Available http://support.sas.com/techsup/technote/ts230.html.

    SAS Institute Inc. 2007. TS-654. Numeric Precision 101. Cary, NC: SAS InstituteInc. Available http://support.sas.com/techsup/technote/ts654.pdf. This document isan overview of numeric precision and how it is represented in SAS applications.

  • 11

    C H A P T E R

    2SAS Names and Support forDBMS Names

    Introduction to SAS/ACCESS Naming 11SAS Naming Conventions 12

    Length of Name 12Case Sensitivity 12SAS Name Literals 13

    SAS/ACCESS Default Naming Behaviors 13Modification and Truncation 13ACCESS Procedure 13DBLOAD Procedure 14

    Renaming DBMS Data 14Renaming SAS/ACCESS Tables 14Renaming SAS/ACCESS Columns 14Renaming SAS/ACCESS Variables 14

    Options That Affect SAS/ACCESS Naming Behavior 15Naming Behavior When Retrieving DBMS Data 15Naming Behavior When Creating DBMS Objects 16SAS/ACCESS Naming Examples 17

    Replacing Unsupported Characters 17Preserving Column Names 18Preserving Table Names 19Using DQUOTE=ANSI 20Using Name Literals 22Using DBMS Data to Create a DBMS Table 22Using a SAS Data Set to Create a DBMS Table 23

    Introduction to SAS/ACCESS Naming

    Because some DBMSs allow case-sensitive names and names with special characters,show special consideration when you use names of such DBMS objects as tables andcolumns with SAS/ACCESS features. This section presents SAS/ACCESS namingconventions, default naming behaviors, options that can modify naming behavior, andusage examples. See the documentation for your SAS/ACCESS interface for informationabout how SAS handles your DBMS names.

  • 12 SAS Naming Conventions Chapter 2

    SAS Naming Conventions

    Length of NameSAS naming conventions allow long names for SAS data sets and SAS variables. For

    example, MYDB.TEMP_EMPLOYEES_QTR4_2000 is a valid two-level SAS name for adata set.

    The names of the following SAS language elements can be up to 32 characters inlength:

    members of SAS libraries, including SAS data sets, data views, catalogs, catalogentries, and indexes

    variables in a SAS data set

    macros and macro variables

    The following SAS language elements have a maximum length of eight characters:

    librefs and filerefs

    SAS engine names

    names of SAS/ACCESS access descriptors and view descriptors

    variable names in SAS/ACCESS access descriptors and view descriptors

    For a complete description of SAS naming conventions, see the SAS LanguageReference: Dictionary.

    Case SensitivityWhen SAS encounters mixed-case or case-sensitive names in SAS code, SAS stores

    and displays the names as they are specified. If the SAS variables, Flight and dates,are defined in mixed casefor example,

    input Flight $3. +3 dates date9.;

    then SAS displays the variable names as defined. Note how the column headingsappear as defined:

    Output 2.1 Mixed-Case Names Displayed in Output

    SAS System

    Obs Flight dates

    1 114 01MAR20002 202 01MAR20003 204 01MAR2000

    Although SAS stores variable names as they are defined, it recognizes variables forprocessing without regard to case. For example, SAS processes these variables asFLIGHT and DATES. Likewise, renaming the Flight variable to "flight" or "FLIGHT"would result in the same processing.

  • SAS Names and Support for DBMS Names ACCESS Procedure 13

    SAS Name LiteralsA SAS name literal is a name token that is expressed as a quoted string, followed by

    the letter n. Name literals enable you to use special characters or blanks that are nototherwise allowed in SAS names when you specify a SAS data set or variable. Nameliterals are especially useful for expressing database column and tables names thatcontain special characters.

    Here are two examples of name literals:

    data mydblib.My Staff Tablen;

    data Budget_for_1999;input $ Amount Budgetedn Amount Spentn;

    Name literals are subject to certain restrictions. You can use a name literal only for SAS variable and data set names, statement

    labels, and DBMS column and table names. You can use name literals only in a DATA step or in the SQL procedure. If a name literal contains any characters that are not allowed when

    VALIDVARNAME=V7, then you must set the system option toVALIDVARNAME=ANY. For details about using the VALIDVARNAME= systemoption, see VALIDVARNAME= System Option on page 423.

    SAS/ACCESS Default Naming Behaviors

    Modification and TruncationWhen SAS/ACCESS reads DBMS column names that contain characters that are not

    standard in SAS names, the default behavior is to replace an unsupported characterwith an underscore (_). For example, the DBMS column name Amount Budgeted$becomes the SAS variable name Amount_Budgeted_.

    Note: Nonstandard names include those with blank spaces or special characters(such as @, #, %) that are not allowed in SAS names.

    When SAS/ACCESS encounters a DBMS name that exceeds 32 characters, ittruncates the name.

    After it has modified or truncated a DBMS column name, SAS appends a number tothe variable name, if necessary, to preserve uniqueness. For example, DBMS columnnames MY$DEPT, My$Dept, and my$dept become SAS variable names MY_DEPT,MY_Dept0, and my_dept1.

    ACCESS ProcedureIf you attempt to use long names in the ACCESS procedure, you get an error

    message advising you that long names are not supported. Long member names, such asaccess descriptor and view descriptor names, are truncated to eight characters. LongDBMS column names are truncated to 8-character SAS variable names within the SASaccess descriptor. You can use the RENAME statement to specify 8-character SASvariable names, or you can accept the default truncated SAS variable names that areassigned by the ACCESS procedure.

  • 14 DBLOAD Procedure Chapter 2

    The ACCESS procedure converts DBMS object names to uppercase characters unlessthey are enclosed in quotation marks. Any DBMS objects that are given lowercasenames when they are created, or whose names contain special or national characters,must be enclosed in quotation marks.

    DBLOAD ProcedureYou can use long member names, such as the name of a SAS data set that you want

    to load into a DBMS table, in the DBLOAD procedure DATA= option. However, if youattempt to use long SAS variable names, you get an error message advising you thatlong variable names are not supported in the DBLOAD procedure. You can use theRENAME statement to rename the 8-character SAS variable names to long DBMScolumn names when you load the data into a DBMS table. You can also use the SASdata set option RENAME to rename the columns after they are loaded into the DBMS.

    Most DBLOAD procedure statements convert lowercase characters in user-specifiedvalues and default values to uppercase. If your host or database is case sensitive andyou want to specify a value that includes lowercase alphabetic characters (for example,a user ID or password), enclose the entire value in quotation marks. You must also putquotation marks around any value that contains special characters or nationalcharacters.

    The only exception is the DBLOAD SQL statement. The DBLOAD SQL statement ispassed to the DBMS exactly as you enter it with case preserved.

    Renaming DBMS Data

    Renaming SAS/ACCESS TablesYou can rename DBMS tables and views using the CHANGE statement, as shown in

    this example:

    proc datasets lib=x;change oldtable=newtable;

    quit;

    You can rename tables using this method for all SAS/ACCESS engines. However, ifyou change a table name, any view that depends on that table no longer works unlessthe view references the new table name.

    Renaming SAS/ACCESS ColumnsYou can use the RENAME statement to rename the 8-character default SAS variable

    names to long DBMS column names when you load the data into a DBMS table. Youcan also use the SAS data set option RENAME= to rename the columns after they areloaded into the DBMS.

    Renaming SAS/ACCESS VariablesYou can use the RENAME statement to specify 8-character SAS variable names such

    as access descriptors and view descriptors.

  • SAS Names and Support for DBMS Names Naming Behavior When Retrieving DBMS Data 15

    Options That Affect SAS/ACCESS Naming BehaviorTo change how SAS handles case-sensitive or nonstandard DBMS table and column

    names, specify one or more of the following options.

    PRESERVE_COL_NAMES=YESis a SAS/ACCESS LIBNAME and data set option that applies only to creatingDBMS tables. When set to YES, this option preserves spaces, special characters,and mixed case in DBMS column names. See PRESERVE_COL_NAMES=LIBNAME Option on page 166 for more information about this option.

    PRESERVE_TAB_NAMES=YESis a SAS/ACCESS LIBNAME option. When set to YES, this option preservesblank spaces, special characters, and mixed case in DBMS table names. SeePRESERVE_TAB_NAMES= LIBNAME Option on page 168 for more informationabout this option.

    Note: Specify the alias PRESERVE_NAMES=YES | NO if you plan to specifyboth the PRESERVE_COL_NAMES= and PRESERVE_TAB_NAMES= options inyour LIBNAME statement. Using this alias saves time when you are coding.

    DQUOTE=ANSIis a PROC SQL option. This option specifies whether PROC SQL treats valueswithin double quotation marks as a character string or as a column name or tablename. When you specify DQUOTE=ANSI, your SAS code can refer to DBMSnames that contain characters and spaces that are not allowed by SAS namingconventions. Specifying DQUOTE=ANSI enables you to preserve specialcharacters in table and column names in your SQL statements by enclosing thenames in double quotation marks.

    To preserve table names, you must also specify PRESERVE_TAB_NAMES=YES.To preserve column names when you create a table, you must also specifyPRESERVE_COL_NAMES=YES.

    VALIDVARNAME=ANYis a global system option that can override the SAS naming conventions. SeeVALIDVARNAME= System Option on page 423 for information about this option.

    The availability of these options and their default settings are DBMS-specific, so see theSAS/ACCESS documentation for your DBMS to learn how the SAS/ACCESS engine foryour DBMS processes names.

    Naming Behavior When Retrieving DBMS DataThe following two tables illustrate how SAS/ACCESS processes DBMS names when

    retrieving data from a DBMS. This information applies generally to all interfaces. Insome cases, however, it is not necessary to specify these options because the optiondefault values are DBMS-specific. See the documentation for your SAS/ACCESSinterface for details.

  • 16 Naming Behavior When Creating DBMS Objects Chapter 2

    Table 2.1 DBMS Column Names to SAS Variable Names When Reading DBMS Data

    DBMS Column Name Desired SAS Variable Name Options

    Case-sensitive DBMS columnname, such as Flight

    Case-sensitive SAS variable name,such as Flight

    No options are necessary

    DBMS column name withcharacters that are not valid inSAS names, such as My$Flight

    Case-sensitive SAS variable namewhere an underscore replaces theinvalid characters, such asMy_Flight

    No options are necessary

    DBMS column name withcharacters that are not valid inSAS names, such as My$Flight

    Nonstandard, case-sensitive SASvariable name, such as My$Flight

    PROC SQL DQUOTE=ANSI or, ina DATA or PROC step, use a SASname literal such as My$Flightnand VALIDVARNAME=ANY

    Table 2.2 DBMS Table Names to SAS Data Set Names When Reading DBMS Data

    DBMS Table Name Desired SAS Data Set Name Options

    Default DBMS table name, such asSTAFF

    Default SAS data set or membername (uppercase), such as STAFF

    PRESERVE_TAB_NAMES=NO

    Case-sensitive DBMS table name,such as Staff

    Case-sensitive SAS data set, suchas Staff

    PRESERVE_TAB_NAMES=YES

    DBMS table name with charactersthat are not valid in SAS names,such as All$Staff

    Nonstandard, case-sensitive SASdata set name, such as All$Staff

    PROC SQLDQUOTE=ANSI andPRESERVE_TAB_NAMES=YES or,in a DATA step or PROC, use aSAS name literal such asAll$Staffn andPRESERVE_TAB_NAMES=YES

    Naming Behavior When Creating DBMS ObjectsThe following two tables illustrate how SAS/ACCESS handles variable names when

    creating DBMS objects such as tables and views. This information applies generally toall interfaces. In some cases, however, it is not necessary to specify these optionsbecause the option default values are DBMS-specific. See the documentation for yourDBMS for details.

  • SAS Names and Support for DBMS Names Replacing Unsupported Characters 17

    Table 2.3 SAS Variable Names to DBMS Column Names When Creating Tables

    SAS Variable Name as Input Desired DBMS Column Name Options

    Any SAS variable name, such asMiles

    Default DBMS column name(normalized to follow the DBMSsnaming conventions), such as MILES

    PRESERVE_COL_NAMES=NO

    A case-sensitive SAS variablename, such as Miles

    Case-sensitive DBMS column name,such as Miles

    PRESERVE_COL_NAMES=YES

    A SAS variable name withcharacters that are not valid in anormalized SAS name, such asMiles-to-Go

    Case-sensitive DBMS column namethat matches the SAS name, such asMiles-to-Go

    PROC SQL DQUOTE=ANSI andPRESERVE_COL_NAMES=YESor, in a DATA or PROC step, use aSAS name literal andPRESERVE_COL_NAMES=YESand VALIDVARNAME=ANY

    Table 2.4 SAS Data Set Names to DBMS Table Names

    SAS Data Set Name as Input Desired DBMS Table Name Options

    Any SAS data set name, such asPayroll

    Default DBMS table name(normalized to follow the DBMSsnaming conventions), such asPAYROLL

    PRESERVE_TAB_NAMES=NO

    Case-sensitive SAS data set name,such as Payroll

    Case-sensitive DBMS table name,such as Payroll

    PRESERVE_TAB_NAMES=YES

    Case-sensitive SAS data set namewith characters that are not validin a normalized SAS name, such asPayroll-for-QC

    Case-sensitive DBMS table namethat matches the SAS name, suchas Payroll-for-QC

    PROC SQL DQUOTE=ANSI andPRESERVE_TAB_NAMES=YES or,in a DATA or PROC step, use aSAS name literal andPRESERVE_TAB_NAMES=YES

    SAS/ACCESS Naming Examples

    Replacing Unsupported CharactersIn the following example, a view, myview, is created from the Oracle table, mytable.

    proc sql;connect to oracle (user=testuser password=testpass);create view myview as

    select * from connection to oracle(select "Amount Budgeted$", "Amount Spent$"

    from mytable);quit;

    proc contents data=myview;

  • 18 Preserving Column Names Chapter 2

    run;

    In the output produced by PROC CONTENTS, the Oracle column names (that wereprocessed by the SQL view of MYTABLE) are renamed to different SAS variable names:Amount Budgeted$ becomes Amount_Budgeted_ and Amount Spent$ becomesAmount_Spent_.

    Preserving Column Names

    The following example uses the Oracle table, PAYROLL, to create a new Oracle table,PAY1, and then prints the table. Both the PRESERVE_COL_NAMES=YES and thePROC SQL DQUOTE=ANSI options are used to preserve the case and nonstandardcharacters in the column names. You do not need to quote the column aliases in orderto preserve the mixed case. You only need double quotation marks when the columnname has nonstandard characters or blanks.

    By default, most SAS/ACCESS interfaces use DBMS-specific rules to set the case oftable and column names. Therefore, even though the new pay1 Oracle table name iscreated in lowercase in this example, Oracle stores the name in uppercase as PAY1. Ifyou want the table name to be stored as "pay1", you must setPRESERVE_TAB_NAMES=NO.

    options linesize=120 pagesize=60 nodate;

    libname mydblib oracle user=testuser password=testpass path=ora8_servrschema=hrdept preserve_col_names=yes;

    proc sql dquote=ansi;create table mydblib.pay1 as

    select idnum as "ID #", sex, jobcode, salary,birth as BirthDate, hired as HiredDate

    from mydblib.payrollorder by birth;

    title "Payroll Table with Revised Column Names";select * from mydblib.pay1;quit;

    SAS recognizes the JOBCODE, SEX, and SALARY column names, whether youspecify them in your SAS code as lowercase, mixed case, or uppercase. In the Oracletable, PAYROLL, the SEX, JOBCODE, and SALARY columns were created inuppercase. They therefore retain this case in the new table unless you rename them.Here is partial output from the example:

    Output 2.2 DBMS Table Created with Nonstandard and Standard Column Names

    Payroll Table with Revised Column Names

    ID # SEX JOBCODE SALARY BirthDate HiredDate------------------------------------------------------------------------1118 M PT3 11379 16JAN1944:00:00:00 18DEC1980:00:00:001065 M ME2 35090 26JAN1944:00:00:00 07JAN1987:00:00:001409 M ME3 41551 19APR1950:00:00:00 22OCT1981:00:00:001401 M TA3 38822 13DEC1950:00:00:00 17NOV1985:00:00:001890 M PT2 91908 20JUL1951:00:00:00 25NOV1979:00:00:00

  • SAS Names and Support for DBMS Names Preserving Table Names 19

    Preserving Table NamesThe following example uses PROC PRINT to print the DBMS table PAYROLL. The

    DBMS table was created in uppercase and since PRESERVE_TAB_NAMES=YES, thetable name must be specified in uppercase. (If you set thePRESERVE_TAB_NAMES=NO, you can specify the DBMS table name in lowercase.) Apartial output follows the example.

    options nodate linesize=64;libname mydblib oracle user=testuser password=testpass

    path=ora8_servr preserve_tab_names=yes;

    proc print data=mydblib.PAYROLL;title PAYROLL Table;

    run;

    Output 2.3 DBMS Table with a Case-Sensitive Name

    PAYROLL TableObs IDNUM SEX JOBCODE SALARY BIRTH1 1919 M TA2 34376 12SEP1960:00:00:002 1653 F ME2 35108 15OCT1964:00:00:003 1400 M ME1 29769 05NOV1967:00:00:004 1350 F FA3 32886 31AUG1965:00:00:005 1401 M TA3 38822 13DEC1950:00:00:00

    The following example submits a SAS/ACCESS LIBNAME statement and then opensthe SAS Explorer window, which lists the Oracle tables and views that are referencedby the MYDBLIB libref. Notice that 16 members are listed and that all of the membernames are in the case (initial capitalization) that is set by the Explorer window. Thetable names are capitalized because PRESERVE_TAB_NAMES= defaulted to NO.

    libname mydblib oracle user=testuser pass=testpass;

    Display 2.1 SAS Explorer Window Listing DBMS Objects

  • 20 Using DQUOTE=ANSI Chapter 2

    If you submit a SAS/ACCESS LIBNAME statement withPRESERVE_TAB_NAMES=YES and then open the SAS Explorer window, you see adifferent listing of the Oracle tables and views that the MYDBLIB libref references.

    libname mydblib oracle user=testuser password=testpasspreserve_tab_names=yes;

    Display 2.2 SAS Explorer Window Listing Case-Sensitive DBMS Objects

    Notice that there are 18 members listed, including one that is in lowercase and one thathas a name separated by a blank space. Because PRESERVE_TAB_NAMES=YES, SASdisplays the tables names in the exact case in which they were created.

    Using DQUOTE=ANSIThe following example creates a DBMS table with a blank space in its name. Double

    quotation marks are used to specify the table name, International Delays. Both of thepreserve names LIBNAME options are also set by using the aliasPRESERVE_NAMES=. Because PRESERVE_NAMES=YES, the schema airport is nowcase sensitive for Oracle.

    options linesize=64 nodate;

    libname mydblib oracle user=testuser password=testpass path=airdataschema=airport preserve_names=yes;

    proc sql dquote=ansi;create table mydblib."International Delays" as

    select int.flight as "FLIGHT NUMBER", int.dates,del.orig as ORIGIN,int.dest as DESTINATION, del.delay

    from mydblib.INTERNAT as int,mydblib.DELAY as del

    where int.dest=del.dest and int.dest=LON;quit;

    proc sql dquote=ansi outobs=10;

  • SAS Names and Support for DBMS Names Using DQUOTE=ANSI 21

    title "International Delays";select * from mydblib."International Delays";

    Notice that you use single quotation marks to specify the data value for London(int.dest=LON) in the WHERE clause. Because of the preserve name LIBNAMEoptions, using double quotation marks would cause SAS to interpret this data value asa column name.

    Output 2.4 DBMS Table with Nonstandard Column Names

    International Delays

    FLIGHTNUMBER DATES ORIGIN DESTINATION DELAY-----------------------------------------------------------219 01MAR1998:00:00:00 LGA LON 18219 02MAR1998:00:00:00 LGA LON 18219 03MAR1998:00:00:00 LGA LON 18219 04MAR1998:00:00:00 LGA LON 18219 05MAR1998:00:00:00 LGA LON 18219 06MAR1998:00:00:00 LGA LON 18219 07MAR1998:00:00:00 LGA LON 18219 01MAR1998:00:00:00 LGA LON 18219 02MAR1998:00:00:00 LGA LON 18219 03MAR1998:00:00:00 LGA LON 18

    If you query a DBMS table and use a label to change the FLIGHT NUMBER columnname to a standard SAS name (Flight_Number), a label (enclosed in single quotationmarks) changes the name only in the output. Because this column name and the tablename, International Delays, each have a space in their names, you have to enclose thenames in double quotation marks. A partial output follows the example.

    options linesize=64 nodate;

    libname mydblib oracle user=testuser password=testpass path=airdataschema=airport preserve_names=yes;

    proc sql dquote=ansi outobs=5;title "Query from International Delays";

    select "FLIGHT NUMBER" label=Flight_Number, dates, delayfrom mydblib."International Delays";

    Output 2.5 Query Renaming a Nonstandard Column to a Standard SAS Name

    Query from International Delays

    Flight_Number DATES DELAY--------------------------------------219 01MAR1998:00:00:00 18219 02MAR1998:00:00:00 18219 03MAR1998:00:00:00 18219 04MAR1998:00:00:00 18219 05MAR1998:00:00:00 18

    You can preserve special characters by specifying DQUOTE=ANSI and using doublequotation marks around the SAS names in your SELECT statement.

  • 22 Using Name Literals Chapter 2

    proc sql dquote=ansi;connect to oracle (user=testuser password=testpass);create view myview asselect "Amount Budgeted$", "Amount Spent$"from connection to oracle

    (select "Amount Budgeted$", "Amount Spent$"from mytable);

    quit;proc contents data=myview;run;

    Output from this example would show that Amount Budgeted$ remains AmountBudgeted$ and Amount Spent$ remains Amount Spent$.

    Using Name LiteralsThe following example creates a table using name literals. You must specify the SAS

    option VALIDVARNAME=ANY in order to use name literals. Use PROC SQL to printthe new DBMS table because name literals work only with PROC SQL and the DATAstep. PRESERVE_COLUMN_NAMES=YES is required only because the table is beingcreated with nonstandard SAS column names.

    options ls=64 validvarname=any nodate;

    libname mydblib oracle user=testuser password=testpass path=ora8servrpreserve_col_names=yes preserve_tab_names=yes ;

    data mydblib.Sample Tablen;EmpID#n=12345;Lname=Chen;Salary in $n=63000;

    proc sql;title "Sample Table";select * from mydblib.Sample Tablen;

    Output 2.6 DBMS Table to Test Column Names

    Sample Table

    SalaryEmpID# Lname in $

    -------------------------12345 Chen 63000

    Using DBMS Data to Create a DBMS TableThe following example uses PROC SQL to create a DBMS table based on data from

    other DBMS tables. You preserve the case sensitivity of the aliased column names byusing PRESERVE_COL_NAMES=YES. A partial output is displayed after the code.

    libname mydblib oracle user=testuser password=testpasspath=hrdata99 schema=personnel preserve_col_names=yes;

  • SAS Names and Support for DBMS Names Using a SAS Data Set to Create a DBMS Table 23

    proc sql;create table mydblib.gtforty as

    select lname as LAST_NAME,fname as FIRST_NAME,salary as ANNUAL_SALARY

    from mydblib.staff a,mydblib.payroll b

    where (a.idnum eq b.idnum) and(salary gt 40000)

    order by lname;

    proc print noobs;title Employees with Salaries over $40,000;

    run;

    Output 2.7 Updating DBMS Data

    Employees with Salaries over $40,000

    ANNUAL_LAST_NAME FIRST_NAME SALARY

    BANADYGA JUSTIN 88606BAREFOOT JOSEPH 43025BRADY CHRISTINE 68767BRANCACCIO JOSEPH 66517CARTER-COHEN KAREN 40260CASTON FRANKLIN 41690COHEN LEE 91376FERNANDEZ KATRINA 51081

    Using a SAS Data Set to Create a DBMS Table

    The following example uses a SAS DATA step to create a DBMS table,College-Hires-1999, from a temporary SAS data set that has case-sensitive names. Itcreates the temporary data set and then defines the LIBNAME statement. Because ituses a DATA step to create the DBMS table, it must specify the table name as a nameliteral and specify the PRESERVE_TAB_NAMES= and PRESERVE_COL_NAMES=options (in this case, by using the alias PRESERVE_NAMES=).

    options validvarname=any nodate;

    data College_Hires_1999;input IDnum $4. +3 Lastname $11. +2

    Firstname $10. +2 City $15. +2State $2.;

    datalines;3413 Schwartz Robert New Canaan CT3523 Janssen Heike Stamford CT3565 Gomez Luis Darien CT;

    libname mydblib oracle user=testuser password=testpasspath=hrdata99 schema=hrdept preserve_names=yes;

  • 24 Using a SAS Data Set to Create a DBMS Table Chapter 2

    data mydblib.College-Hires-1999n;set College_Hires_1999;

    proc print;title College Hires in 1999;

    run;

    Output 2.8 DBMS Table with Case-Sensitive Table and Column Names

    College Hires in 1999

    Obs IDnum Lastname Firstname City State

    1 3413 Schwartz Robert New Canaan CT2 3523 Janssen Heike Stamford CT3 3565 Gomez Luis Darien CT

  • 25

    C H A P T E R

    3Data Integrity and Security

    Introduction to Data Integrity and Security 25DBMS Security 25

    Privileges 25Triggers 26

    SAS Security 26Securing Data 26Assigning SAS Passwords 26Protecting Connection Information 28Extracting DBMS Data to a SAS Data Set 28Defining Views and Schemas 29Controlling DBMS Connections 29Locking, Transactions, and Currency Control 30Customizing DBMS Connect and Disconnect Exits 31

    Potential Result Set Differences When Processing Null Data 31

    Introduction to Data Integrity and Security

    This section briefly describes DBMS security issues and then presents measures youcan take on the SAS side of the interface to help protect DBMS data from accidentalupdate or deletion. This section also provides information about how SAS handles nullvalues that help you achieve consistent results.

    DBMS Security

    Privileges

    The database administrator controls who has privileges to access or update DBMSobjects. This person also controls who can create objects, and creators of the objectscontrol who can access the objects. A user cannot use DBMS facilities to access DBMSobjects through SAS/ACCESS software unless the user has the appropriate DBMSprivileges or authority on those objects. You can grant privileges on the DBMS side byusing the SQL pass-through facility to EXECUTE an SQL statement, or by issuing aGRANT statement from the DBLOAD procedure SQL statement.

  • 26 Triggers Chapter 3

    You should give users only the privileges on the DBMS that they must have.Privileges are granted on whole tables or views. You must explicitly grant to users theprivileges on the DBMS tables or views that underlie a view so they can use that view.

    See your DBMS documentation for more information about ensuring security on theDBMS side of the interface.

    TriggersIf your DBMS supports triggers, you can use them to enforce security authorizations

    or business-specific security considerations. When and how triggers are executed isdetermined by when the SQL statement is executed and how often the trigger isexecuted. Triggers can be executed before an SQL statement is executed, after an SQLstatement is executed, or for each row of an SQL statement. Also, triggers can bedefined for DELETE, INSERT, and UPDATE statement execution.

    Enabling triggers can provide more specific security for delete, insert, and updateoperations. SAS/ACCESS abides by all constraints and actions that are specified by atrigger. For more information, see the documentation for your DBMS.

    SAS Security

    Securing DataSAS preserves the data security provided by your DBMS and operating system;

    SAS/ACCESS does not override the security of your DBMS. To secure DBMS data fromaccidental update or deletion, you can take steps on the SAS side of the interface suchas the following:

    specifying the SAS/ACCESS LIBNAME option DBPROMPT= to avoid savingconnection information in your code

    creating SQL views and protecting them from unauthorized access by applyingpasswords.

    These and other approaches are discussed in detail in the following sections.

    Assigning SAS PasswordsBy using SAS passwords, you can protect SQL views, SAS data sets, and descriptor

    files from unauthorized access. The following table summarizes the levels of protectionthat SAS passwords provide. Note that you can assign multiple levels of protection.

  • Data Integrity and Security Assigning SAS Passwords 27

    Table 3.1 Password Protection Levels and Their Effects

    File Type READ= WRITE= ALTER=

    PROC SQLview ofDBMSdata

    Protects the underlyingdata from being read orupdated through theview; does not protectagainst replacement ofthe view

    Protects the underlyingdata from being updatedthrough the view; doesnot protect againstreplacement of the view

    Protects the view frombeing modified, deleted,or replaced

    Accessdescriptor

    No effect on descriptor No effect on descriptor Protects the descriptorfrom being read or edited

    Viewdescriptor

    Protects the underlyingdata from being read orupdated through theview

    Protects the underlyingdata from being updatedthrough the view

    Protects the descriptorfrom being read or edited

    You can use the following methods to assign, change, or delete a SAS password: the global SETPASSWORD command, which opens a dialog box the DATASETS procedures MODIFY statement.

    The syntax for using PROC DATASETS to assign a password to an access descriptor,a view descriptor, or a SAS data file is as follows:

    PROC DATASETS LIBRARY=libref MEMTYPE=member-type;MODIFY member-name (password-level = password-modification);

    RUN;

    The password-level argument can have one or more of the following values: READ=,WRITE=, ALTER=, or PW=. PW= assigns read, write, and alter privileges to adescriptor or data file. The password-modification argument enables you to assign anew password or to change or delete an existing password. For example, this PROCDATASETS statement assigns the password MONEY with the ALTER level ofprotection to the access descriptor ADLIB.SALARIES:

    proc datasets library=adlib memtype=access;modify salaries (alter=money);

    run;

    In this case, users are prompted for the password whenever they try to browse orupdate the access descriptor or try to create view descriptors that are based onADLIB.SALARIES.

    In the next example, the PROC DATASETS statement assigns the passwords MYPWand MYDEPT with READ and ALTER levels of protection to the view descriptorVLIB.JOBC204:

    proc datasets library=vlib memtype=view;modify jobc204 (read=mypw alter=mydept);

    run;

    In this case, users are prompted for the SAS password when they try to read the DBMSdata or try to browse or update the view descriptor VLIB.JOBC204. You need bothlevels to protect the data and descriptor from being read. However, a user could stillupdate the data that VLIB.JOBC204 accessesfor example, by using a PROC SQLUPDATE. Assign a WRITE level of protection to prevent data updates.

    Note: When you assign multiple levels of passwords, use a different password foreach level to ensure that you grant only the access privileges that you intend.

  • 28 Protecting Connection Information Chapter 3

    To delete a password, put a slash after the password:

    proc datasets library=vlib memtype=view;modify jobc204 (read=mypw/ alter=mydept/);

    run;

    Protecting Connection Information

    In addition to directly controlling access to data, you can protect the data indirectlyby protecting the connection information that SAS/ACCESS uses to reach the DBMS.Generally, this is achieved by not saving connection information in your code.

    One way to protect connection information is by storing user name, password, andother connection options in a local environment variable. Access to the DBMS is deniedunless the correct user and password information is stored in a local environmentvariable. See the documentation for your DBMS to determine whether this alternativeis supported.

    Another way to protect connection information is by requiring users to manuallyenter it at connection time. When you specify DBPROMPT=YES in a SAS/ACCESSLIBNAME statement, each user has to provide DBMS connection information in adynamic, interactive manner. This is demonstrated in the following statement. Thestatement causes a dialog box to prompt the user to enter connection information, suchas a user name and password:

    libname myoralib oracle dbprompt=yes defer=no;

    The dialog box that appears contains the DBMS connection options that are valid forthe SAS/ACCESS engine that is being used; in this case, Oracle.

    Using the DBPROMPT= option in the LIBNAME statement offers severaladvantages. DBMS account passwords are protected because they do not need to bestored in a SAS program or descriptor file. Also, when a password or user namechanges, the SAS program does not need to be modified. Another advantage is that thesame SAS program can be used by any valid user name and password combination thatis specified during execution. You can also use connection options in this interactivemanner when you want to run a program on a production server instead of testing aserver without modifying your code. By using the prompt window, the new server namecan be specified dynamically.

    Note: The DBPROMPT= option is not available in SAS/ACCESS Interface to DB2under z/OS.

    Extracting DBMS Data to a SAS Data Set

    If you are the owner of a DBMS table and do not want anyone else to read the data,you can extract the data (or a subset of the data) and not distribute information abouteither the access descriptor or view descriptor.

    Note: You might need to take additional steps to restrict LIBNAME orPass-Through access to the extracted data set.

    If you extract data from a view that has a SAS password assigned to it, the new SASdata file is automatically assigned the same password. If a view does not have apassword, you can assign a password to the extracted SAS data file by using theMODIFY statement in the DATASETS procedure. See the Base SAS Procedures Guidefor more information.

  • Data Integrity and Security Controlling DBMS Connections 29

    Defining Views and SchemasIf you want to provide access to some but not all fields in a DBMS table, create a

    SAS view that prohibits access to the sensitive data by specifying that particularcolumns be dropped. Columns that are dropped from views do not affect the underlyingDBMS table and can be reselected for later use.

    Some SAS/ACCESS engines support LIBNAME options that restrict or qualify thescope, or schema, of the tables in the libref. For example, the DB2 engine supports theAUTHID= and LOCATION= options, and the Oracle engine supports the SCHEMA=and DBLINK= options. See the SAS/ACCESS documentation for your DBMS todetermine which options are available to you.

    This example uses SAS/ACCESS Interface to Oracle:

    libname myoralib oracle user=testuser password=testpasspath=myoraserver schema=testgroup;

    proc datasets lib=myoralib;run;

    In this example the MYORALIB libref is associated with the Oracle schema namedTESTGROUP. The DATASETS procedure lists only the tables and views that areaccessible to the TESTGROUP schema. Any reference to a table that uses the librefMYORALIB is passed to the Oracle server as a qualified table name; for example, if theSAS program reads a table by specifying the SAS data set MYORALIB.TESTTABLE,the SAS/ACCESS engine passes the following query to the server:

    select * from "testgroup.testtable"

    Controlling DBMS ConnectionsBecause the overhead of executing a connection to a DBMS server can be

    resource-intensive, SAS/ACCESS supports the CONNECTION= and DEFER= optionsto control when a DBMS connection is made, and how many connections are executedwithin the context of your SAS/ACCESS application. For most SAS/ACCESS engines, aconnection to a DBMS begins one transaction, or work unit, and all statements issuedin the connection execute within the context of the active transaction.

    The CONNECTION= LIBNAME option enables you to specify how many connectionsare executed when the library is used and which operations on tables are shared withina connection. By default, the value is CONNECTION=SHAREDREAD, which meansthat a SAS/ACCESS engine executes a shared read DBMS connection when the libraryis assigned. Every time a table in the library is read, the read-only connection is used.However, if an application attempts to update data using the libref, a separateconnection is issued, and the update occurs in the new connection. As a result, there isone connection for read-only transactions and a separate connection for each updatetransaction.

    In the example below, the SAS/ACCESS engine issues a connection to the DBMSwhen the libref is assigned. The PRINT procedure reads the table by using the firstconnection. When the PROC SQL updates the table, the update is performed with asecond connection to the DBMS.

    libname myoralib oracle user=testuser password=testpasspath=myoraserver;

    proc print data=myoralib.mytable;run;

  • 30 Locking, Transactions, and Currency Control Chapter 3

    proc sql;update myoralib.mytable set acctnum=123

    where acctnum=456;quit;

    This example uses SAS/ACCESS Interface to DB2 under z/OS. The LIBNAMEstatement executes a connection by way of the DB2 Call Attach Facility to the DB2DBMS server:

    libname mydb2lib db2 authid=testuser;

    If you want to assign more than one SAS libref to