292
SAS/ACCESS ® 9.2 Interface to PC Files Reference SAS ® Documentation

Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

  • Upload
    donhu

  • View
    230

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

SAS/ACCESS® 9.2 Interface to PC FilesReference

SAS® Documentation

Page 2: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2009.SAS/ACCESS ® 9.2 Interface to PC Files: Reference. Cary, NC: SAS Institute Inc.

SAS/ACCESS® 9.2 Interface to PC Files: ReferenceCopyright © 2009, SAS Institute Inc., Cary, NC, USAISBN 978-1-59994-710-5All rights reserved. Produced in the United States of America.For a hardcopy 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, February 20091st printing, March 2009SAS® 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.

Page 3: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Contents

What’s New vii

Overview vii

New and Enhanced Support for Import and Export Wizards and Procedures vii

New and Enhanced Support for PC Files Server vii

Support for New File Formats viii

Date/Time Value Differences between SAS and Microsoft Files viii

Documentation Enhancements viii

P A R T 1 SAS/ACCESS 9.2 Interface to PC Files: Reference 1

Chapter 1 � Working with SAS/ACCESS Interface to PC Files 3Methods for Accessing PC Files Data 3

Using This Document 4

Sample Data in This Document 4

P A R T 2 Import and Export Wizards and Procedures 5

Chapter 2 � Features and Supported Data Sources 7Features of the Import and Export Wizards and Procedures 7

Supported Data Sources and Platforms 7

Chapter 3 � Using the SAS Import and Export Wizards 11About the Import and Export Wizards 11

Using the External File Interface (EFI) 11

Chapter 4 � Using the IMPORT Procedure 13Overview: IMPORT Procedure 13

Syntax: IMPORT Procedure 13

Chapter 5 � Using the EXPORT Procedure 19Overview: EXPORT Procedure 19

Syntax: EXPORT Procedure 19

Chapter 6 � File Format-Specific Reference for IMPORT and EXPORT Procedures 25Delimited Files 26

Accessing Data in Microsoft Access Database Files and Excel Workbook Files 30

Microsoft Excel Workbook Files 31

Microsoft Access Database Files 47

Lotus 1-2-3 WKn Files 54

dBase DBF Files 58

dBase DBFMEMO Files 63

JMP Files 63

Paradox DB Files 66

Page 4: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

iv

SPSS SAV Files 67

Stata DTA Files 69

P A R T 3 LIBNAME Statement and Pass-Through Facility on 32-Bit MicrosoftWindows 73

Chapter 7 � The LIBNAME Engines 75Overview: LIBNAME Engines 75

Software Requirements 76

Macro Variables 76

SAS Trace System Options 77

Chapter 8 � LIBNAME Statement: PC Files on Microsoft Windows 81Overview: LIBNAME Statement for PC Files on Microsoft Windows 81

Assigning a Libref Interactively 82

LIBNAME Options for PC Files on Microsoft Windows 86

Data Set Options for PC Files on Microsoft Windows 93

Chapter 9 � The Pass-Through Facility for PC Files on Microsoft Windows 111Overview: Pass-Through Facility for PC Files on Microsoft Windows 111

Syntax for the Pass-Through Facility for PC Files 112

Microsoft Jet and Microsoft Ace Provider Supported Data Types 120

Special Jet and Ace Queries 122

Special Jet Commands 124

Chapter 10 � File-Specific Reference 127Microsoft Excel Workbook Files 127

Microsoft Access Files 132

P A R T 4 LIBNAME Statement and Pass-Through Facility on Linux, UNIX, and64-Bit Microsoft Windows 137

Chapter 11 � The PC Files Server on 32-Bit Microsoft Windows 139Overview 139

PC Files Server Modes 140

PC Files Server Installation 141

Running the PC Files Server as a Desktop Application 141

Running the PC Files Server as a Windows Service 144

Constraints 144

Shared Information 145

Chapter 12 � LIBNAME Statement: PC Files on Linux, UNIX, and 64-Bit MicrosoftWindows 147Overview: LIBNAME Statement for PC Files on Linux, UNIX, and 64-Bit MicrosoftWindows 147

LIBNAME Options for PC Files on Linux and UNIX 153

Data Set Options for PC Files on Linux and UNIX 159

Page 5: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

v

Chapter 13 � Pass-Through Facility: PC Files on Linux, UNIX, and 64-Bit MicrosoftWindows 177Overview: Pass-Through Facility for PC Files on Linux, UNIX, and 64-Bit MicrosoftWindows 177

Syntax for the Pass-Through Facility for PC Files 177

Special PC Files Queries 187

P A R T 5 ACCESS and DBLOAD Procedures 189

Chapter 14 � The ACCESS Procedure for PC Files 191Overview: ACCESS Procedure for PC Files 191

SAS/ACCESS Descriptors for PC Files 193

SAS Passwords for Descriptors 193

Performance and Efficient View Descriptors for PC Files 194

ACCESS Procedure Syntax 194

Chapter 15 � The DBLOAD Procedure for PC Files 215Overview: DBLOAD Procedure for PC Files 215

DBLOAD Procedure Naming Conventions 216

DBLOAD Procedure Syntax 216

Chapter 16 � File-Specific Reference for the ACCESS and DBLOAD Procedures 225ACCESS Procedure: XLS Specifics 226

DBLOAD Procedure: XLS Specifics 232

Setting Environment Variables for XLS Files 235

ACCESS Procedure: WKn Specifics 236

DBLOAD Procedure: WKn Specifics 240

Setting Environment Variables for WKn Files 242

ACCESS Procedure: DBF Specifics (Windows) 243

DBLOAD Procedure: DBF Specifics (Windows) 245

ACCESS Procedure: DIF Specifics 247

DBLOAD Procedure: DIF Specifics 250

Setting Environment Variables for DIF Files 253

P A R T 6 Appendixes 255

Appendix 1 � The DBF and DIF Procedures 257Introduction to the DBF and DIF Procedures 257

Appendix 2 � Recommended Reading 263Recommended Reading 263

Glossary 265

Index 271

Page 6: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

vi

Page 7: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

vii

What’s New

Overview

SAS/ACCESS 9.2 Interface to PC Files has these new features and enhancements:

� new and enhanced support for Import and Export Wizards and procedures

� new and enhanced support for PC Files Server

� support for new file formats

� new UNICODE= LIBNAME option

� date and time value differences between Microsoft Access database and Excel files

� documentation enhancements to SAS/ACCESS 9.2 Interface to PC Files: Reference

z/OS is the successor to the OS/390 (formerly MVS) operating system. SAS/ACCESS9.1 and later for z/OS is supported on both OS/390 and z/OS operating systems.Throughout this document, any reference to z/OS also applies to OS/390 unlessotherwise stated.

New and Enhanced Support for Import and Export Wizards andProcedures

New and enhanced PC-specific support is available for these wizards and procedures.Information that is specific to UNIX and OpenMVS for Integrity Servers for theIMPORT and EXPORT procedures is still in the Base SAS Procedures Guide.

New and Enhanced Support for PC Files Server

The following support is available for PC Files Server:

� new high-level view and installation

� enhanced start-up and configuration

Page 8: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

viii What’s New

� PC Files Server can be run in either of these modes:Server mode runs with a graphical interface on the PC server desktop. This mode

was available in SAS 9.1.3. Although you must start it manually, it makesaccess to PC Files Server configuration and client monitoring easier.

Service mode runs as a Windows service, so you can start it automaticallywhenever you start Windows. Although it lacks the graphical interface forconfiguration and monitoring, it is a more automated mode.

� Server and service modes cannot be active at the same time because each modewould try to listen on the same network port.

� When you run PC Files Server as a service, follow these steps to change suchconfiguration options as the port number, the number of users, and encryption.See Configuring the PC Files Server.

1 Stop the service.2 Run the server so that you can use the graphical interface.3 Change the options that you want.4 Shut down the server and restart the service.

Support for New File FormatsSAS import and export utilities support the following new file formats:� New Microsoft Office 2007 file formats: Access database (.accdb) files and Excel

workbook (.xlsb, xlsm, .xlsx) files� “dBase DBFMEMO Files” on page 63� “JMP Files” on page 63� “Paradox DB Files” on page 66� “SPSS SAV Files” on page 67� “Stata DTA Files” on page 69

Date/Time Value Differences between SAS and Microsoft FilesIn different versions of SAS software, PROC IMPORT and the LIBNAME engine can

read in date/time values from a Microsoft Access or Excel file using different formats.To change to the format that you need, you can now specify USEDATE= as either aLIBNAME option or an optional statement with PROC IMPORT. For details on how toprocess date/time values, see “Processing Date/Time Values between SAS and MicrosoftExcel” on page 132 and “Processing Date/Time Values between SAS and MicrosoftAccess” on page 136.

Documentation EnhancementsSAS/ACCESS 9.2 Interface to PC Files: Reference was significantly reorganized and

rewritten.

Page 9: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

1

P A R T1

SAS/ACCESS 9.2 Interface to PC Files:Reference

Chapter 1. . . . . . . . . .Working with SAS/ACCESS Interface to PC Files 3

Page 10: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

2

Page 11: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

3

C H A P T E R

1Working with SAS/ACCESSInterface to PC Files

Methods for Accessing PC Files Data 3Using This Document 4

Sample Data in This Document 4

Methods for Accessing PC Files Data

You can use SAS/ACCESS Interface to PC Files to read data from PC files, to usethat data in SAS reports or applications, and to use SAS data sets to create PC files invarious formats. SAS/ACCESS Interface to PC Files includes the following features:

Accessing data in Microsoft Access database files and Excel workbook files. See“Accessing Data in Microsoft Access Database Files and Excel Workbook Files” onpage 30

Import and Export Wizards and procedures (OpenVMS, UNIX, and MicrosoftWindows operating environments)

enables data transfer between SAS and several PC file formats, includingMicrosoft Access, Microsoft Excel, Lotus 1-2-3, DBF, JMP, SPSS, Stata, andParadox. Not every PC file format is available under every operating environment.For a list of file formats that are supported under your operating environment, seeTable 2.1 on page 8.

LIBNAME statement (Linux, UNIX, and Microsoft Windows operating environments)provides direct, transparent access to Microsoft Access (97, 2000, 2002, 2003, or2007) and Microsoft Excel (5, 95, 97, 2000, 2002, 2003, or 2007) data. To use theLIBNAME statement to access PC files on Linux and UNIX, you are required toinstall the PC Files Server. (For more information, see Chapter 11, “The PC FilesServer on 32-Bit Microsoft Windows,” on page 139.)

Pass-Through Facility (Linux, UNIX, and Microsoft Windows operatingenvironments)

enables access to Microsoft Access (97, 2000, 2002, or 2003) and Microsoft Excel (5,95, 97, 2000, 2002, or 2003) data using the SQL syntax to the data source withoutleaving your SAS session. SQL statements are passed directly to the data sourcefor processing.

ACCESS procedure (Microsoft Windows operating environments)creates descriptor files that describe data in a PC file to SAS so you can directlyread, update, or extract PC files data into a SAS data file. You can use theACCESS procedure with Microsoft Excel (4, 5, 95), Lotus 1-2-3 (WK1, WK3, WK4),DBF, and DIF file formats.

Page 12: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

4 Using This Document � Chapter 1

DBLOAD procedure (Microsoft Windows operating environments)creates PC files and loads them with data from a SAS data set. You can use theDBLOAD procedure with any file formats that the ACCESS procedure supports.

DBF and DIF procedures (Linux, UNIX, Microsoft Windows, and z/OS operatingenvironments)

enable conversion between dBASE (DBF) files and SAS data sets and betweendata interchange format (DIF) files and SAS data sets. The DIF procedure is notavailable under z/OS.

Using This DocumentThis document is intended for applications programmers and users who know how to

use their operating environment and are familiar with their PC files, as well as how touse basic SAS commands and statements. It provides a general reference, specificdetails, and code examples that show how you can access and use data in PC files fromSAS.

Sample Data in This DocumentExamples in this document show how you can use SAS/ACCESS Interface to PC

Files to read and write PC file data directly from SAS programs. They are not meant asexamples for you to follow in designing files for any purpose. Sample data is availablefrom http://supporttest.unx.sas.com/kb/##/###.html. The data is based on a fictitiousinternational textile manufacturer whose product line includes some special fabrics thatthey make to precise specifications. All data is fictitious.

Page 13: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

5

P A R T2

Import and Export Wizards and Procedures

Chapter 2. . . . . . . . . .Features and Supported Data Sources 7

Chapter 3. . . . . . . . . .Using the SAS Import and Export Wizards 11

Chapter 4. . . . . . . . . .Using the IMPORT Procedure 13

Chapter 5. . . . . . . . . .Using the EXPORT Procedure 19

Chapter 6. . . . . . . . . .File Format-Specific Reference for IMPORT and EXPORTProcedures 25

Page 14: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

6

Page 15: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

7

C H A P T E R

2Features and Supported DataSources

Features of the Import and Export Wizards and Procedures 7Supported Data Sources and Platforms 7

Features of the Import and Export Wizards and ProceduresTo read and write data between SAS data sets and external PC files, you can use the

Import and Export Wizards and procedures. Although they have similar capabilities,the wizards are point-and-click interfaces, and the procedures are code-based. Thewizards also do not provide the full features of the procedures. For example, you cannotuse them to specify such data set options as DROP, KEEP, and WHERE.

Supported Data Sources and PlatformsThe IMPORT and EXPORT procedures work within the same limited range of file

formats if these reside locally on UNIX, but they also work with a wider range of PCfile formats if these are on the PC.

This table shows the availability of Import and Export Wizards and procedures withrespect to the data source components and platforms.

The Import and Export Wizards and procedures are part of Base SAS software. Ifyou do not have a license to SAS/ACCESS Interface to PC Files, however, you canaccess only CSV, TXT, and delimited files.

Page 16: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

8 Supported Data Sources and Platforms � Chapter 2

Table 2.1 Availability of the Import/Export Wizards and Procedures

Import ExportData SourceDescription

DataSource

IdentifierWizard PROC Wizard PROC Supported

Platforms

Supported SASReleases onPlatforms

Excel using LIBNAMEengine

EXCEL

EXCEL97

EXCEL2000

EXCEL2002

EXCEL2003

EXCEL2007

Yes Yes Yes Yes 32-bitWindows

9.0 or higher

Excel using PC FilesServer

EXCELCS No Yes No Yes 64-bitWindows

Linux, UNIX

9.1.3 or higher

9.1 or higher

Excel using .XLS fileformats

XLS No Yes No Yes 32-bitWindows

64-bitWindows

Linux, UNIX

9.1.3 SP3 orhigher

Excel v4 using PROCACCESS and DBLOAD

EXCEL4 Yes Yes Yes Yes 32-bitWindows

64-bitWindows

8.2 or higher

9.1.3 SP1 orhigher

Excel v5 using PROCACCESS and DBLOAD

EXCEL5 Yes Yes Yes Yes 32-bitWindows

64-bitWindows

8.2 or higher

9.1.3 SP1 orhigher

Access2000+ usingLIBNAME engine

ACCESS

ACCESS2000

ACCESS2002

ACCESS2003

ACCESS2007

Yes Yes Yes Yes 32-bitWindows

9.0 or higher

Access97 usingLIBNAME engine

ACCESS97 Yes Yes Yes Yes 32-bitWindows

V9.0 or higher

Access using PC FilesServer

ACCESSCS No Yes No Yes 64-bitWindows

Linux, UNIX

9.1.3 or higher

9.1 or higher

dBase using .DBF fileformats

DBF Yes Yes Yes Yes 32-bitWindows

64-bitWindows

Linux, UNIX

8.2 or higher

9.1.3 SP1 orhigher

8.1 or higher

Page 17: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Features and Supported Data Sources � Supported Data Sources and Platforms 9

Import ExportData SourceDescription

DataSource

IdentifierWizard PROC Wizard PROC Supported

Platforms

Supported SASReleases onPlatforms

dBase file formats withMEMO support

DBFMEMO No Yes No Yes 32-bitWindows

64-bitWindows

Linux, UNIX

9.2

JMP using .JMP fileformats

JMP Yes Yes Yes Yes 32-bitWindows

64-bitWindows

Linux, UNIX

9.1 or higher

9.1.3 or higher

9.1 or higher

Paradox using .DB fileformats

DB Yes Yes Yes Yes 32-bitWindows

64-bitWindows

Linux, UNIX

9.2

SPSS using .SAV fileformats

SAV Yes Yes Yes Yes 32-bitWindows

64-bitWindows

Linux, UNIX

9.1.3 SP3 orhigher

Stata using .DTA fileformats

DTA Yes Yes Yes Yes 32-bitWindows

64-bitWindows

Linux, UNIX

9.1.3 SP3 orhigher

Lotus 1-2-3 using .WK1file formats

WK1 Yes Yes Yes Yes 32-bitWindows

64-bitWindows

8.2 or higher

9.1.3 or higher

Lotus 1-2-3 using .WK3file formats

WK3 Yes Yes Yes Yes 32-bitWindows

64-bitWindows

8.2 or higher

9.1.3 or higher

Lotus 1-2-3 using .WK4file formats

WK4 Yes Yes Yes Yes 32-bitWindows

64-bitWindows

8.2 or higher

9.1.3 or higher

comma-separated file CSV Yes Yes Yes Yes 32-bitWindows

64-bitWindows

Linux, UNIX

Open VMS

8.2 or higher

Page 18: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

10 Supported Data Sources and Platforms � Chapter 2

Import ExportData SourceDescription

DataSource

IdentifierWizard PROC Wizard PROC Supported

Platforms

Supported SASReleases onPlatforms

tab-separated file TAB Yes Yes Yes Yes 32-bitWindows

64-bitWindows

Linux, UNIX

Open VMS

8.2 or higher

delimiter-separated file DLM Yes Yes Yes Yes 32-bitWindows

64-bitWindows

Linux, UNIX

Open VMS

V8.2 or higher

data files using client/server model

PCFS No Yes No Yes 32-bitWindows

64-bitWindows

Linux, UNIX

Open VMS

9.1 or higher

Page 19: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

11

C H A P T E R

3Using the SAS Import and ExportWizards

About the Import and Export Wizards 11Import and Export Wizards 11

Using the External File Interface (EFI) 11

About the Import and Export Wizards

Import and Export WizardsWith the Import and Export Wizard you can transfer data between external data

sources and SAS Data sets. As each wizard presents a series of windows with simplechoices to guide you through a process, making a complex infrequent task more simpleto perform.

� The Import Wizard guides you through the steps to read data from an externaldata source and write it to a SAS data set.

� The Export Wizard guides you through the steps to read data from a SAS data setand write it to an external data source.

For each step, each wizard display a window with selections that you can make. Toget help for any window, select the Help button.

To start the wizard, select File � Import Data or File � Export Data from the SASwindowing environment.

Using the External File Interface (EFI)

The External File Interface (EFI) is a point-and-click graphical interface that enablesyou to read and write data that is not in SAS internal format.

After a series of windows that request specific information, the wizard invokes theEFI when you select Finish. To return to the wizard without invoking the EFI, selectBack. To close the wizard without invoking the EFI, select Cancel.

For instruction on using the EFI after the IFE is invoked, select Help and thenUsing This Window from the SAS menu bar.

Page 20: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

12

Page 21: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

13

C H A P T E R

4Using the IMPORT Procedure

Overview: IMPORT Procedure 13Syntax: IMPORT Procedure 13

PROC IMPORT Statement 14

Overview: IMPORT Procedure

The IMPORT procedure reads data from an external data source and writes it to aSAS data set. External data sources can include Microsoft Access databases, MicrosoftExcel files, Lotus 1-2-3 spreadsheets, Paradox files, SPSS files, Stata files, anddelimited external files. (Delimited files contain columns of data values that areseparated by a delimiter, such as a blank or a comma.)

When you run PROC IMPORT, the procedure reads the input file and writes the datato a SAS data set. The SAS variable definitions are based on the input records. PROCIMPORT imports the data by one of the following methods:

� generated DATA step code

� generated SAS/ACCESS code

� translation engines

You control the results with statements and options that are specific to the inputdata source. PROC IMPORT generates the specified output SAS data set and writesinformation about the import to the SAS log. In the log, you see the DATA step or theSAS/ACCESS code that PROC IMPORT generates. If a translation engine is used, nocode is submitted.

Note: To import data, you can also use the Import Wizard, which is a windowingtool that guides you through the steps to import an external data source. You canrequest that the Import Wizard generate IMPORT procedure statements, which you cansave to a file for subsequent use. To open the Import Wizard, select File � Import Datafrom the SAS windowing environment. �

Syntax: IMPORT ProcedureRestriction: PROC IMPORT is available for the following operating environments:

� OpenVMS for Integrity servers

� Linux, UNIX

� Microsoft Windows

Page 22: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

14 PROC IMPORT Statement � Chapter 4

PROC IMPORTDATAFILE="filename" | DATATABLE="tablename"OUT=<libref.>SAS-data-set <(SAS-data-set-options)><DBMS=data-source-identifier><REPLACE> ;

<data-source-statement(s);>

PROC IMPORT Statement

PROC IMPORTDATAFILE="filename"OUT=<libref.>SAS-data-set<DBMS=data-source-identifier><REPLACE> ;

Required Arguments

DATAFILE="filename"specifies the complete path and filename or fileref for the input PC file, spreadsheet,or delimited external file. A fileref is a SAS name that is associated with the physicallocation of the output file. To assign a fileref, use the FILENAME statement. If youspecify a fileref or if the complete path and filename does not include specialcharacters (such as the backslash in a path), lowercase characters, or spaces, thenyou can omit the quotation marks. For more information about the FILENAMEstatement, see SAS Language Reference: Dictionary.Alias: FILE=Restriction: PROC IMPORT does not support device types or access methods for

the FILENAME statement except for DISK. For example, PROC IMPORT does notsupport the TEMP device type, which creates a temporary external file.

Restriction: For client/server applications. When running SAS/ACCESS softwareon UNIX to access data that is stored on a PC server, you must specify the fullpath and filename of the file that you want to import. The use of a fileref is notsupported.

Restriction: PROC IMPORT can import data only if the data type is supported bySAS. SAS supports numeric and character types of data but not, for example,binary objects. If the data that you want to import is a type that SAS does notsupport, PROC IMPORT might not be able to import it correctly. In many cases,the procedure attempts to convert the data to the best of its ability. However, thisis not possible for some times.

Interaction: For some input data sources like a Microsoft Excel spreadsheet, todetermine the data type (numeric or character) for a column, the first eight rows ofdata are scanned and the most prevalent type of data is used (this is the default).If most of the data in the first eight rows is missing, SAS defaults to the characterdata type; any subsequent numeric data for that column becomes missing as well.Mixed data can also create missing values. For example, if the first eight rowscontain mostly character data, SAS assigns the column as a character data type.Any subsequent numeric data for that column becomes missing.

Tip: For information about how SAS converts data types, see the specificinformation for the data source file format that you are importing.

Page 23: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Using the IMPORT Procedure � PROC IMPORT Statement 15

Tip: If a DBF file was created by Microsoft Visual FoxPro, the file must be exportedby Visual FoxPro into an appropriate dBASE format in order to import the file toSAS.

DATATABLE="tablename"specifies the table name of the input DBMS table. If the name does not includespecial characters (such as question marks), lowercase characters, or spaces, you canomit the quotation marks. The DBMS table name might be case sensitive.Alias: TABLE=Requirement: When importing Microsoft Access tables, SAS/ACCESS converts the

table name to a SAS member name. SAS does not support member names longerthan 32 bytes.

Requirement: When you import a DBMS table, you must specify the DBMS=option.

OUT=<libref.>SAS-data-setidentifies the output SAS data set with either a one- or two-level SAS name (libraryand member name). If the specified SAS data set does not exist, PROC IMPORTcreates it. If you specify a one-level name, by default PROC IMPORT uses either theUSER library (if assigned) or the WORK library (if USER not assigned).Featured in: All examples

(SAS-data-set-options)specifies SAS data set options. For example, to assign a password to the resultingSAS data set, you can use the ALTER=, PW=, READ=, or WRITE= data set option.To import only data that meets a specified condition, you can use the WHERE= dataset option. For information about all SAS data set options, see the data set optionssection in SAS Language Reference: Dictionary.

OptionsWhen exporting data to a Microsoft Access table, SAS/ACCESS Interface for PC Files

converts the table name to a SAS member name. SAS does not support member namesthat are longer than 32 bytes.

DBMS=data-source-identifierspecifies the type of data to import. To import a DBMS table, you must specifyDBMS= using a valid database identifier. For example, DBMS=ACCESS specifies toimport a Microsoft Access 2000, 2002, or 2003 table. To import PC files,spreadsheets, and delimited external files, you do not have to specify DBMS= if thefilename that is specified by DATAFILE= contains a valid extension so that PROCIMPORT can recognize the type of data. For example, PROC IMPORT recognizes thefilename ACCOUNTS.WK1 as a Lotus 1-2-3 Release 2 spreadsheet and the filenameMYDATA.CSV as a delimited external file that contains comma-separated datavalues; therefore, a DBMS= specification is not necessary.

The following values are valid for the DBMS= option. For detailed informationabout supported platforms and SAS releases, see Table 2.1 on page 8.

DataSourceIdentifier

Input Data Source Extension

ACCESS Microsoft Access 2000, 2002, 2003, or 2007 table (using the LIBNAMEstatement)

.mdb

.accdb

ACCESS97 Microsoft Access 97 table (using the LIBNAME statement) .mdb

Page 24: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

16 PROC IMPORT Statement � Chapter 4

DataSourceIdentifier

Input Data Source Extension

ACCESSCS Microsoft Access table (using the LIBNAME statement .mdb

.accdb

CSV delimited file (comma-separated values) .csv

DBF dBASE 5.0, IV, III+, and III files .dbf

DBFMEMO dBASE 5.0, IV, III+, and III files with memos

FoxPro and Visual FoxPro files with memos

.dbf

.fpt

.dbt

DLM delimited file (default delimiter is a blank) .*

DTA Stata file .dta

EXCEL Excel 97, 2000, 2002, or 2003 spreadsheet (using the LIBNAMEstatement)

.xls

.xlsb

.xlsm

.xlsx

EXCEL4 Excel 4.0 spreadsheet (using PROC ACCESS) .xls

EXCEL5 Excel 5.0 or 7.0 (95) spreadsheet (using PROC ACCESS) .xls

EXCELCS Excel spreadsheet (using the LIBNAME statement) .xls

.xlsb

JMP PCFS .jmp

PARADOX Paradox .DB files .db

PCFS Files on PC Files Server .*

SAV SPSS file .sav

TAB delimited file (tab-delimited values) *.txt

WK1 Lotus1-2-3 Release 2 spreadsheet .wk1

WK3 Lotus 1-2-3 Release 3 spreadsheet .wk3

WK4 Lotus 1-2-3 Release 4 or 5 spreadsheet .wk4

XLS Excel 5.0, 95, 97, 2000, 2002, or 2003 spreadsheet (using file formats) .xls

Restriction: The availability of a data source depends on:� the operating environment, and in some cases the platform. See .� whether your site has a license to the SAS/ACCESS Interface for PC Files. If

you do not have a license, only delimited files are supported.

When you specify a value for DBMS=, consider the following:� When you specify DBMS=XLS for an Excel file, you can read and write Excel

spreadsheets under UNIX directly, without having to access the PC Files Server.� Microsoft Access versions 2000, 2002, and 2003 share the same internal file

formats. The SAS LIBNAME engine recognizes ACCESS2000, ACCESS2002,and ACCESS2003 as aliases for the identifier ACCESS. By specifyingDBMS=ACCESS, SAS can read in any of these versions of files that are savedin Microsoft Access applications.

Page 25: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Using the IMPORT Procedure � PROC IMPORT Statement 17

� Microsoft Excel versions 97, 2000, 2002, and 2003 share the same internal fileformats. The SAS LIBNAME engine recognizes EXCEL97, EXCEL2000,EXCEL2002, and EXCEL2003 as aliases for the identifier EXCEL.

The following table summarizes the versions of Excel files and whether PROCIMPORT can distinguish among them based on the DBMS= specification.

Identifier Excel 2007 Excel 97, 2000,2002, 2003

Excel 5.0, 95 Excel 4.0

XLS no yes yes no

EXCEL yes yes yes yes

EXCEL5 no no yes yes

EXCEL4 no no yes yes

The following table summarizes the access technology used based on the DBMS=specifications.

DBMS= Uses Requires OperatingPlatform

EXCEL SAS Excel LIBNAME engine Microsoft Jet or AceProvider

32-bit Windows

XLS file formats technology 32-bit Windows

64-bit Windows

Linux, UNIX

EXCELCS PC Files LIBNAME engine PC Files Server MicrosoftExcel Driver on 32-bitWindows

64-bit Windows

Linux, UNIX

Note: Although Excel 4.0 and Excel 5.0 spreadsheets are often interchangeable, itis recommended that you specify the exact version. �

REPLACEoverwrites an existing SAS data set. If you do not specify REPLACE, PROCIMPORT does not overwrite an existing data set.

Page 26: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

18

Page 27: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

19

C H A P T E R

5Using the EXPORT Procedure

Overview: EXPORT Procedure 19Syntax: EXPORT Procedure 19

PROC EXPORT Statement 20

Overview: EXPORT Procedure

The EXPORT procedure reads data from a SAS data set and writes it to an externaldata source. External data sources can include: Microsoft Access databases, MicrosoftExcel files, Lotus 1–2–3 spreadsheets, Paradox files, SPSS files, Stata files, DBF, andJMP delimited external files. (Delimited files contain columns of data values that areseparated by a delimiter, such as a blank or a comma.)

When you run PROC EXPORT, the procedure reads the input data set and writes thedata to the external data source. PROC EXPORT exports the data by one of thefollowing methods:

� generated DATA step code

� generated SAS/ACCESS code

� translation engines

You control the results with statements and options that are specific to the outputdata source. PROC EXPORT generates the specified output file and writes informationabout the export to the SAS log. In the log, you see the DATA step or the SAS/ACCESScode that PROC EXPORT generates. If a translation engine is used, no code issubmitted.

Note: To export data, you can also use the Export Wizard, which is a windowing toolthat guides you through the steps to export a SAS data set. You can request that theExport Wizard generate EXPORT procedure statements, which you can save to a file forsubsequent use. To open the Export Wizard, select File � Export Data from the SASwindowing environment. �

Syntax: EXPORT ProcedureRestriction: PROC EXPORT is available for the following operating environments:

� OpenVMS for Integrity servers

� Linux, UNIX

� Microsoft Windows

Page 28: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

20 PROC EXPORT Statement � Chapter 5

PROC EXPORT DATA=<libref.>SAS-data-set <(SAS-data-set-options)>OUTFILE="filename" | OUTTABLE="tablename"<DBMS=data-source-identifier> <REPLACE> <LABEL>;

<data-source-statement(s);>

PROC EXPORT Statement

PROC EXPORT DATA=<libref.>SAS-data-set <(SAS-data-set-options)>OUTFILE="filename" | OUTTABLE="tablename"<DBMS=data-source-identifier> <REPLACE> <LABEL>;

Required Arguments

DATA=<libref.>SAS-data-setidentifies the input SAS data set with either a one- or two-level SAS name (libraryand member name). If you specify a one-level name, by default, PROC EXPORT useseither the USER library (if assigned) or the WORK library (if USER not assigned).

Default: If you do not specify a SAS data set, PROC EXPORT uses the mostrecently created SAS data set, which SAS keeps track of with the system variable_LAST_. However, in order to be certain that PROC EXPORT uses the correctdata set, you should identify the SAS data set.

Restriction: PROC EXPORT can export data only if the format of the data issupported by the data source or the amount of data is within the limitations of thedata source. For example, some data sources have a maximum number of rows orcolumns, and some data sources cannot support SAS user-defined formats andinformats. If the data that you want to export exceeds the limits of the data source,PROC EXPORT might not be able to export it correctly. When SAS encountersincompatible formats, the procedure formats the data to the best of its ability.

(SAS-data-set-options)specifies SAS data set options. For example, if the data set that you are exportinghas an assigned password, you can use the ALTER=, PW=, READ=, or WRITE= dataset option. To export only data that meets a specified condition, you can use theWHERE= data set option. For information about SAS data set options, see “Data SetOptions” in SAS Language Reference: Dictionary.

OUTFILE="filename"specifies the complete path and filename or a fileref for the output PC file,spreadsheet, or delimited external file. You can omit the quotation marks you specifya fileref or if the complete path and filename do not include special characters (suchas the backslash in a path), lowercase characters, or spaces. A fileref is a SAS namethat is associated with the physical location of the output file. To assign a fileref, usethe FILENAME statement.

Alias: FILE

Restriction: PROC EXPORT does not support device types or access methods forthe FILENAME statement except for DISK. For example, PROC EXPORT doesnot support the TEMP device type, which creates a temporary external file.

Page 29: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Using the EXPORT Procedure � PROC EXPORT Statement 21

Restriction: For client/server applications: You must specify the full path andfilename of the file that you want to import when you are running SAS/ACCESSsoftware on UNIX to access data that is stored on a PC server. Using a fileref isnot supported.

OUTTABLE="tablename"specifies the table name of the output DBMS table. If the name does not includespecial characters (such as question marks), lowercase characters, or spaces, you canomit the quotation marks. The DBMS table name might be case sensitive.

Alias: TABLE

Requirement: When you export a DBMS table, you must specify the DBMS= option.

Options

DBMS=data-source-identifierspecifies the type of data to export. To export a DBMS table, you must specifyDBMS= by using a valid database identifier. For example, DBMS=ACCESS specifiesto export a table into a Microsoft Access 2000, 2002, 2003, or 2007 database. You donot have to specify DBMS= to export PC files, spreadsheets, and delimited externalfiles if the filename that you specify in OUTFILE= contains a valid extension. PROCEXPORT can recognize the type of data if you specify a valid extension. For example,PROC EXPORT recognizes the filename ACCOUNTS.WK1 as a Lotus 1-2-3 Release 2spreadsheet and the filename MYDATA.CSV as an external file that containscomma-separated data values; therefore, a DBMS= specification is not necessary.

Tip: When you specify DBMS=XLS for an Excel file, you can read and write Excelspreadsheets under UNIX directly, without having to access the PC Files Server.

The following values are valid for the DBMS= option. For detailed informationabout supported platforms and SAS releases, see“Supported Data Sources and Platforms” on page 7

Data SourceIdentifier

Output Data Source Extension Versionof FileCreated

ACCESS* Microsoft Access 2000, 2002, 2003 or 2007 table(using the LIBNAME statement)

.mdb

.accdb

2000

2007

ACCESS97 Microsoft Access 97 table (using the LIBNAMEstatement)

.mdb 97

ACCESSCS Microsoft Access table (using the LIBNAMEstatement)

.mdb

.accdb

2000***

2007

CSV delimited file (comma-separated values) .csv

DBF dBASE 5.0, IV, III+, and III files .dbf 5.0

DBFMEMO dBASE 5.0, IV, III+, and III files with memos

FoxPro and VisualPro with memos

.dbf

.fpt

5.0

DLM delimited file (default delimiter is a blank) .*

DTA Stata file .dta Version8

EXCEL4 Excel 4.0 spreadsheet (using proc DBLOAD) .xls 4.0

Page 30: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

22 PROC EXPORT Statement � Chapter 5

Data SourceIdentifier

Output Data Source Extension Versionof FileCreated

EXCEL5 Excel 5.0 or 7.0 (95) spreadsheet (using procDBLOAD)

.xls 5.0

EXCEL* Excel 97, 2000, 2002, 2003 or 2007 spreadsheet(using the LIBNAME statement)

.xls

.xlsb

.xlsx

97

2007

2007

EXCELCS Excel spreadsheet (using the LIBNAME statement) .xls

xlsb

97**

2007

XLS Excel 97, 2000, 2002, or 2003 spreadsheet (using fileformats)

.xls 97

JMP JMP file

PARADOX Paradox DB files .db

PCFS Files on PC server .*

SAV SPSS file, compressed and uncompressed binary files .sav

TAB delimited file (tab-delimited values) .txt

WK1 Lotus 1-2-3 Release 2 spreadsheet .wk1

WK3 Lotus 1-2-3 Release 3 spreadsheet .wk3

WK4 Lotus 1-2-3 Release 4 and 5 spreadsheet .wk4

* Not available for Microsoft Windows 64-Bit Edition.** Value listed here is the default value. The real version of the loaded file dependson the version of the existing file or the value specified for VERSION= statement.Restriction: Here is what the availability of an output data source depends on:

� the operating environment, and in some cases the platform, as specified inthe previous table

� whether your site has a license to SAS/ACCESS Interface for PC Files. If youdo not have a license, only delimited files are available

When you specify a value for DBMS=, consider the following for specific datasources:

� Microsoft Access 2000, 2002, and 2003 share the same internal file formats. TheSAS LIBNAME engine recognizes ACCESS2000, ACCESS2002, ACCESS2003,and ACCESS2007 as aliases for the identifier ACCESS. The file that is exportedfrom SAS can be read by any of these versions of Microsoft Access.

� Microsoft Excel 97, 2000, 2002, and 2003 share the same internal file formats.The SAS LIBNAME engine recognizes EXCEL97, EXCEL2000, EXCEL2002,EXCEL2003, and EXCEL2007 as aliases for the identifier EXCEL. The file thatis exported from SAS can be read by any of these versions of Microsoft Excel.

� To export a data set to an existing Microsoft Access database, PROC EXPORTcan write to Access 97, Access 2000, Access 2002, or Access 2003 regardless ofyour specification. For example, if you specify DBMS=ACCESS2000 and thedatabase is in Access 97 format, PROC EXPORT exports the table, and thedatabase remains in Access 97 format.

Page 31: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Using the EXPORT Procedure � PROC EXPORT Statement 23

However, if you specify DATABASE= for an Access database .mdb file thatdoes not exist, a new database is created using the format specified in DBMS=.For example, if you specify DBMS=ACCESS to create a new file, the result is anMDB file that Access 2000, 2002, or 2003 can read, but Access 97 cannot. Formore information about DATABASE=, see “IMPORT and EXPORT ProcedureStatements for Microsoft Access” on page 49.

The following table summarizes the DBMS= specifications and indicateswhich version of Microsoft Access can open the resulting database.

Identifier Access 2000, 2002, 2003 Access 97

ACCESS yes no

ACCESS97 yes yes

ACCESS 2007 yes yes

ACCESS 2007Restriction: Only Access 2007 and above can open Access 2007 formats.Feature: Access 2007 can open all previous formats

� To export a Microsoft Excel spreadsheet, PROC EXPORT creates an XLS file forthe specified version. This table summarizes the DBMS= specifications andindicates which version of Microsoft Excel can open the resulting spreadsheet:

Identifier Excel 2007 Excel 97, 2000,2002, 2003

Excel 5.0,95

Excel 4.0

XLS no yes yes no

EXCEL no yes no no

EXCEL5 no yes yes no

EXCEL4 no yes yes yes

EXCELRestriction: Only Excel 2007 and above can open Excel 2007 formats.Feature: Excel 2007 can open all previous formats. Later versions of Excel

can open and update files in previous formats.� Missing values are translated to blanks when you export a SAS data set to a

dBASE file (DBF) if the data set does not contain character or numeric values.� Due to dBASE limitations, values for a character variable that are longer than

256 characters are truncated in the resulting dBASE file when you export aSAS data set to a dBASE file (DBF).

REPLACEoverwrites an existing file. Note that for a Microsoft Access database or an Excelworkbook, REPLACE overwrites the target table or spreadsheet. If you do notspecify REPLACE, PROC EXPORT does not overwrite an existing file.

LABELwrites SAS label names as column names to the exported table. If SAS label namesdo not exist, then the variable names are used as column names in the exported table.Alias: DBLABELRequirement: When you export a DBMS table, you must specify the DBMS= option.

Page 32: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

24

Page 33: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

25

C H A P T E R

6File Format-Specific Referencefor IMPORT and EXPORTProcedures

Delimited Files 26Delimited File Essentials 26

IMPORT and EXPORT Procedure Statements for Delimited Files 27

Examples of Importing and Exporting Delimited Files 29

Example 1: Import CSV data into SAS 29

Example 2: Import Space-Separated Data Values into SAS 29Example 3: Export a SAS Data Set to a CSV File 29

Example 4: Import a Subset of CSV Data into SAS 30

Accessing Data in Microsoft Access Database Files and Excel Workbook Files 30

Microsoft Excel Workbook Files 31

Microsoft Excel Files Essentials 31

Excel Data Types 32Supported SAS Import and Export Components for Excel 33

Overview: Components for Excel 33

Import and Export Microsoft Excel Files Using the LIBNAME Statement 33

Examples of Importing and Exporting Excel Data 41

Importing and Exporting Microsoft Excel Files Using PROC ACCESS and PROCDBLOAD 42

Examples of Importing and Exporting Excel 4 and Excel 5 Files 43

Import and Export Microsoft Excel Files Using XLS File Formats 43

Examples of Importing and Exporting XLS Files 46

Microsoft Access Database Files 47Microsoft Access File Essentials 47

Microsoft Access Database Data Types 47

IMPORT and EXPORT Procedure Statements for Microsoft Access 49

Examples of Importing and Exporting Microsoft Access Files 53

Example 1: Import a SAS Data Set from a Microsoft Access 2007 Database Table 53

Example 2: Export a SAS Data Set and Create a New Microsoft Access Database File 53Example 3: Import a Data Set from a Microsoft Access Database File Using a Read

Buffer 54

Example 4: Export a SAS Data Set to a Microsoft Access Database File on a PC FilesServer 54

Lotus 1-2-3 WKn Files 54WKn Files Essentials 54

WKn Data Types 56

Supported Import and Export Components and Statements for WKn Files 56

Examples of Importing and Exporting WKn Files 57

Example 1: Export a SAS Data Set to a WK4 File 57Example 2: Import Data from a SAS Data Set from a WK4 File 58

Example 3: Export Data to a WK1 File from a SAS Data Set 58

Example 4: Import Data from a WK1 File into a SAS Data Set 58

Page 34: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

26 Delimited Files � Chapter 6

dBase DBF Files 58DBF Files Essentials 58

DBF Data Types 59

Setting Environment Variables and System Options 60

Supported SAS IMPORT/EXPORT Procedure Statements 61

Examples of Importing and Exporting DBF Files 62Example 1: Export Data to a DBF File from a SAS Data Set 62

Example 2: Import Data from a DBF File into a SAS Data Set 62

Example 3: Export Data to a DBF File from a SAS Data SAS Using Encoding 62

Example 4: Import and Translate Data from a DBF File 62

dBase DBFMEMO Files 63

Example of Importing DBF File with Memo Field 63Example 1: Import Data from a DBF File with Memo Field into a SAS Data Set 63

JMP Files 63

JMP Files Essentials 63

JMP Missing Values 63

JMP Data Types 64Importing and Exporting Data in JMP Files 65

Examples of Importing and Exporting JMP Files 65

Example 1: Export a SAS Data Set to a JMP File 65

Example 2: Import a SAS Data Set from a JMP File 66

Examples of Importing and Exporting JMP Files Using a PC Files Server 66Example 1: Export a SAS Data Set on UNIX to a JMP File on Microsoft Windows 66

Example 2: Import Data from a JMP File on Microsoft Windows to a SAS Data Set onUNIX 66

Paradox DB Files 66

Paradox File Essentials 66

Examples of Importing and Exporting Paradox DB Files 67Example 1: Export a SAS Data Set to a Paradox DB File 67

Example 2: Import a SAS Data Set from a Paradox DB File 67

SPSS SAV Files 67

SAV File Essentials 67

SPSS Data Types 67Examples of Importing and Exporting SPSS SAV Files 69

Example 1: Export a SAS Data Set to an SPSS SAV File 69

Example 2: Import a SAS Data Set from an SPSS SAV File 69

Stata DTA Files 69

DTA Files Essentials 69DTA Data Types 69

Examples of Importing and Exporting Stata DTA Files 71

Delimited Files

Delimited File EssentialsIn computer programming, a delimited text file is a flat file that contains data that is

separated by a delimiting character called a delimiter. A delimiter defines thebeginning or end of a contiguous string of character data. The delimiter is notconsidered part of the character data string. A delimited text file is also called adelimiter-separated values (DSV or DLM) file.

Page 35: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � IMPORT and EXPORT Procedure Statements for Delimited Files 27

A comma-separated values (CSV) file is a form of delimited file where the delimiter isa comma. A TAB file is a form of delimited file where the delimiter is a tab character.Files that have other delimiters such as spaces ( ) or semicolons (;) are also known asdelimited text files, or delimited files.

In a delimited text file, the first row of data is normally read as column names. Thecolumn names are then used as SAS variable names. A line character indicates a newrow. A CSV file might contain lines of data similar to these:

First,Last,AgeAbraham,Howard,31Smith,Jack,24Chen,Jo,38

The Import and Export wizards and procedures use SAS External File Interfacecomponents to read and to write data in delimited external files.

The delimited file component is included in Base SAS and does not require a licensefor SAS/ACCESS Interface to PC Files. Be aware of these behaviors when using thesewizards and procedures to import or export data in a delimited external file.

� When data values are enclosed in quotation marks, delimiters within the value aretreated as character data. Quotation marks are removed from character values.

� Two consecutive delimiters indicate a missing value.� A delimiter can be specified as one or more characters and can be in binary form.

Here is an example: delimiter=’09’X.� While exporting data with PROC EXPORT, items that exceed the output line

length are discarded. See the DROPOVER option of the FILE statement in SASLanguage Reference: Dictionary.

� As PROC IMPORT reaches the end of the current input data record, variableswithout any values assigned are set to missing.

For more detailed information about general syntax, see these topics:� Chapter 3, “Using the SAS Import and Export Wizards,” on page 11� Chapter 4, “Using the IMPORT Procedure,” on page 13� Chapter 5, “Using the EXPORT Procedure,” on page 19� “Using the External File Interface (EFI)” on page 11

IMPORT and EXPORT Procedure Statements for Delimited FilesThis table lists the statements that are available to process delimited text external

files using the IMPORT and EXPORT procedures. Data source files consist ofCSV=comma-separated values files, TAB=tab-separated values files, DLM=delimiterseparated values files. See “Examples of Importing and Exporting Delimited Files” onpage 29.

Table 6.1 IMPORT and EXPORT Procedure Statements for Delimited Files

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

DATAROW= 1 to 2147483647 2 Yes No

GETNAMES= YES | NO YES Yes No

GUESSINGROWS= 1 to 2147483647 20 Yes No

CSV

PUTNAMES= YES | NO YES No Yes

Page 36: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

28 IMPORT and EXPORT Procedure Statements for Delimited Files � Chapter 6

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

DATAROW= 1 to 2147483647 2 Yes No

GETNAMES= YES | NO YES Yes No

GUESSINGROWS= 1 to 2147483647 20 Yes No

TAB

PUTNAMES= YES | NO YES No Yes

DATAROW= 1 to 2147483647 2 Yes No

DELIMITER= ’char’ | ’nn’x ’ ’ Yes Yes

GETNAMES= YES | NO YES Yes No

GUESSINGROWS= 1 to 2147483647 20 Yes No

DLM

PUTNAMES= YES | NO YES No Yes

DATAROW=1 to 2147483647;starts reading data from the specified row number in the delimited text externalfile. When GETNAMES=YES (default for GETNAMES=), the default value is 2and you can specify only a value equal to or greater than 2. WhenGETNAMES=NO, the default value is 1.

DELIMITER=’char’ | ’nn’x;specifies the delimiter that separates columns of data in the imported or exportedfile. You can specify the delimiter as a single character or as a hexadecimal value.For example, if columns of data are separated by an ampersand, specifyDELIMITER=’&’. If you do not specify DELIMITER=, PROC IMPORT assumesthat the delimiter is a blank character.

GETNAMES=YES | NO;determines whether to generate SAS variable names from the data values in thefirst record of the imported file.

If a data value in the first record that is read contains special characters thatare not valid in a SAS name (such as a blank), SAS converts the character to anunderscore. For example, the column name Occupancy Code would become theSAS variable name Occupancy_Code.

YES specifies that PROC IMPORT is to generate SAS variablenames from the data values in the first record of the importedfile.

NO specifies that PROC IMPORT is to generate SAS variablenames as VAR1, VAR2, VAR3, and so on.

GUESSINGROWS=1 to 2147483647;specifies that the number of rows in the delimited text file to scan to determine theappropriate data type for the columns. The scan process scans from Row 1 to thenumber that is specified by GUESSINGROWS=. The default value is 20. However,you could change the default value in the SAS registry. To do this from the SASmenu, select Solutions � Accessories � Registry Editor. From the RegistryEditor that opens, select Products � BASE � EFI � GuessingRows.

PUTNAMES=YES | NO;determines whether to write SAS variable names to the first record of the exporteddata file. If you specify the LABEL option, SAS variable labels are written insteadof variable names.

Page 37: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Examples of Importing and Exporting Delimited Files 29

YES specifies that PROC EXPORT is to write SAS variable namesto the first record and write the first observation data to thesecond record of the exported data file.

NO specifies that PROC EXPORT is to write the first observationdata to the exported data file.

Examples of Importing and Exporting Delimited Files

Example 1: Import CSV data into SASThis example uses the first row of data for SAS variable names, reads data in from

Row 2, and scans 10 rows of data to determine data types for each column.

PROC IMPORT OUT=WORK.TESTFILE="&dlmdir.\invoice.csv"DBMS=CSV REPLACE;

GETNAMES=YES;DATAROW=2;GUESSINGROWS=10;

RUN;

Example 2: Import Space-Separated Data Values into SASIn this example, SAS generates such variable names as VAR1 and VAR2, reads data

starting from Row 2, and scans the default number of rows (20) to determine the datatypes for each column. ’20’x is the hexadecimal value for a blank character (space) inASCII code.

PROC IMPORT OUT=WORK.TESTDATAFILE="&dlmdir.\invoice.txt"DBMS=DLM REPLACE;

DELIMITER=’20’x;GETNAMES=NO;DATAROW=;

RUN;

Example 3: Export a SAS Data Set to a CSV FileThis example exports the SAS data set, SDF.INVOICE, to a CSV file named

invoice.csv. Instead of writing column names to the first row of data, it exports dataonly to the output file.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.INVOICE

OUTFILE="c:\temp\invoice.csv"DBMS=DLM REPLACE;

DELIMITER=’,’;PUTNAMES=NO;

RUN;

Page 38: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

30 Accessing Data in Microsoft Access Database Files and Excel Workbook Files � Chapter 6

Example 4: Import a Subset of CSV Data into SASThis example reads in data from Rows 6-10 of the selected columns in the

customer.csv file. It uses the global OBS= option to limit the number of data rows toimport and OBS=MAX to reset the option to the default value.

OPTIONS OBS=10;PROC IMPORT OUT= WORK.Test (KEEP=Customer_ID Name Address First-Ordered_Date

DATAFILE= "&dlmdir.\customer.csv"DBMS=CSV REPLACE;

GETNAMES=YES;DATAROW=6;

RUN;OPTIONS OBS=MAX;

Accessing Data in Microsoft Access Database Files and ExcelWorkbook Files

SAS uses Microsoft Data Access Components (MDAC) and Microsoft Jet enginesoftware to access Microsoft Access database files (.md and .accdb) and Excel workbookfiles (.xls, xlsb, xlsm, and .xlsx). Microsoft provides only 32–bit Windows versions of theMicrosoft Jet and Microsoft Ace engines.

If you are running SAS on 32–bit Windows system, you can use the ACCESS or EXCELLIBNAME engines to access data in Microsoft Access or Microsoft Excel files. The PCFiles engine can also read, and update .xlsx files. It always exports the new file as withan .xlsb file extension. Excel users can also use the DBMS=XLS engine to access datain an Excel .xls file. The XLS engine does not require the Microsoft Jet or Microsoft Aceengine. It is available for SAS running on any Windows, UNIX, or Linux operatingsystem.

If you are running SAS on UNIX, Linux, or 64–bit Windows system, you must usethe PCFILES LIBNAME engine and also have the SAS PC Files Server installed andrunning on a 32– bit Windows system.

This table shows you the engines and components that are available to use in variousconfigurations of SAS software, operating systems, and processors.

Page 39: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Microsoft Excel Files Essentials 31

Table 6.2 Accessing Data in Microsoft Access Database Files and Excel WorkbookFiles

ProcessorOperating

SystemSAS

LIBNAMEEngine

PROC IMPORT/EXPORT

Requiresa PCFiles

Server?

X86

X64

32-bitWindows

32-bitASCESS

EXCEL

DBMS_ACCESS

DBMS=ACCESS97

DBMS=EXCEL

No

X6464-bit

Windows32-bit

ACCESS

EXCEL

DBMS_ACCESS

DBMS=ACCESS97

DBMS=EXCEL

No

X64

IPF

64-bitWindows

64–bitACCESS

EXCEL

DBMS_ACCESS

DBMS=ACCESS97

DBMS=EXCEL

Yes

Note: x86 represents traditional 32-bit processors from Intel and AMD. X64 represents 64-bitextended systems from AMD and Intel. IPF represents the Intel Itanium 64-bit processor family.

Microsoft Excel Workbook Files

Microsoft Excel Files EssentialsSAS/ACCESS Interface to PC Files works with Microsoft Excel workbook 5, 95, 97,

2000, 2002, 2003, 2007. Throughout this document these files are collectively referredto as .xls files, except for version 2007. Microsoft Excel workbook 2007 file formats arereferred to as .xlsb, .xlsm, or .xlsx files. Files that are created with Excel 2007 cancreate and work with all Excel file formats.

An Excel file represents an Excel workbook. An Excel workbook is a collection ofworksheets. A worksheet that was created with a version before Excel 2007 can containup to 256 columns and 65,536 rows in an .xls file.

Excel 2007 has been enhanced to support 16,384 columns and 1,048,576 rows in aworksheet. Files that are created with Excel 2007 can have an .xlsb, .xlsx, or.xlsmextension.

A cell is the intersection of a column and a row. It is referenced by a column numberand a row number; for example, B5. A cell is the basic unit that saves data in theworksheet. A cell can contain a numeric value or a text value of up to 32,767 characters.

A range is a subset of cells in a worksheet. Its address identifies it: It begins withthe name of the top-left cell and ends with the name of the bottom-right cell, separatedby two periods. For example, the range B2..E8 is the range address for a rectangularblock of 12 cells, where the top-left cell is B2 and the bottom-right cell is E8 (shown asshaded, below). A range name identifies a range.

Page 40: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

32 Excel Data Types � Chapter 6

Display 6.1 A Range of Data in an Excel Worksheet

SAS/ACCESS Interface to PC Files treats an Excel workbook as a database, and arange as a table. A range name must be defined in the Excel file before SAS can use it.A worksheet is treated as a special range. A worksheet name appended with a $character is treated as a range.

For example, Sheet1 is a sheet name in an Excel file. SAS treats Sheet1$ as a validrange name and uses it to refer to the whole worksheet. You need to use SAS n-literalwhen referring to the sheet name, for example, ’Sheet1$’n. The first row of data in arange is normally treated as a column name and is used for SAS variables name.

� For Excel 4 files, only one spreadsheet is allowed per file.� Microsoft Excel 4, Excel 5, and Excel 95 limits are 256 columns, 16,384 rows.� Microsoft Excel 97, 2000, 2002, 2003 limits are 256 columns, 65,536 rows� Microsoft Excel 2007 limits are 16,384 columns, 1,048,576 rows.� Excel 95 files are treated as the same format as Excel 5 files.� Excel 2000, 2002, and 2003 files are treated as the same format as Excel 97 files.� Excel 2007 are treated as a unique format. See “Microsoft Excel Files Essentials”

on page 31

Excel Data TypesMicrosoft Excel software has two data types: character and numeric. Microsoft Excel

character data can be entered as labels or formula strings; Microsoft Excel numericdata can be entered as numbers or formulas.

Character data is generally considered text and can include character type dates andnumbers. A cell can save up to 32,767 characters.

Numeric data can include numbers (0 through 9), formulas, or error values (such as#NULL!, #N/A, #VALUE!).

Numeric data can also include date and time values. The conversion of date and timevalues between SAS data sets and Microsoft Excel spreadsheets is transparent to users.However, you are encouraged to understand the differences between them.

Page 41: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Supported SAS Import and Export Components for Excel 33

In Microsoft Excel software, a date value is the integer portion of a number that canrange from 01 January 1900 (saved as integer value: 1) to 31 December 9999 (saved asinteger value: 2,958,465). A Microsoft Excel software time value is the decimal portionof a number that represents time as a proportion of a day. For example, 0.0 is midnight,0.5 is noon, and 0.999988 is 23:59:59 (on a 24-hour clock). While a number can haveboth a date and a time portion, the formats in Microsoft Excel display a number in adate, time, or date/time format.

In SAS software, SAS dates are valid back to AD 1582 and ahead to AD 9,999. Adate value is represented by the number of days between January 01, 1960, and thatdate. A time value is represented by the number of seconds between midnight and thattime of day. A datetime value is represented by the number of seconds betweenmidnight January 01, 1960, and that datetime.

When you export a SAS time value to an Excel file, the value could be displayed as“1/0/1900” in the Excel software. You need to format the cell with a Time format to seethe time value displayed correctly.

Supported SAS Import and Export Components for Excel

Overview: Components for ExcelSAS import and export utilities provide three components to access Microsoft Excel

files.

LIBNAMEstatement

generates a LIBNAME statement for the PC files engine and alsogenerates PROC SQL code to read data from or write data to anExcel file. This component supports Excel versions 5/95, 97, 2000,2002, 2003, and 2007. For details about available statements, see“Import and Export Microsoft Excel Files Using the LIBNAMEStatement” on page 33

ACCESS andDBLOADprocedures

generates PROC ACCESS code to read from or PROC DBLOAD codeto write data to an Excel file. This component supports only Excelversions 4 and 5/95. This is for SAS 6 compatibility support and isavailable only on Microsoft Windows. For details about availablestatements, see “Importing and Exporting Microsoft Excel FilesUsing PROC ACCESS and PROC DBLOAD” on page 42

XLS file formats translates Excel .xls file formats so you can read data from or writedata to an Excel file. This component supports Excel versions 5/95,97, 2000, 2002, and 2003. For details about available statements,see “Import and Export Microsoft Excel Files Using XLS FileFormats” on page 43.

Note: This component does not support V 2007 .xlsb or .xlsxfiles. �

Import and Export Microsoft Excel Files Using the LIBNAME Statement

The LIBNAME statement component for importing and exporting Microsoft Excelworkbook data generates SAS LIBNAME statement code. The LIBNAME statementuses the Microsoft Ace or Microsoft Jet engine to access data in Microsoft Excelworkbook files.

Page 42: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

34 Supported SAS Import and Export Components for Excel � Chapter 6

This table lists the LIBNAME statement options that are available to import datafrom or export data to an Excel file. See “Examples of Importing and Exporting ExcelData” on page 41.

Table 6.3 Available Statements for Importing and Exporting Excel Files Using aLIBNAME Statement on Microsoft Windows

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

DBDSOPTS= ’Excel data setoptions’

Yes Yes

DBSASLABEL= COMPAT |NONE

COMPAT Yes No

GETNAMES= YES | NO YES Yes No

MIXED= YES | NO NO Yes No

NEWFILE= YES | NO NO No Yes

RANGE= “range name” Yes No

SCANTEXT= YES | NO YES Yes No

SCANTIME= YES | NO YES Yes No

SHEET= “sheet name” Yes Yes

TEXTSIZE= 1 to 32767 1024 Yes No

EXCEL

EXCEL97

EXCEL2000

EXCEL2002

EXCEL2003

EXCEL2007

USEDATE= YES | NO YES Yes No

This table lists the statements that are available to import data from or export datato an Excel file using a LIBNAME statement on Linux, UNIX, and Microsoft Windows64-bit operating platforms. This component requires that the PC Files Server isrunning on a Microsoft Windows operating platform where the PC files reside.

Page 43: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Supported SAS Import and Export Components for Excel 35

Table 6.4 Available Statements for Importing and Exporting Excel Files Using aLIBNAME Statement on a PC Files Server

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

DBDSOPTS= ’Excel data setoptions’

Yes Yes

DBSASLABEL= YES | NO YES Yes No

PORT= 1 to 65535 Yes Yes

RANGE= “range name” Yes No

SCANTEXT= YES | NO YES Yes No

SCANTIME= YES | NO YES Yes No

SERVER= ’server name’ Yes Yes

SERVICE= ’service name’ Yes Yes

SHEET= “sheet name” Yes Yes

TEXTSIZE= 1 to 32767 1024 Yes No

USEDATE= YES | NO YES Yes No

EXCELCS

VERSION= ’5’ | ’95’ | ’97’ |’2000’ | ’2002’ |’2003’ | ’2007’

’97’ Yes Yes

DBDSOPTS=’any data set options that are valid for the Excel LIBNAME engine’enables you to take advantage of useful data set options for the LIBNAME enginesuch as READBUFF=, INSERTBUFF=, DBTYPE=, DROP=, FIRSTOBS=, andOBS=. These options are for advanced users who are familiar with the PC filesLIBNAME engine.

You must surround the options in single quotation marks. Here is an example:DBDSOPTS=’FIRSTOBS=10 READBUFF=25’;.

If the option string that you are specifying contains single quotations marks,use double quotation marks around it in your statement. Here is an example:DBDSOPTS="DBTYPE=(BilledTo=’CHAR(8)’)";.

See “Data Set Options for PC Files on Microsoft Windows” on page 93 and “DataSet Options for PC Files on Linux and UNIX” on page 159 for a list of supporteddata set options.

Note: For UNIX users who use the client/server model with an Excelworkbook, the default value for READBUFF= is 1. To improve performance forreading data, set READBUFF= to 25 or higher. �

DBSASLABEL=COMPAT | NONE | YES | NO;specifies the data source column names.

(COMPAT/)YES specifies that the data source column names are saved as thecorresponding SAS label names. YES is an alias of COMPAT.

(NONE/)NO specifies that the data source column names are not saved asSAS label names. The SAS label names are then left as blanks.NO is an alias of NONE.

GETNAMES=YES | NO; (available only for DBMS=EXCEL)determines whether to generate SAS variable names from the data values in thefirst record of the imported Excel file.

Page 44: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

36 Supported SAS Import and Export Components for Excel � Chapter 6

If a data value in the first record for the input file is read and it contains invalidspecial characters in a SAS name, such as a blank; SAS converts the character toan underscore. For example, the column name Occupancy Code becomes the SASvariable name Occupancy_Code.

YES specifies that PROC IMPORT generate SAS variable namesfrom the data values in the first record of the imported Excelfile.

NO specifies that PROC IMPORT generate SAS variable names asF1, F2, F3, and so on.

MIXED=YES | NO; (available only for DBMS=EXCEL)specifies whether to convert numeric data values into character data values for acolumn that contains mixed data types. This option is valid only when you import(read) data from Excel. The Microsoft Ace or Microsoft Jet engine handles thisoption. The default is NO.

YES assigns a SAS character type for the column and converts allnumeric data values to character data values when mixed datatypes are found. When you specify MIXED=YES, theconnection is set in import mode and no updates are allowed.

CAUTION:Due to a limitation in the Microsoft Ace or Microsoft Jet Excelengine, using MIXED=YES could result in improper text variablelengths. �

NO assigns numeric or character type for the column, depending onthe majority of the type data that is found. Both numeric datain a character column and character data in a numeric columnare imported as missing values.

These registry settings can affect the behavior of the MIXED= option. They arelocated in theHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\AccessConnectivity Engine\Engines\Excel key of the Microsoft Windows registry.

Page 45: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Supported SAS Import and Export Components for Excel 37

Table 6.5 Registry Settings for the MIXED Option

TypeGuessRows an integer type with a default value of 8. You can use the number ofrows in the worksheet range in scans to determine column types. Ifyou set this type to 0, all rows in the range are checked. Microsoftstates that the valid range of TypeGuessRows is 0–16. However,you could set as high as 16384, and it would still operate correctly.

CAUTION:Changing the TypeGuessRows value cause a scan to fail ifyou set it higher than 16384. It also affects any softwarethat uses the Microsoft Ace provider to access Excel filedata, including accessing Excel data in a Microsoft Accessdatabase. The TypeGuessRows value is registered withand controlled by Microsoft. It is recommended that youset the value to 0. �

ImportMixedTypes a string type with a default value of Text. If a column contains morethan one type of data while scanning TypeGuessRows rows, thecolumn type is determined to be Text if the setting value is Text. Ifthe setting value is Majority, the most common column typedetermines the column type.

For the MIXED=YES option to work correctly, you should youchange TypeGuessingRows to 0 in the Microsoft Windows registryso that all rows in the specified range are scanned. As a result,when you use MIXED=YES, the Microsoft Ace and Microsoft Jetengines always assigns character type for columns with data ofmixed data types. The numeric data is converted to character data.

NEWFILE=YES | NO; (available only for DBMS=EXCEL)when exporting a SAS data set to an existing Excel file, specifies whether to replacethe previous Excel file. This statement is valid only when DBMS=EXCEL is used.

YES specifies that PROC EXPORT deletes the specified Excel file, ifit exists, and loads the SAS data set to a sheet in the newlycreated Excel file.

NO specifies that PROC EXPORT loads the SAS data set to a sheetand append it to the existing Excel file. If the specified Excelfile does not already exist, it is loaded to a sheet in the newlycreated Excel file.

PORT= port-number; (available only for Client Server Model)specifies the number of the port that is listening on the PC Files Server. The validvalue is between 1 and 65535. This port or service name displays on the PC FilesServer control panel screen when it is started on the PC. This PORT= statementand the SERVICE= statement should not be used in the same procedure. Thedefault value is 8621. Alias: PORT_NUMBER=.

RANGE="range-name" | "absolute-range"; (valid only for PROC IMPORT)subsets a spreadsheet by identifying the rectangular set of cells to import from thespecified spreadsheet. The range name is a name that the user defined in thespreadsheet to represent a range of cells within the spreadsheet in the Excel file.The range name is not case sensitive and does not allow any special characterexcept underscore.

When data is imported from an Excel file, a sheet name that is appended with a$ character is treated as a range name, which refers to the whole sheet. You can

Page 46: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

38 Supported SAS Import and Export Components for Excel � Chapter 6

use PROC DATASETS to list the available data set names, which are mapped tothe range names in the Excel file. If the displayed range name contains singlequotes, keep the single quotes as part of the range name to access the sheet. Forexample, here is how you can retrieve data from the spreadsheet for two separatesheet names, My#Test and CustomerOrders:

RANGE="’My#Test$’";RANGE="’ CustomerOrders$’";

Absolute range identifies the top-left cell that begins the range and thebottom-right cell that ends the range. For example, C2:F12 represents cells withinColumn C, Row 2, and Column F, Row 12. Here is another example:

RANGE="’summary$a4:b20’";

In this example, $ defines the end of the sheet name, and the colon (:) separatesthe values for the upper left (UL) and lower right (LR) of the cell range. If thisstatement is not specified, PROC IMPORT reads the entire spreadsheet as a range.

If the range name is available, it is recommended that you use RANGE= optionwithout the SHEET= option for PROC IMPORT. To use the absolute rangeaddress, it is strongly recommended that you use the full range address withquotes. For example, specify ’sheet_name$A1:C7’n. Use SHEET= only when youwant to access the whole sheet.

SCANTEXT=YES | NO;specifies whether to scan the column to determine the length of the text data foreach data source column. This option applies only to character data type columns.Alias: SCAN_TEXT, SCANMEMO.

YES scans the length of text data for a data source column and usesthe length of the longest string of data that it finds as the SASvariable width. If the maximum length that it finds is greaterthan the value in the TEXTSIZE= option, the smaller value inTEXTSIZE= is applied as the SAS variable width.

NO does not scan the length of text data for a data source column.The column length returned from the Microsoft Ace orMicrosoft Jet engine is used as the SAS variable width. If thereturned column width is greater than what is specified in theTEXTSIZE= option, the smaller value specified in TEXTSIZE=is applied as the SAS variable width.

Specify SCANTEXT=NO when you need to update data in aMicrosoft Excel workbook.

To correct truncated text data for DBCS users (including Chinese, Japanese,and Korean), you can set the environment variable DBE_DBCS to YES. Thisdoubles the scanned text data length and therefore corrects the problem oftruncated text data. To set the DBE_DBCS environment variable, submit thisstatement: Options set=DBE_DBCS YES;.

The Microsoft Ace or Microsoft Jet engine handles the SCANTEXT= option.These registry settings could affect the behavior of the SCANTEXT= option.

These are located in theHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\AccessConnectivity Engine\Engines\Excel key of the Microsoft Windows registry.

Page 47: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Supported SAS Import and Export Components for Excel 39

Table 6.6 Registry Settings for the SCANTEXT Option

TypeGuessRows an integer type with a default value of 8. The number of rows in theworksheet range is used to scan to determine column types. If set to0, all rows in the range are checked. Microsoft states that the validrange of TypeGuessRows is 0 to 16. However, it could be set as highas 16384 and still operate correctly.

ImportMixedTypes a string type with a default value of Text. If a column contains morethan one data type when scanning of TypeGuessRows rows, thecolumn type is determined to be Text if the setting value is Text. Ifthe setting value is Majority, the most common column typedetermines the column type.

So that the SCANTEXT=YES option works correctly, it is strongly recommendedthat you change TypeGuessingRows to 0 in the Microsoft Windows registry so thatall rows in the specified range are scanned. As a result, when you useSCANTEXT=YES, the Microsoft Ace or Microsoft Jet engine always assignscharacter type for columns with mixed data types. The numeric data is convertedto character data.

To change the value of TypeGuessRows, follow these steps in Microsoft Windows:1 Start � Run

In the Run window dialog box, type Regedt32 and select OK.2 Open this key in the Registry Editor window:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\AccessConnectivity Engine\Engines\Excel

3 Double-click TypeGuessRows.4 In the Edit DWORD dialog box under Base, select Decimal, enter 0 in the

Value field, and select OK.5 Exit from the Registry Editor window.

SCANTIME=YES | NO;specifies whether to scan the date/time data while importing data from a date/timecolumn from the Microsoft Excel workbook.

YES scans the date/time column and assigns the TIME. format for adate/time column only if time values are found in the column.

NO specifies not to scan the date/time column. The DATETIME.format is assigned for a date/time column if USEDATE=NO.The DATE. format is assigned for a date/time column ifUSEDATE=YES.

SERVER= "PC-server-name"; (available only for Client Server Model)specifies the name of the PC Files Server. You must bring up the listener on thePC Files Server before you can establish a connection to it. You can configure theservice name, port number, maximum number of connections allowed, and use ofdata encryption on your . This is a required statement. For more information, seePC Files ServerChapter 11, “The PC Files Server on 32-Bit Microsoft Windows,”on page 139. Alias: SERVER_NAME=.

SERVICE= "service-name";.(available only for Client Server Model)specifies the service name that is defined on your service file for your client andserver machines. This port number or service name is displayed on the PC Files

Page 48: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

40 Supported SAS Import and Export Components for Excel � Chapter 6

Server control panel screen when it is started on the PC. This statement and thePORT= statement should not be used in the same procedure. The service nameneeds to be defined on your UNIX machine and your PC Files Server. Alias:SERVICE_NAME=.

SHEET="sheet-name" |"sheetname" ;identifies a particular spreadsheet in an Excel workbook. If the "sheet-name"contains a special character such as space in PROC EXPORT, SAS converts it intoan underscore. For example, a sheet name “Employee Information” becomes’’Employee_Information”.

If your sheet name contains special characters, use PROC DATASETS to list theavailable data set names. If the sheet name shown contains single quotes, keepthe single quotes as part of the sheet name in order to be able to access the sheet.For example, specify SHEET="’My#Test’";.Restriction: Avoid sheet-names that look like cell references, which have <1–3

characters> plus 1 or more digits. For example, A1, IV65536, TRY123,XFD1048576.

If both the range name and the sheet name are missing, PROC IMPORT reads thefirst spreadsheet in the workbook. If you do not specify this statement, PROCIMPORT reads the first spreadsheet that was physically saved in the Excel file. Tomake sure that PROC IMPORT reads the data that you want, identify thespreadsheet by specifying the range name (RANGE=) or the sheet name(SHEET=). It is recommended that you use RANGE= without SHEET= in PROCIMPORT. Use SHEET= only when you want to import the entire spreadsheet. Ifthe sheet name contains special characters, you can use instead of SHEET= toimport data. See RANGE= for details.

If you do not specify this statement, PROC EXPORT writes the spreadsheetname as the SAS data set name.

Excel supports spreadsheet names up to 31 characters. SAS supports data setnames up to 32 characters.

TEXTSIZE=1 to 32767;specifies the maximum variable length in SAS that is allowed while importing datafrom Microsoft Excel text columns. Any text data in Excel whose length exceedsthis value is truncated when it is imported into SAS. Alias: DBMAX_TEXT=.

USEDATE=YES | NO;specifies whether to assign a DATE or a DATETIME format while importing adate/time column from a Microsoft Excel workbook. To assign the appropriateTIME format, see the SCANTIME= statement. For processing date/time valuesbetween SAS and Microsoft Excel, see “Processing Date/Time Values between SASand Microsoft Excel” on page 132.

YES assigns the DATE format for the corresponding date/timecolumn in the Microsoft Excel table.

NO assigns the DATETIME format for the corresponding date/timecolumn in the Microsoft Excel table.

VERSION=’file-version’;.(available only for Client Server Model)specifies the version of the file that you want to create if the file does not exist onyour PC Files Server yet. Valid values are 2007, 2003, 2002, 2000, 97, 95, and 5.The default value is 97 for XLS files. Always surround the version value withsingle quotation marks. If the file already exists on the PC Files Server, thisstatement is ignored.

Page 49: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Supported SAS Import and Export Components for Excel 41

Examples of Importing and Exporting Excel DataExample 1: Export a SAS Data Set to an Excel FileThis example exports a SAS data set called SDF.ORDERS to an Excel 2007 .xlsb file

with the Orders sheet name. In this case, SHEET supports only an .xlsb file.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.ORDERS

FILE="c:\temp\demo.xlsb"DBMS=EXCEL REPLACE;

SHEET="Orders";RUN;

Example 2: Import a Range from Excel 2007 .xlsb File to a SAS Data SetThis example imports a range named INVOICE from an Excel workbook file and

performs these tasks:� uses the first row of data as column names� scans length for character type columns� assigns DATETIME. format for date/time columns� leaves SAS labels blank� limits the size of text fields to be less than or equal to 512 characters

PROC IMPORT OUT=WORK.INVOICEFILE="&demodir.demo.xlsb"DBMS=EXCEL REPLACE;

RANGE="INVOICE";GETNAMES=YES;SCANTEXT=YES;USEDATE=NO;SCANTIME=YES;DBSASLABEL=NONE;TEXTSIZE=512; /* default is 1024 */

RUN;

Example 3: Import a Range From an Excel File on a PC Files Server to a SAS DataSet

Code in this example imports a range named as Orders from an Excel file on a PCFiles Server. It assigns the DATETIME. format for date/time columns.

PROC IMPORT OUT=WORK.ORDERSDATAFILE="&pcfdir.demo.xls"DBMS=EXCELCS REPLACE;

RANGE="Orders";SERVER="&server";PORT=8621;USEDATE=NO;SCANTIME=YES;

RUN;

Page 50: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

42 Supported SAS Import and Export Components for Excel � Chapter 6

Example 4: Export a SAS Data Set to an Excel Workbook FileThis next example exports a SAS data set named SDF.CUSTOMER to an Excel

workbook file with Customer sheet name on the PC Files Server.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.CUSTOMER

FILE="c:\temp\demo.xls"DBMS=EXCELCS REPLACE;

SHEET="Customer";SERVER="&server";SERVICE=SASPCFILE;

RUN;

Importing and Exporting Microsoft Excel Files Using PROC ACCESS andPROC DBLOAD

This import/export component uses the ACCESS and DBLOAD procedures behindthe scenes to access data in Microsoft Excel files. However, it does not support Excel2007, .xlsx, .xlsb, or .xlsm files. The PROC ACCCESS and PROC DBLOAD componentis available only on Microsoft Windows.

Note: Because ACCESS and DBLOAD procedures are compatible only with SAS 6procedures, they ignore SAS system options such as VALIDVARNAME=. PROCACCESS and PROC DBLOAD have other SAS 6 limitations such as a maximum of8-byte SAS variable names and a maximum of 200-character value. �

This table lists the statements that are available to import data from or export datato an Excel file using PROC ACCESS and PROC DBLOAD. For examples of thesestatements, see “Examples of Importing and Exporting Excel 4 and Excel 5 Files” onpage 43

Table 6.7 Available Statements for Importing and Exporting Excel Files UsingACCESS and DBLOAD Procedures

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

GETNAMES= YES | NO YES Yes No

RANGE= Range Name orAbsolute Range Value,such as ’A1..C4’

Yes No

EXCEL5

SHEET= Sheet name Yes No

GETNAMES= YES | NO YES Yes NoEXCEL4

RANGE= Range Name orAbsolute Range Value,such as ’A1..C4’

Yes No

GETNAMES=YES | NO; (available only for Microsoft Windows; valid for only PROCIMPORT)

determines whether to generate SAS variable names from the data values in thefirst record of the imported Excel file.

If a data value in the first record for the input file that is read contains specialcharacters that are not valid in a SAS name (such as a blank), SAS converts thecharacter to an underscore. For example, the column name My ID becomes theSAS variable name MY_ID.

Page 51: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Supported SAS Import and Export Components for Excel 43

YESspecifies that PROC IMPORT generates SAS variable names from the datavalues in the first record of the imported Excel file.

NOspecifies that PROC IMPORT generates SAS variable names as VAR0, VAR1,VAR2, and so on.

Examples of Importing and Exporting Excel 4 and Excel 5 FilesExample 1: Export a SAS Data Set to an Excel 5 FileThis example exports a SAS data set, ORDERS, to an Excel 5 workbook file with

sheet name Sheet1.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.ORDERS

OUTFILE="c:\temp\orders.xls"DBMS=EXCEL5 REPLACE;

RUN;

Example 2: Import a SAS Data Set from an Excel 5 FileThe next example imports a SAS data set, INVOICE, from an Excel 5 workbook file,

INVOICE.

PROC IMPORT OUT=WORK.INVOICEFILE="&xls5dir.invoice.xls"DBMS=EXCEL5 REPLACE;

GETNAMES=YES;RUN;

Import and Export Microsoft Excel Files Using XLS File FormatsThis Import/Export component uses the translation engine method to read and write

XLS file formats directly. This component supports Excel versions 5/95, 97, 2000, 2002,and 2003. However, it does not support Excel 2007 .xlsx, .xlsb, or .xlsm files. It isavailable on Linux, UNIX, and Microsoft Windows operating platforms.

These tables list the statements that are available to import data from or export datato an Excel file. See “Examples of Importing and Exporting XLS Files” on page 46.

Page 52: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

44 Supported SAS Import and Export Components for Excel � Chapter 6

Table 6.8 Available Statements for Importing and Exporting Excel Files Using theTranslation Engine

DataSource

Syntax Valid Value Default Value In PROCIMPORT?

In PROCEXPORT?

ENDCOL= Last columnfor data

Last columnthat containsdata

Yes No

ENDNAMEROW= Last row forvariablenames

Same asNAMEROW

Yes No

ENDROW= Last row fordata

Last row thatcontains data

Yes No

GETNAMES= YES | NO YES Yes No

NAMEROW= First row forvariablenames

First row thatcontainsvariable names

Yes No

NEWFILE= YES | NO NO No Yes

PUTNAMES= YES | NO YES No Yes

RANGE= NAME |SHEET$UL:LR

First row Yes No

SHEET= Sheet name First sheet Yes Yes

STARTCOL= First columnfor data

Last columnthat containsdata

Yes No

XLS

STARTROW= First row fordata

First row thatcontains data

Yes No

ENDCOL=; (available only for DBMS=XLS for backward compatibility; use RANGE=instead)

specifies the last column for data. The default is the last row that contains data.

Restriction: This component (DBMS=XLS) does not support Excel 2007formats. Files with .xlsb, .xlsm, and .xlsx extensions are not supported.

ENDNAMEROW=NAMEROW; (available only for backward compatibility; useRANGE= instead)

specifies the last row for variable names. The default is the same as NAMEROW.

ENDROW=1 to 65535; (available only for backward compatibility; use RANGE=instead)

specifies the last row for data. The default is the last row that contains data.

GETNAMES=YES | NO; (available only for DBMS=XLS for backward compatibility;use RANGE= instead)

determines whether to generate SAS variable names from the data values in thefirst record of the imported file. If a data value in the first record that is readcontains special characters that are not valid in a SAS name (such as a blank),SAS converts the character to an underscore. For example, the column nameOccupancy Code would become the SAS variable name Occupancy_Code.

Page 53: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Supported SAS Import and Export Components for Excel 45

YES specifies that PROC IMPORT is to generate SAS variablenames from the data values in the first record of the importedExcel file.

NO specifies that PROC IMPORT is to generate SAS variablenames as VAR1, VAR2, VAR3, and so on.

NAMEROW=; (available only for backward compatibility; use RANGE= instead)specifies the first row for variable names. The default is the first row that containsvariable names.

NEWFILE=YES | NO; (available only for DBMS=XLS for backward compatibility;use RANGE= instead)

when exporting a SAS data set to an existing Excel file, specifies whether to replacethe previous Excel file. This statement is valid only when DBMS=XLS is used.

YES specifies that PROC EXPORT deletes the specified Excel file, ifit exists, and loads the SAS data set to a sheet in the newlycreated Excel file.

NO specifies that PROC EXPORT loads the SAS data set to a sheetand append it to the existing Excel file. If the specified Excelfile does not already exist, PROC EXPORT loads the SAS dataset to a sheet in the newly created Excel file.

PUTNAMES=YES | NO; (available only for backward compatibility; use RANGE=instead)

determines whether to write SAS variable names to the first record of the exporteddata file. If you specify the LABEL option, SAS variable labels are written insteadof variable names.

YES specifies that PROC EXPORT is to write SAS variable namesto the first record and write the first observation data to thesecond record of the exported data file.

NO specifies that PROC EXPORT is to write the first observationdata to the exported data file.

RANGE="range-name" | "absolute-range"; (valid for only PROC IMPORT)subsets a spreadsheet by identifying the rectangular set of cells to import from thespecified spreadsheet. The range name is a name that represents a range of cellswithin the spreadsheet in the Excel file. Absolute range identifies the top-left cellthat begins the range and the bottom-right cell that ends the range. For example,’C2..F12’ represents cells within Column C, Row 2, and Column F, Row 12. Youneed to specify the target sheet name with SHEET= if you use absolute range.

By default, the first row is viewed as containing variable names. IfGETNAMES=N, the column is set to the 1– or 2–letter ID and all rows are read asdata.

If you do not specify RANGE=, PROC IMPORT reads the entire spreadsheet asa range.

Use RANGE= instead of STARTCOL=, STARTROW=, ENDCOL=, ENDROW=,or any combination of these because RANGE= already contains all of these values.

SHEET="sheet-name";identifies a particular spreadsheet in an Excel workbook. Specify sheet-name toname the sheet name as output. If the sheet already exists, it is replaced. You canalso use it to append a new sheet to an existing spreadsheet.

If you do not specify this statement, PROC IMPORT reads the first spreadsheetphysically saved in the Excel file. To be certain that PROC IMPORT reads thespreadsheet that you want, specify SHEET= to identify the spreadsheet.

Page 54: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

46 Supported SAS Import and Export Components for Excel � Chapter 6

Even if you can specify the SHEET= statement in PROC IMPORT for EXCEL4,the value is ignored. Excel version 5/95 allows multiple sheets in a file. Thisexport component supports only exporting a single sheet per file.

For PROC EXPORT, if you specify the SHEET= statement, the name that theuser entered defines the sheet name and range name in the exported Excel file.The underscore character replaces the special character for both the range andsheet names. If you do not specify the SHEET= statement, the SAS data set namedefines the sheet name and range name in the exported Excel file.Restriction: Avoid SHEET=names that look like cell references. For example,

<1–3 characters> plus 1 or more digits. For example, A1, IV65536, TRY123,XFD1048576.

Restriction: You cannot insert or replace a sheet in a workbook that contains apivot table. The existing spreadsheet is scanned. If a pivot table exists, this isreported, and the worksheet is not inserted or replaced.

STARTCOL=; (available only for backward compatibility; use RANGE= instead)specifies the first column for data. The default is the first column that containsdata.

STARTROW=; (available only for backward compatibility; use RANGE= instead)specifies the first row for data. The default is the first row that contains data.

Examples of Importing and Exporting XLS FilesExample 1: Export SAS Data Sets to Excel Workbook FilesThis example exports the SDF.INVOICE and SDF.ORDERSSAS data sets to Excel

workbook files with Invoice and Orders as sheet names.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.INVOICE

FILE="&tmpdir.text.xls"DBMS=XLS REPLACE;

SHEET="Invoice";RUN;

PROC EXPORT DATA=SDF.ORDERSFILE="&tmpdir.text.xls"DBMS=XLS REPLACE;

SHEET="Orders";RUN;

Example 2: Import Data Using a Range NameThis example imports SAS data from a demo XLS file using a range name.

PROC IMPORT OUT=WORK.INVOICEFILE="&demodir.demo.xls"DBMS=XLS REPLACE;

RANGE="INVOICE";GETNAMES=YES;

RUN;

Example 3: Import Data Using an Absolute Range AddressThis example imports SAS data from a demo XLS file using an absolute range

address.

PROC IMPORT OUT=WORK.INVOICEFILE="&demodir.demo.xls"DBMS=XLS REPLACE;

Page 55: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Microsoft Access Database Data Types 47

RANGE="Invoice$B4:D10";GETNAMES=NO;

RUN;

Microsoft Access Database Files

Microsoft Access File Essentials

SAS/ACCESS Interface to PC Files works with Microsoft Access database 97, 2000,2002, 2003, and 2007 files.

Microsoft Access is a desktop relational database system that uses the Microsoft Aceor Microsoft Jet engine to store and retrieve data. A database is a collection ofinformation that is related to a particular subject or purpose, such as tracking customerorders or maintaining a music collection. All objects in a Microsoft Access database(including tables, queries, forms, and reports) are stored in the native Microsoft Jet.mdb file format or the Ace .accdb file format if the file is greater than, or equal toMicrosoft Access database 2007.

The table below lists the maximum size limits for the components of .mdb and .accdbfiles.

Table 6.9 Microsoft Access Database (.mdb and .accdb) Maximum Size Limits PerComponent

File size 2GB / 32,768 objects

Number of fields per table 255

Number of characters per text field 255

Memo field size 65535 characters

Table name size 64 characters

Field name size 64 characters

Record size 2000 characters (excluding memo and OLEobject fields) for .mdb

4000 characters (excluding memo and OLEobject fields) for .accdb

While importing data from a table, SAS converts special characters in a table nameinto underscores ( _ ) in the corresponding data set name. If a field contains specialcharacters, SAS converts them into underscores in the corresponding variable name.

Microsoft Access Database Data TypesHere is a summary of all field data types that are available in Microsoft Access, their

uses, and their storage sizes.

Text Use for text or combinations of text and numbers, such as addresses,or for numbers that do not require calculations, such as telephone

Page 56: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

48 Microsoft Access Database Data Types � Chapter 6

numbers, part numbers, or postal codes. Stores up to 255characters. The FieldSize property controls the maximum number ofcharacters that can be entered.

Memo Use for lengthy text and numbers, such as notes or descriptions.Stores up to 65,536 characters.

Number Use for data to be included in mathematical calculations, except forcalculations involving money (use Currency type). Stores 1, 2, 4, or 8bytes; stores 16 bytes for Replication ID (GUID). The FieldSizeproperty defines the specific Number type.

Date/Time Use for dates and times. Stores as 8–byte numbers.

Currency Use for currency values and to prevent rounding during calculations.Stores as 8–byte numbers with precision to four decimal places.

AutoNumber Use for unique sequential (incrementing by 1) or random numbersthat are automatically inserted when a record is added. Stores 4bytes; stores 16 bytes for Replication ID (GUID).

Yes/No Use for data that can be only one of two possible values, such as Yes/No, True/False, On/Off. Null values are not allowed. Stores 1 bit.Use -1 for Yes value and 0 for No value.

OLE Object Use for OLE objects (such as Microsoft Word documents, MicrosoftExcel spreadsheets, pictures, sounds, or other binary data) that werecreated in other programs using the OLE protocol (link). Stores upto 1 gigabyte (limited by disk space).

Hyperlink Use for hyperlinks. A hyperlink can be a UNC path (link) or a URL(link). Stores up to 64,000 characters.

Attachments[new forMicrosoft Access2007]

Use to attach images, spreadsheet files, documents, charts, andother types of supported files to records in your database.

The conversion of date and time values between SAS data sets and Microsoft Accessdatabase is transparent to users. However, you are encouraged to understand thedifferences between them.

In Microsoft Access database software, a date value is saved with the integer portionof a number that ranges from 30 December 1899 (saved as integer value: 0) to 31December 9999 (saved as integer value: 2,958,465). A Microsoft Access databasesoftware time value is the decimal portion of a number that represents time as aproportion of a day. For example, 0.0 is midnight, 0.5 is noon, and 0.999988 is 23:59:59(on a 24-hour clock). While a number can have both a date and a time portion, theformats in Microsoft Access database display a number in a date, time, or date/timeformat.

In SAS software, SAS dates are valid back to A.D. 1582 and ahead to A.D. 9,999. Adate value is represented by the number of days between January 01, 1960, and thatdate. A time value is represented by the number of seconds between midnight and thattime of day. A datetime value is represented by the number of seconds betweenmidnight January 01, 1960, and that datetime.

A date value before year 1582 is imported as a missing value in SAS. You can importa time value as a date value 30DEC1899, so make sure that you have assigned thecorrect format. Years 4000 and 8000 are considered leap years in the Microsoft Accessdatabase system. However, they are considered as a nonleap year in the SAS softwaresystem. For more information about time values, see USEDATE= and SCANTIME=.

Page 57: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � IMPORT and EXPORT Procedure Statements for Microsoft Access 49

IMPORT and EXPORT Procedure Statements for Microsoft AccessBefore you use PROC IMPORT and PROC EXPORT for Microsoft Access files, it is

helpful to be familiar with Microsoft Access file formats. Microsoft Access 2000, 2002,and 2003 share the same .mdb file formats. Access 2007 uses .accdb file formats.ACCESS2000, ACCESS2002, and ACCESS2003 are treated as aliases for Access inSAS. However, Microsoft Access 97 used different formats, which are incompatible withAccess 200x versions.

For an existing .mdb, you can specify DBMS=ACCESS on Microsoft Windowsplatforms and SAS identifies the version for you. Specify DBMS=ACCESS97 onMicrosoft Windows platforms only when you want to export and create a new .mdb filewith Microsoft Access version 97 formats.

These tables list the statements that are available to import data from an MicrosoftAccess database file using the LIBNAME statement on Microsoft Windows operatingsystem platforms. See “Examples of Importing and Exporting Microsoft Access Files” onpage 53.

Table 6.10 IMPORT and EXPORT Procedure Statements for Microsoft Access Fileson Microsoft Windows

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

DATABASE= “complete path andfilename for theMicrosoft Accessdatabase file”

Yes Yes

DBDSOPTS= ’any valid data setoptions for MicrosoftAccess database engine’

Yes Yes

DBPASSWORD= “database password” Yes Yes

DBSASLABEL= YES | NO YES Yes No

MEMOSIZE= 1 to 32767 1024 Yes No

PASSWORD= “User password” Yes Yes

SCANMEMO= YES | NO YES Yes No

SCANTIME= YES | NO YES Yes No

USEDATE= YES | NO NO Yes No

USER= “user ID” Yes Yes

ACCESS

ACCESS97

ACCESS2000

ACCESS2002

ACCESS2003

ACCESS2007

WGDB= “complete path andfilename for theWorkgroupAdministration file”

Yes Yes

On Linux, UNIX, and Microsoft Windows 64-bit operating platforms, you can use theclient/server model to access data in your .mdb file and .accdb file. For more information,see Chapter 11, “The PC Files Server on 32-Bit Microsoft Windows,” on page 139.

For an existing .mdb, you can specify DBMS=ACCESSCS when using the client/server model and SAS identifies the version of Microsoft Access for you. You can specify

Page 58: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

50 IMPORT and EXPORT Procedure Statements for Microsoft Access � Chapter 6

VERSION=’97’ when using the client/server model only when you want to export andcreate a new .mdb file with Microsoft Access version 97 formats.

Note: If the client/server model is used, the SAS client cannot access a Microsoft filewith both database password protection and user level security protection. In this case,you must choose only one security protection to be able to access your Microsoft Accessdatabase file from a SAS client. �

This table lists the statements to import data from a Microsoft Access database fileusing the client/server model. The statements are valid on Linux, UNIX, and MicrosoftWindows 64-bit operating platforms.

Table 6.11 IMPORT and EXPORT Procedure Statements for Microsoft Access Fileson Linux, UNIX, and Microsoft Windows 64-Bit

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

DATABASE= “complete path andfilename for theMicrosoft Accessdatabase file”

Yes Yes

DBDSOPTS= ’any valid data setoptions for MicrosoftAccess database engine’

Yes Yes

DBPASSWORD= “database password” Yes Yes

DBSASLABEL= YES | NO YES Yes No

MEMOSIZE= 1 to 32767 1024 Yes No

PASSWORD= “user password” Yes Yes

PORT= 1 to 65535 8621 Yes Yes

SCANMEMO= YES | NO YES Yes No

SCANTIME= YES | NO YES Yes No

SERVER= “server name” Yes Yes

SERVICE= “service name” Yes Yes

USEDATE= YES | NO NO Yes No

USER= “user ID” Yes Yes

VERSION= ’97’ |’’2000’ | ’2002’ |’2003’ | ’2007’

’2000’ Yes Yes

ACCESSCS

WGDB= “complete path andfilename for theWorkgroupAdministration file”

Yes Yes

DATABASE="database";specifies the complete path and filename of the Microsoft Access database file thatcontains the specified DBMS table. If the database name does not containlowercase characters, special characters, or national characters ($, #, or @), youcan omit the quotation marks.

Page 59: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � IMPORT and EXPORT Procedure Statements for Microsoft Access 51

SAS does not generate a default value, but you can configure one in the DBMSclient software.

DBDSOPTS= ’data set options that are valid for the Microsoft Access databaseLIBNAME engine’;

Enables you to take advantage of useful data set options for the LIBNAME enginesuch as READBUFF=, INSERTBUFF=, DBTYPE=, DROP=, FIRSTOBS=, andOBS=. This option is for advanced users who are familiar with the PC filesLIBNAME engine.

You must surround the options in single quotation marks. Here is an example:

DBDSOPTS=’FIRSTOBS=10 READBUFF=25’;

.If the option string that you are specifying contains single quotations marks,

use double quotation marks around it in your statement. Here is an example:

DBDSOPTS="DBTYPE=(BilledTo=’CHAR(8)’)";

For a list of supported data set options, please refer to “Data Set Options for PCFiles on Microsoft Windows” on page 93 or “Data Set Options for PC Files onLinux and UNIX” on page 159.

Note:� For users who use the client/server model to access data in a Microsoft Access

database, the default value for READBUFF= is 1. To improve performancefor reading data, set READBUFF= to 25 or higher.

� For users who use the client/server model to access data in a Microsoft Accessdatabase, the default value for INSERTBUFF= is 1. To improve performancefor writing data, set INSERTBUFF= to 25 or higher.

DBPASSWORD="database-file-password";enables you to access your file if you have database-level security set in your .mdbfile. A database password is case sensitive, and you can define it instead ofuser-level security. Aliases: DBPWD, DBPW.

DBSASLABEL=(COMPAT/)YES | (NONE/)NO;specifies whether the data source column names are saved as the correspondingSAS label names.

(COMPAT/)YESspecifies that the data source column names are saved as the correspondingSAS label names. YES is an alias of COMPAT.

(NONE/)NOspecifies that the data source column names are not saved as SAS labelnames and are left as nulls. NO is an alias of NONE.

MEMOSIZE=1 to 32767;Specifies the maximum variable length in SAS that is allowed while importingdata from memo columns of a Microsoft Access database table. Any memo data inMicrosoft Access database table whose length exceeds this value is truncated whenit is imported into SAS. Alias: DBMAX_TEXT=.

PORT= port-number; (available only for Client Server Model)specifies the number of the port that is listening on the PC Files Server. The validvalue is between 1 and 65535. This port or service name is displayed on the PCFiles Server control panel screen when it is started on the PC. The PORT=

Page 60: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

52 IMPORT and EXPORT Procedure Statements for Microsoft Access � Chapter 6

statement and the SERVICE= statement should not be used in the sameprocedure. The default value is 8621. Alias: PORT_NUMBER=.

SCANMEMO=YES | NO;specifies whether to scan the memo data to determine the column length for eachmemo type source column.

Note: This option applies only to memo data type columns. It does not apply totext type columns. �

YESscans the length of memo data for a data source column and uses the lengthof the longest memo text of data that it finds as the SAS variable width.However, if the maximum length that it finds is greater than the value in theMEMOSIZE= option, the smaller value in MEMOSIZE= is applied as theSAS variable width.

NOdoes not scan the length of memo data for a data source column. The columnlength returned from the Microsoft Ace or Microsoft Jet engine is used as theSAS variable width. However, if the returned column width is greater thanwhat is specified in the MEMOSIZE= option, the smaller value specified inMEMOSIZE= is applied as the SAS variable width.

Note: To correct the truncated memo data problem for DBCS users(including Chinese, Japanese, and Korean), set the environment variableDBE_DBCS to YES. This doubles the scanned memo data length andtherefore corrects the problem of truncated memo data. To set theDBE_DBCS environment variable, submit this statement: Optionsset=DBE_DBCS YES; �

SCANTIME=YES | NO;specifies whether to scan the date/time data while importing data from a date/timecolumn from the Microsoft Excel workbook.

YESscans the date/time column and assigns the TIME. format for a date/timecolumn only if time values are found in the column.

NOspecifies not to scan the date/time column. The DATETIME. format isassigned for a date/time column if USEDATE=NO. The DATE. format isassigned for a date/time column if USEDATE=YES.

SERVER= "PC-server-name"; (available only for Client Server Model)specifies the name of the PC Files Server. You must bring up the listener on thePC Files Server before you can establish a connection to it. You can configure theservice name, port number, maximum number of connections allowed, and use ofdata encryption on your PC Files Server. This is a required statement. For moreinformation, see PC Files ServerChapter 11, “The PC Files Server on 32-BitMicrosoft Windows,” on page 139.

Alias: SERVER_NAME=

SERVICE= "service-name";.(available only for Client Server Model)specifies the service name that is defined on your service file for your client andserver machines. This port number or service name is displayed on the PC FilesServer control panel screen when it is started on the PC. This statement and thePORT= statement should not be used in the same procedure. Note that this servicename needs to be defined on both your UNIX machine and your PC Files Server.

Page 61: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Examples of Importing and Exporting Microsoft Access Files 53

Alias: SERVICE_NAME=

USEDATE=YES | NO;specifies whether to assign a DATE. or a DATETIME. format while importing adate/time column from a Microsoft Excel workbook. See the SCANTIME=statement in order to assign the appropriate TIME. format.

For processing of date/time values between SAS and Microsoft Access, see“Processing Date/Time Values between SAS and Microsoft Access” on page 136.

YESassigns the DATE. format for the corresponding date/time column in theMicrosoft Excel table.

NOassigns the DATETIME. format for the corresponding date/time column inthe Microsoft Excel table.

VERSION=’file-version’; (available only for Client Server Model)specifies the version of the file that you want to create if the file does not exist onyour PC Files Server yet. Valid values are 2007, 2003, 2002, 2000, and 97. Thedefault value depends on the filename extension. Always surround the versionvalue with single quotation marks. If the file already exists on the PC FilesServer, the statement is ignored.

Examples of Importing and Exporting Microsoft Access Files

Example 1: Import a SAS Data Set from a Microsoft Access 2007 DatabaseTable

This example imports a data set named CUSTOMER from the Customers table in aMicrosoft Access database, demo.accdb. The Microsoft Access table was saved in version2007 format.

PROC IMPORT OUT=WORK.CUSTOMERDATATABLE="Customers"DBMS=ACCESS REPLACE;

DATABASE="&demodir.demo.accdb";USEDATE=YES;SCANTIME=NO;DBSASLABEL=NONE;

RUN;

Example 2: Export a SAS Data Set and Create a New Microsoft AccessDatabase File

Code in this example exports a SAS data set named EMPLOYEE and creates a newMicrosoft Access database file named test97.mdb. Note that test97.mdb does existbefore PROC EXPORT is submitted. SAS loads and names the table Employees. Itthen creates and saves it in the new file, test97.mdb, in version 97 format.

X "DEL c:\temp\test97.mdb";PROC EXPORT DATA=SDF.EMPLOYEE

OUTTABLE="Employees"DBMS=ACCESS97 REPLACE;

Page 62: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

54 Lotus 1-2-3 WKn Files � Chapter 6

DATABASE="c:\temp\test97.mdb";RUN;

Example 3: Import a Data Set from a Microsoft Access Database File Usinga Read Buffer

This example imports a data set named INVOICE from the Invoice table in aMicrosoft Access database named demo.mdb. The read buffer is set for 10 rows.

PROC IMPORT OUT=SDF.INVOICETABLE="Invoice"DBMS=ACCESSCS REPLACE;

DATABASE="&pcfdir.demo.mdb";SERVER=&server;PORT=&port;DBDSOPTS="READBUFF=10";

RUN;

Example 4: Export a SAS Data Set to a Microsoft Access Database File ona PC Files Server

This next example exports a SAS data set named ORDERS to a new Microsoft Accessdatabase filenamed test.mdb, which is located on the PC Files Server. The codeperforms these tasks:

� Drops the variable SPECINST� Sets the insert buffer to 20 rows� Writes SAS label names if column names exist in the loaded table named Orders� If test.mdb does not exist, a new test.mdb file is created with version 97 formats.

Otherwise, the version statement is ignored.� Writes the table to the existing file without changing its version.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.ORDERS (DROP=SPECINST)

OUTTABLE="Orders"DBMS=ACCESSCS REPLACE LABEL;

DATABASE="&cstmpdir.test97.mdb";SERVER=&server;PORT=&port;VERSION=’97’;DBDSOPTS="INSERTBUFF=20";

RUN;

Lotus 1-2-3 WKn Files

WKn Files EssentialsThis section introduces Lotus 1-2-3 WKn files. It focuses on the terms and concepts

that help you use SAS/ACCESS Interface to PC Files.SAS/ACCESS Interface to PC Files works with WK1, WK3, and WK4 (releases 4 and

5) files. These files contain data in the form of Lotus 1-2-3 spreadsheets. They are

Page 63: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � WKn Files Essentials 55

referred to collectively in this document as WKn files, where n represents releases 1, 3,or 4. SAS/ACCESS Interface to PC Files does not support the .123 format for files fromLotus SmartSuite 97 software.

Various software products, such as the Lotus 1-2-3 spreadsheet and database system,enable you to use spreadsheet or database files to enter, organize, and performcalculations on data. Spreadsheets are most often used for general ledgers, incomestatements, and other types of financial record keeping. Database files also enable youto organize related information, such as the data in an accounts-receivable journal.

In both spreadsheets and database files, the data is organized according to certainrelationships among data items. These relationships are expressed in a tabular form, incolumns and rows. Each column represents one category of data, and each row can holdone data value for each column.

A Lotus 1-2-3 worksheet is an electronic spreadsheet consisting of a grid of 256columns and 8,192 rows. The intersection of a column and a row is called a cell. Thisdisplay illustrates a portion of a standard 1-2-3 worksheet.

Display 6.2 Columns and Rows of Data in a WKn File

Column letters for each column appear above the worksheet. Columns are lettered Athrough IV (A to Z, AA to AZ, BA to BZ, and so on, to IV). Row numbers for each rowappear to the left of the worksheet. Rows are numbered 1 to 8,192. For WK1 files, onlyone worksheet (worksheet A) is allowed per file. For WK3 and WK4 files, up to 256worksheets (worksheets A-IV) are allowed. However, the SAS/ACCESS interface toWKn files uses only one worksheet and defaults to worksheet A.

A range is a subset of cells in a worksheet. A range is identified by its address, whichbegins with the name of the top-left cell and ends with the name of the bottom-right cellseparated by two periods. For example, the range B2..E8 is the range address for arectangular block of 28 cells whose top-left cell is B2 and whose bottom-right cell is E8(as shaded in the figure).

You can give a name to a range and use the name in commands and formulas insteadof the range address in Lotus 1-2-3. A range name can be up to 15 characters long andshould contain no spaces. For example, if the range B3..D6 is named GRADE_TABLE,the formula @AVG(GRADE_TABLE) has the same value as @AVG(B3..D6).

Page 64: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

56 WKn Data Types � Chapter 6

For more information about ranges and their naming conventions, see the Lotus1-2-3 software documentation.

WKn Data TypesLotus 1-2-3 software has two data types: character and numeric. Lotus 1-2-3

character data can be entered as labels or formula string. Lotus 1-2-3 numeric data canbe entered as numbers or formulas.

Character data is generally considered text and can include dates and numbers ifprefixes are used to indicate character data and to align the data in the cell. Forexample, in Lotus 1-2-3, the value "110 Maple Street uses the double quotation markprefix and aligns the label on the right side of the cell.

Numeric data can include numbers (0 through 9), formulas, and cell entries thatbegin with one of these symbols: +, $, @, -, or #.

Numeric data can also include date and time values. In Lotus 1-2-3 software, a datevalue is the integer portion of a number that can range from 01 January 1900 to 31December 2099, that is, 1 to 73,050. A Lotus 1-2-3 software time value is the decimalportion of a number that represents time as a proportion of a day. For example, 0.0 ismidnight, 0.5 is noon, and 0.999988 is 23:59:59 (on a 24-hour clock).

While a number can have both a date and a time portion, the formats in Lotus 1-2-3display a number only in a date format or a time format. The conversion of date andtime values between SAS data sets and Lotus 1-2-3 spreadsheets is transparent tousers. However, you are encouraged to understand the differences between them.

Supported Import and Export Components and Statements for WKnFiles

The import/export component for WKn files uses ACCESS and DBLOAD proceduresbehind the scenes to access data in WKn files. This component is available only onMicrosoft Windows.

Note: Because ACCESS and DBLOAD procedures are compatible only with SAS 6procedures, SAS system options such as VALIDVARNAME= are ignored. Thiscomponent has other SAS 6 limitations—such as not being case sensitive, a maximumlength of 8 bytes of SAS variable name, and a maximum length of 200 characters ofdata value. �

These tables list the statements that are available to import data from Lotus 1-2-3files using the IMPORT and EXPORT procedures on Microsoft Windows. See“Examples of Importing and Exporting WKn Files” on page 57.

Table 6.12 Available Statements for Importing and Exporting Lotus 1-2-3 Files

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

GETNAMES= YES | NO YES Yes No

RANGE= Range Name orAbsolute Range Value

Yes No

WK4

WK3

SHEET= Sheet name Yes Yes

Page 65: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Examples of Importing and Exporting WKn Files 57

DataSource

Syntax Valid Value DefaultValue

In PROCIMPORT?

In PROCEXPORT?

GETNAMES= YES | NO YES Yes NoWK1

RANGE= Range Name orAbsolute Range Value

Yes No

SHEET= worksheet-letter | <’>worksheet-name<’>; (valid for only PROC IMPORT)identifies a particular spreadsheet in a WKn file. Sheet names can be up to 15characters long and are not case sensitive. A worksheet letter is a one- ortwo-letter alpha character. For WK1 files, there is only one worksheet letter:worksheet A. For WK3 and WK4 files, there can be up to 256 different worksheetletters: worksheet A through worksheet Z and worksheet AA through worksheetIV. The default value is A. For example, specifying WORKSHEET=B identifiesworksheet B from a group of worksheets.

If this statement is not specified, PROC IMPORT reads the first spreadsheetphysically saved in the WKn file. To be certain that PROC IMPORT reads thedesired spreadsheet, you should identify the spreadsheet by specifying SHEET=.

RANGE="range-name" | "absolute-range"; (valid for only PROC IMPORT)subsets a spreadsheet by identifying the rectangular set of cells to import from thespecified spreadsheet. The range names can be up to 15 characters long and arenot case sensitive. If you specify a range name, the name must have beenpreviously defined in the WKn file.

Absolute range identifies the top-left cell that begins the range and thebottom-right cell that ends the range. For example, ’C2..F12’ represents cellswithin Column C, Row 2, and Column F, Row 12.

If this statement is not specified, PROC IMPORT reads the entire spreadsheetas a range.

GETNAMES=YES | NO; (available only for Microsoft Windows; valid for only PROCIMPORT)

determines whether to generate SAS variable names from the data values in thefirst record of the imported Excel file.

When SAS reads the data value in the first record of the input file, SAS checks forinvalid SAS name characters (such as a blank). Invalid characters are convertedto an underscore. For example, the column name ’My ID’ becomes the SASvariable name ’MY_ID’.

YESspecifies that PROC IMPORT generate SAS variable names from the datavalues in the first record of the imported Excel file.

NOspecifies that PROC IMPORT generate SAS variable names as VAR0, VAR1,VAR2, and so on.

Examples of Importing and Exporting WKn Files

Example 1: Export a SAS Data Set to a WK4 FileThis example exports data from SAS data set SDF.EMPLOYEE to a WK4 file

Employee.wk4 without variables FRSTNAME and MIDNAME.

Page 66: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

58 dBase DBF Files � Chapter 6

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.EMPLOYEE(DROP=FRSTNAME MIDNAME)

OUTFILE= "&tmpdir.Employee.wk4"DBMS=WK4 REPLACE;

RUN;

Example 2: Import Data from a SAS Data Set from a WK4 FileThis example imports data from a WK4 file named invoice.wk4 into SAS data set

named Invoice. It retrieves data from Sheet A, within range from left top cell, A1, toright bottom cell, D12. It then reads the first row of data in the range as SAS variablenames.

PROC IMPORT OUT=WORK.InvoiceDATAFILE="&wkndir.Invoice.wk4"DBMS=WK4 REPLACE;

SHEET="A";RANGE="A1..D12";GETNAMES=YES;

RUN;

Example 3: Export Data to a WK1 File from a SAS Data SetThe next example exports data to a WK1 file named Orders.wk1 from a SAS data set

named SDF.ORDERS, without the variable SPECINST.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.ORDERS(DROP=SPECINST)

OUTFILE="&tmpdir.Orders.wk1"DBMS=WK1 REPLACE;

RUN;

Example 4: Import Data from a WK1 File into a SAS Data SetThis example imports data from a WK1 file named Orders.wk1 into a SAS data set

named Test. It retrieves data from left top cell, B5, to right bottom cell, D12. SASassigns name for each variable as VAR0, VAR1, and VAR2.

PROC IMPORT OUT=WORK.TestDATAFILE="&wkndir.orders.wk1"DBMS=WK1 REPLACE;

RANGE="B5..D12";GETNAMES=NO;

RUN;

dBase DBF Files

DBF Files EssentialsThis section introduces dBase DBF files. It focuses on the terms and concepts that

help you use SAS/ACCESS Interface to PC Files.

Page 67: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � DBF Data Types 59

DBF files are in a file format that dBASE creates. dBASE is a relational databasemanagement system for PC systems. DBF files can be created using a variety of PCsoftware programs, such as Microsoft Visual FoxPro.

A DBF file contains data that is organized in a tabular format of database fields andrecords. Each database field can contain one type of data, and each record can hold onedata value for each field. This picture illustrates four database fields fromCustomer.DBF and highlights a database field and a record.

database field

CUSTOMER CITY STATE COUNTRY

14324742 San Jose CA USA14569877 Memphis TN USA record14898029 Rockville MD USA26422096 La Rochelle France38763919 Buenos Aires Argentina46783280 Singapore Singapore

DBF Data Types

Every field in a DBF file has a name and a data type. The data type tells how muchphysical storage to set aside for the database field and the form in which the data isstored. This list describes each data type.

Character(N) specifies a field for character string data. The maximum length of Nis 254 characters. Characters can be letters, digits, spaces, or specialcharacters. You can abbreviate character to char in your programs.

Numeric(N,n) specifies a decimal number. The N value is the total number ofdigits (precision), and the n value is the number of digits to the rightof the decimal point (scale). The maximum values allowed dependon the software product you are using. For dBASE products, hereare the maximum values that are allowed:

dBASE Version N, n

dBASE II 16, 14

dBASE III 19, 15

dBASE III PLUS 19, 15

dBASE IV 20, 18

dBASE 5.0 20, 18

Numeric field types always preserve the precision of their originalnumbers. However, SAS stores all numbers internally asdouble-precision, floating-point numbers so their precision is limitedto 16 digits.

Page 68: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

60 Setting Environment Variables and System Options � Chapter 6

Note: If every available digit in a DBF file field is filled with a 9, SAS interprets the value of the field as missing. If a field in SASindicates a missing value (represented by a period), SAS writes anine for each available digit in the corresponding DBF file databasefield. A value is represented as missing if you fill every availabledigit in a DBF file field with nines while you are in a SAS session,scroll from the field, and return to the field. �

Float(N,n) specifies a floating-point binary number that is available in dBASEIV and later versions. The maximum N,n value for Float is 20,18.Check with the documentation that comes with other softwareproducts you might be using to create DBF files to determinewhether those products support floating-point binary numbers.

Date specifies a date value in a format that has numbers and a charactervalue to separate the month, day, and year. The default format ismm/dd/yy; for example, 02/20/95 for February 20, 1995.

Dates in DBF files can be subtracted from one another, with theresult being the number of days between the two dates. A number(of days) can also be added to a date, with the result being a date.

Logical specifies a type that answers a yes/no or true/false question for eachrecord in a file. This type is 1 byte long and accepts these charactervalues: Y, y, N, n, T, t, F, and f.

dBASE also has data types called Memo, General, binary, and OLE. These data typesare stored in an associated memo text file (a DBT file), but these data types are notsupported in the SAS/ACCESS Interface to PC Ffiles.

Setting Environment Variables and System Options

Missing Values Missing numeric values are filled in with blanks by default. TheDBFMISCH environment variable is used to change the default byspecifying the character that the interface to DBF files uses to fillmissing numeric fields. For example, if you try to write a SAS filewith a missing numeric variable to a DBF file, the correspondingfield in the DBF file would be filled with the DBFMISCH character.Conversely, any numeric or float field in a DBF file that contains theDBFMISCH character is treated as a missing value when SAS readit.

You set the DBMISCH environment variable in the SASconfiguration file by using this syntax:

-set DBFMISCH value

Here are the valid values:

<any single character>Type in any single character. For example, to fill missingnumeric values with the character “9”, enter -set DBFMISCH 9.

NULLS To replace missing numeric values with binary zeros, enter -setDBFMISCH NULLS .

BLANKS To replace missing numeric values with blanks, enter -setDBFMISCH BLANKS.

Page 69: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Supported SAS IMPORT/EXPORT Procedure Statements 61

DecimalSeparator

Although a period is used as decimal separator in the United States,some countries might use different symbol characters. For example,some European countries use comma character as the decimalseparator. To allow data saved with different decimal separator to beimported or exported correctly, you must set SAS system option,CTRYDECIMALSEPARATOR.

You set CTRYDECIMALSEPARATOR option in the SAS usingthis syntax:

options CTRYDECIMALSEPARATOR=value;

Valid values can be any character. For example, European usersmight set a comma as the decimal separator by submitting thisstatement in SAS:

options CTRYDECIMALSEPARATOR=’,’ ;

Supported SAS IMPORT/EXPORT Procedure StatementsThis Import/Export component uses DBF file formats to access data in DBF Files on

Linux, UNIX, and Microsoft Windows operating platforms. It imports data from DBFfiles that were saved in versions 3, 4, and 5 formats. It exports data to DBF files withversion 5 formats.

This table lists the statements that are available for processing DBF files in IMPORTand EXPORT procedures. See “Examples of Importing and Exporting DBF Files” onpage 62.

Table 6.13 IMPORT and EXPORT Procedure Statements for DBF Files

DataSource

Syntax Valid Values DefaultValue

In PROCIMPORT?

In PROCEXPORT?

DBF DBENCODING= Encoding-value Current SASsessionencoding

Yes Yes

GETDELETED= YES | NO YES Yes No

DBENCODING=’encoding-value’;Indicates the encoding used to save data in DBF files. An encoding maps eachcharacter in a character set to a unique numeric representation, which results in atable of all code points. A single character can have different numericrepresentations in different encodings.

For example, some DBF files were saved with pcoem850 encoding. When youare importing these DBF files on Microsoft Windows, specifyDBENCODING=pcoem850. SAS IMPORT procedure reads and transcodes data frompcoem850 to Microsoft Windows default WLATIN1.

Refer to the SAS NLS User’s Guide for more information about transcoding andvalid encoding values.

GETDELETED=YES | NO;indicates whether to write records to the SAS data sets that are marked fordeletion but have not been purged.

Page 70: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

62 Examples of Importing and Exporting DBF Files � Chapter 6

YES writes records to the SAS data sets that are marked fordeletion but have not been purged.

NO does not write records to the SAS data sets that are marked fordeletion but have not been purged.

Examples of Importing and Exporting DBF Files

Example 1: Export Data to a DBF File from a SAS Data SetThis example exports data to a DBF file, named test.dbf, from a SAS data set named

SDF.EMPLOYEE, with a WHERE condition in the data set option.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.EMPLOYEE (where=(HIREDATE is not missing))

OUTFILE="&tmpdir.test.dbf"DBMS=DBF REPLACE;

RUN;

Example 2: Import Data from a DBF File into a SAS Data SetThis example imports data from a DBF file named invoice.dbf into SAS data set

named TEST5. The data is imported without the DELETE flag field.

PROC IMPORT OUT=WORK.TEST5DATAFILE="&dbfdir.Invoice.dbf"DBMS=DBF REPLACE;

GETDEL=NO;RUN;

Example 3: Export Data to a DBF File from a SAS Data SAS Using EncodingCode in this example exports data to a DBF file named Oem850.dbf from a SAS data

set named SDF.ORDERS. It translates SAS data from its current session encoding topcoem850 encoding and writes it to the DBF file.

PROC EXPORT DATA=SDF.ORDERSOUTFILE="&dbfdir.Oem850.dbf"DBMS=DBF REPLACE;

DBENCODING=pcoem850;RUN;

Example 4: Import and Translate Data from a DBF FileThis next example imports data from a DBF file named Oem850.dbf, which was

saved with pcoem850 encoding. It reads in the data and translates it from pcoem850encoding to current SAS session encoding.

PROC IMPORT OUT=WORK.ORDERSDATAFILE="&dbfdir.Oem850.dbf"DBMS=DBF REPLACE;

DBENCODING=pcoem850;RUN;

Page 71: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � JMP Missing Values 63

dBase DBFMEMO FilesAll versions of dBase under Linux, UNIX, and Microsoft Windows are supported.

Memo files have a .dbt (dBase) or .fpt (FoxPro and Visual FoxPro) file extension. Foxpromemos are stored in a separate directory from dBase memos.

Memo files read blank numeric fields as missing values. Memo files do not havevariables or value labels, and memo support is read-only.

If a memo file exists with the same filename but with a .dbt or .fpt extension, thedriver also reads the memo text for that file. It scans the memo file to determine howmany lines comprise the largest individual memo and the lengths of the longest lines.It then splits memos into one variable per memo line. For example, the first three linesof a memo file called xyz would be named xyz01, xyz02, and xyz03.

Example of Importing DBF File with Memo Field

Example 1: Import Data from a DBF File with Memo Field into a SAS DataSet

This example imports data from a DBF file named orders.dbf into a SAS data setnamed TEST. The memo field data was saved in the orders.fpt file by Microsoft VisualFoxPro. SAS reads data from both orders.dbf and orders.fpt files.

PROC IMPORT OUT=WORK.TESTDATAFILE="orders.dbf"DBMS=DBF REPLACE;

RUN;

JMP Files

JMP Files EssentialsA JMP file is a file format that the JMP software program creates. JMP is an

interactive statistics package that is available for Microsoft Windows and Macintosh.For more information about a JMP concept or term, see the JMP documentation that ispackaged with your system.

A JMP file contains data that is organized in a tabular format of fields and records.Each field can contain one type of data, and each record can hold one data value foreach field.

Variable names can be up to 31 characters in length. When you are reading a JMPfile, any embedded blank or special character in a variable name is replaced with anunderscore (_). This is noted in the log.

See “Examples of Importing and Exporting JMP Files” on page 65.

JMP Missing ValuesJMP supports a single missing value in all variable types other than character. When

you are reading a JMP file, JMP missing value maps to SAS missing value. When youare writing a JMP file, all SAS missing values maps to the single JMP missing value.

Page 72: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

64 JMP Data Types � Chapter 6

JMP Data TypesEvery field in a JMP file has a name and a data type. The data type indicates how

much physical storage to set aside for the field and the format in which the data isstored. This list describes each data type.

Character specifies a field for character string data. The maximum length is255 characters. Characters can be letters, digits, spaces, or specialcharacters.

Meta specifies how metadata contained in the specified data set ishandled. Here is the syntax:

meta=libref.member

When you add this statement to PROC EXPORT, the metadatacontained in the specified data set is added to the built JMP file.When you add this statement to PROC IMPORT, the extra data setthat contains the metadata is created when reading the JMP file.

These record types are processed for the metadata.Table properties:

code="text, subcode="prop", variable="", label=property_text

Variable notes:

code="note", subcode="", variable=varname, label=note_text

You can create any number of properties or notes.

Variable labels are automatically written as SAS labels when theSAS data set is built, and SAS variable labels are read when theJMP table is built.

When you use this statement with PROC IMPORT, value labelsfrom the JMP file can be read and added to the format library.When you use this statement with PROC EXPORT, value lists areread from the format libraries when the JMP table is being built.

The metadata set contains these fields: index, number, variable,code, subcode, name, and label. Those names must match when theSAS metadata data set is being read. To do this easily, write themetadata from an existing JMP file to a SAS data set, view thevariable information, and record the contents of the file.

Numeric specifies an 8–byte floating point number. This is also called adouble precision number. When you are reading data, this mapsdirectly to the SAS double precision number. When you are writingdata, all SAS numeric variables (regardless of length) become JMPnumeric variables.

Rowstate specifies an integer variable that takes on the value of 1 or missing.When you are reading data, this maps to a SAS double precisionnumber.

Date specifies the date format. When you are reading data, the datevalues are mapped to a SAS number and scaled to the base date.The JMP date display format maps to the appropriate SAS datedisplay format. When you are writing data, the SAS output format

Page 73: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � Examples of Importing and Exporting JMP Files 65

for the numeric variable is checked to determine whether it is a dateformat. If so, the SAS numeric value is scaled to a JMP date valuewith the appropriate date display format.

DateTime specifies the datetime format. When you are reading data, thedatetime values are mapped to a SAS number and scaled to the basedatetime. The JMP datetime display format maps to the appropriateSAS datetime display format. When you are writing data, the SASoutput format for the numeric variable is checked to determinewhether it is a datetime format. If so, the SAS numeric value isscaled to a JMP datetime value with the appropriate datetimedisplay format.

Time specifies the time format. When you are reading data, the timevalues are mapped to a SAS number and scaled to the base time.The JMP time display format maps to the appropriate SAS timedisplay format. When you are writing data, the SAS output formatfor the numeric variable is checked to determine whether it is a timeformat. If so, the SAS numeric value is scaled to a JMP time valuewith the appropriate time display format.

Importing and Exporting Data in JMP FilesSAS import/export utilities provide two components for accessing JMP files.

1 Using JMP File Formats (DBMS=JMP)

This Import/Export component uses JMP File Formats to access data in JMPFiles on Linux, UNIX, and Microsoft Windows operating platforms. It importsdata from JMP files saved with any version of JMP formats. It exports data toJMP files with V5 formats. This component does not provide any additionalstatements; you simply use the basic PROC IMPORT and PROC EXPORT syntaxto access your JMP data.

2 Using the PC Files Server (DBMS=PCFS)

This import/export component uses the client/server model to access data inJMP Files on Microsoft Windows from Linux, UNIX, or Microsoft Windows 64-bitoperating platforms. This component requires running the PC Files Server onMicrosoft Windows.

Examples of Importing and Exporting JMP Files

Example 1: Export a SAS Data Set to a JMP File

This example exports a SAS data set named SDF.CUSTOMER to a JMP file namedcustomer.jmp on a local system.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.CUSTOMER

FILE="&tmpdir.customer.jmp"DBMS=JMP REPLACE;

RUN;

Page 74: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

66 Examples of Importing and Exporting JMP Files Using a PC Files Server � Chapter 6

Example 2: Import a SAS Data Set from a JMP FileThis example imports a SAS data set named CUSTOMER from a JMP file named

customer.jmp on a local system.

PROC IMPORT OUT=WORK.CUSTOMERFILE="&jmpdir.customer.jmp"DBMS=JMP REPLACE;

RUN;

Examples of Importing and Exporting JMP Files Using a PC FilesServer

Example 1: Export a SAS Data Set on UNIX to a JMP File on MicrosoftWindows

This example exports a SAS data set named SDF.CUSTOMER to a JMP file namedcustomer.jmp. Note that SAS is running on the UNIX operating platform and the JMPfile is loaded on Microsoft Windows where a PC Files Server is running.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.CUSTOMER

FILE="&cstmpdir.customer.jmp"DBMS=PCFS REPLACE;

SERVER=&server;PORT=8621;

RUN;

Example 2: Import Data from a JMP File on Microsoft Windows to a SASData Set on UNIX

This example imports data from a JMP file named customer.jmp to a SAS data setnamed CUSTOMER. Note that SAS is running on a UNIX platform and the JMP file islocated on Microsoft Windows where a PC Files Server is running.

PROC IMPORT OUT= WORK.CUSTOMERFILE="&csjmpdir.customer.jmp"DBMS=PCFS REPLACE;

SERVER=&server;PORT=8621;

RUN;

Paradox DB Files

Paradox File EssentialsAll versions of Paradox under Linux, UNIX, and Microsoft Windows are supported.

Paradox files have a .db file extension. Paradox supports missing values. It does nothave variables or value labels.

Page 75: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � SPSS Data Types 67

If a memo file with the same filename but with an .db extension exists, the memotext on that file is also read. The memo file is scanned to determine how many linescomprise the largest individual memo and the lengths of the longest lines. The driverthen splits the memos into one variable per memo line. Memo support is read-only.

Examples of Importing and Exporting Paradox DB Files

Example 1: Export a SAS Data Set to a Paradox DB FileThis example exports the SAS data set, SDF.CUSTOMER, to the Paradox DB file,

customer.db, on a local system.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.CUSTOMER

FILE="&tmpdir.customer.db"DBMS=DB REPLACE;

RUN;

Example 2: Import a SAS Data Set from a Paradox DB FileThis example imports the SAS data set, WORK.CUSTOMER, from the Paradox DB

file, customer.db, on a local system.

PROC IMPORT OUT=WORK.CUSTOMERFILE="&tmpdir.customer.db"DBMS=DB REPLACE;

RUN;

SPSS SAV Files

SAV File EssentialsAll versions of SPSS under Microsoft Windows are supported. SPSS files have a .sav

file extension. SPSS files that have short variable names are exported.See “Examples of Importing and Exporting SPSS SAV Files” on page 69.

SPSS Data Types

Missing Values SPSS supports missing values. SAS missing values are written asSPSS missing values.

Variable Names Only the short variable name style is supported. SPSS variablenames can be up to eight characters in length. All alphabeticcharacters must be uppercase. The first character in a variablename can be an uppercase letter (A-Z), a dollar sign ($), or an "at"

Page 76: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

68 SPSS Data Types � Chapter 6

sign (@). Subsequent characters can be any of these characters, plusnumerals (0-9), periods (.), number signs (#), or underscores ( _ ).

SPSS reserves 13 words, which are not allowed to stand alone asvariable names: ALL, AND, BY, EQ, GE, GT, LE, LT, NE, NOT, OR,TO, and WITH. If the program encounters any of these as a variablename, it appends an underscore to the variable name to distinguishit from the reserved word. For example, ALL becomes ALL_.

Invalid characters are converted to underscores unless they areencountered as the first character in a variable name. In that event,the "at" sign (@) is used instead. For example, %ALL becomes @ALL.

When you are exporting to SPSS, SAS variable names that arelonger than eight characters are truncated to eight characters. Iftruncation results in a name that matches another variable name,the last character changes to a single digit (1, 2, 3, and so on) untilthe variable name becomes unique.

Variable Labels SPSS supports variable labels. PROC EXPORT writes the variablename to an SPSS file as the label if the variable name is not a validSPSS name and no label exists.

Value Labels SPSS stores value labels within the data file. The values are turnedinto format library entries as they are read with PROC IMPORT.The name of the format includes its associated variable name(modified to meet the requirements of format names). The name ofthe format is also associated with a variable in the data set.

PROC EXPORT saves the value labels that are associated withthe variables when writing to an SPSS file. It uses the formats thatare associated with the variables to retrieve the value entries.

Data Types SPSS supports numeric and character field types that map directlyto SAS numeric and character fields. This list shows other SPSSdata types and how PROC IMPORT converts them to SAS formats.

Date, Jdate, Wkday, Qyr, Wkyr: Date, Jdate, Wkday, Qyr, Wkyr

Datetime, Dtime: Converts to a SAS datetime value and SASdatetime format.

Time: Converts to a SAS datetime value and SAS datetimeformat.

Adate: Converts to a SAS date value in the mmddyy format.

Moyr: Converts to a SAS date value in the mmmyy format.

When writing SAS data to an SPSS file, PROC EXPORT convertsdata into SPSS variable types.

When exporting data, character fields have a maximum length of256.

Numeric fields are 8-byte floating-point numbers, with theseformat conversions:

Comma Converts to SPSS format type comma.

Dollar Converts to SPSS format type dollar.

Date Converts to SPSS format type date.

mmddyy Converts to SPSS format Adate.

Page 77: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � DTA Data Types 69

mmmyy Converts to SPSS format Moyr.

Datetime Converts to SPSS format Dtime.

Time Converts to SPSS format Time.

Examples of Importing and Exporting SPSS SAV Files

Example 1: Export a SAS Data Set to an SPSS SAV FileThis example exports the SAS data set, SDF.CUSTOMER, to the SPSS SAV file,

customer.sav, on a local system.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.CUSTOMER

FILE="&tmpdir.customer.sav"DBMS=SPSS REPLACE;

RUN;

Example 2: Import a SAS Data Set from an SPSS SAV FileThis example imports the SAS data set, WORK.CUSTOMER, from the SPSS SAV

file, customer.sav, on a local system.

PROC IMPORT OUT=WORK.CUSTOMERFILE="&tmpdir.customer.sav"DBMS=SPSS REPLACE;

RUN;

Stata DTA Files

DTA Files EssentialsAll versions of Stata under Microsoft Windows are supported. Stata files have a .dta

file extension.See “Examples of Importing and Exporting Stata DTA Files” on page 71.

DTA Data Types

Files Import of all Stata versions under Microsoft Windows and UNIX issupported. Export of Stata version 8 and later is supported.

Missing Values Stata supports missing values. SAS missing values are written asStata missing values.

Variable Names When using importing, Stata variable names can be up to 32characters in length. The first character in a variable name can be

Page 78: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

70 DTA Data Types � Chapter 6

any lowercase letter (a–z) or uppercase letter (A–Z), or anunderscore ( _ ). Subsequent characters can be any of thesecharacters, plus numerals (0–9). No other characters are permitted.Stata reserves these 19 words, which are not allowed to stand aloneas variable names:

_all

in

_pred

_b

int

_rc

_coef

long

_skip

_cons

_n

using

double

_N

_weight

float

pi

with

if

If the program encounters any of these reserved words as variablenames, it appends an underscore to the variable name to distinguishit from the reserved word. For example, _N becomes _N_.

When exporting, variable names that are longer than 32characters are truncated. The first character in a variable name canbe any lowercase letter (a–z) or uppercase letter (A–Z), or anunderscore ( _ ). Subsequent characters can be any of thesecharacters, plus numerals (0–9). No other characters are permitted.Invalid characters are converted to underscores ( _ ).

Variable Labels Stata supports variable labels when using PROC IMPORT.

When exporting, if the variable name is not a valid Stata nameand if there is no label, PROC EXPORT writes the variable name toa Stata file as the label.

Value Labels Stata stores value labels within the data file. The values are turnedinto format library entries as they are read with PROC IMPORT.The name of the format includes its associated variable name(modified to meet the requirements of format names). The name ofthe format is also associated with a variable in the data set.

Page 79: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File Format-Specific Reference � DTA Data Types 71

When writing SAS data to a Stata file, PROC EXPORT saves thevalue labels that are associated with the variables. It uses theformats that are associated with the variables to retrieve the valueentries.

Data Types Stata supports numeric field types that map directly to SAS numericfields.

Stata date variables become numerics with a date format.

When writing SAS data to a Stata file, PROC EXPORT convertsdata into variable type double. A SAS date format becomes a Statadate variable.

Examples of Importing and Exporting Stata DTA Files

Example 1: Export a SAS Data Set to a Stata DTA FileThis example exports the SAS data set, SDF.CUSTOMER, to the Stata DTA file,

customer.dta, on a local system.

LIBNAME SDF V9 "&sasdir";PROC EXPORT DATA=SDF.CUSTOMER

FILE="&tmpdir.customer.dta"DBMS=STATA REPLACE;

RUN;

Example 2: Import a SAS Data Set from a Stata DTA FileThis example imports the SAS data set, WORK.CUSTOMER, from the Stata DTA

file, customer.dta, on a local system.

PROC IMPORT OUT=WORK.CUSTOMERFILE="&tmpdir.customer.dta"DBMS=STATA REPLACE;

RUN;

Page 80: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

72

Page 81: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

73

P A R T3

LIBNAME Statement and Pass-ThroughFacility on 32-Bit Microsoft Windows

Chapter 7. . . . . . . . . .The LIBNAME Engines 75

Chapter 8. . . . . . . . . .LIBNAME Statement: PC Files on Microsoft Windows 81

Chapter 9. . . . . . . . . .The Pass-Through Facility for PC Files on MicrosoftWindows 111

Chapter 10. . . . . . . . .File-Specific Reference 127

Page 82: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

74

Page 83: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

75

C H A P T E R

7The LIBNAME Engines

Overview: LIBNAME Engines 75Software Requirements 76

Macro Variables 76

SAS Trace System Options 77

Overview: LIBNAME Engines

SAS to Microsoft Ace/Jet LIBNAME Engine

Microsoft Accessdatabase files

SAS to Microsoft AccessLIBNAME Engine

SAS to Microsoft ExcelLIBNAME Engine

MDAC/OLE DB

Microsoft Ace/Jet Provider

Microsoft Excelworkbook files

Page 84: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

76 Software Requirements � Chapter 7

Software Requirements

On Windows, SAS/ACCESS Interface to PC Files supports a LIBNAME engine forMicrosoft Access database files and a LIBNAME engine for Excel workbook files. Thesetwo engines share most of code that calls OLE DB APIs internally. They require thatyou have installed Microsoft Data Access Components (MDAC) and Microsoft Jet (JointEngine Technology) or Microsoft Ace (for 2007 and above) provider software. By default,SAS software installs and checks the required Microsoft software.

Macro Variables

The automatic macro variables SYSDBMSG, SYSDBRC, SQLXMSG, and SQLXRCare portable, but the SAS/ACCESS engine and the Microsoft Jet Engine determinetheir values. Initially, the macro variables SYSDBMSG and SQLXMSG are blank,whereas SYSDBRC and SQLXRC are set to 0.

SAS/ACCESS generates several return codes and error messages while it processesyour programs. This information is available to you through these SAS macro variables:

SYSDBMSGcontains Jet provider-specific error messages that are generated when you useSAS/ACCESS software to access Microsoft Access or Excel data.

SYSDBRCcontains Jet provider-specific error codes that are generated when you useSAS/ACCESS software to Microsoft Access or Excel data. Error codes that arereturned are text, not numbers.

In this statement, %SUPERQ masks special characters such as &, %, and anyunbalanced parentheses or quotation marks that might exist in the text stored in theSYSDBMSG macro.

%put %superq(SYSDBMSG)

These special characters can cause unpredictable results if you use this statement, so itis more advantageous to use %SUPERQ.

You can also use SYMGET to retrieve error messages:

msg=symget("SYSDBMSG");

Here is an example:

data_null_;msg=symget("SYSDBMSG");put msg;run;

The Pass-Through Facility generates return codes and error messages that areavailable to you through these SAS macro variables:

SQLXMSGcontains Jet provider-specific error messages.

SQLXRCcontains Jet provider-specific error codes.

SQLXMSG and SQLXRC can be used only with the Pass-Through Facility. See“Return Codes” on page 112.

Page 85: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The LIBNAME Engines � SASTRACE= System Option 77

The contents of the SQLXMSG and SQLXRC macro variables can be printed in theSAS log by using the %PUT macro. SQLXMSG is reset to a blank string and SQLXRCis reset to 0 when any Pass-Through Facility statement is executed.

SAS Trace System OptionsSASTRACE= and SASTRACELOC= are SAS system options that have specific SAS/

ACCESS applications.

SASTRACE= System Option

Generates trace information from a DBMS engine

Valid in: OPTIONS statement, configuration file, SAS invocationDefault value: NONE

SyntaxSASTRACE=’,,,d’ | ’,,d,’ | ’d,’ | ’,,,s’

Syntax Description

’,,,d’specifies that all of these SQL statements sent to the Microsoft Jet engine are sent tothe log:

SELECT

UPDATE

CREATE

INSERT

DROP

DELETE

’,,d,’specifies that all routine calls are sent to the log. When this option is selected, allfunction enters and exits, as well as pertinent parameters and return codes, aretraced. However, the information varies from engine to engine.

This option is most useful if you are having a problem and need to send a SAS logto technical support for troubleshooting.

’d,’specifies that all OLE DB API calls for connection information, column bindings,column error information, and row processing are sent to the log. This option is most

Page 86: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

78 SASTRACE= System Option � Chapter 7

useful if you are having a problem and need to send a SAS log to technical supportfor troubleshooting.

’,,,s’specifies that a summary of timing information for calls made to the DBMS is sent tothe log.

Note: By default, Microsoft Access and Microsoft Excel LIBNAME engines useROWSET_INSERT instead of executing the SQL INSERT command. You do not see theINSERT statement in the trace log when inserting rows into a table. You can use theLIBNAME statement or the SQL_INSERT=YES option to see the INSERT statement inthe trace log. �

DetailsThe SASTRACE= options have behavior that is specific to SAS/ACCESS software.SASTRACE= is a very powerful tool to use when you want to see the commands thatthe SAS/ACCESS engine sends. SASTRACE= output is DBMS-specific. However, mostSAS/ACCESS engines shows you statements like SELECT or COMMIT as the DBMSprocesses them for the SAS application. These details can help you manageSASTRACE= output for your files:

� When using SASTRACE= on PC platforms, you must also specify“SASTRACELOC= System Option” on page 80.

� To turn SAS tracing off, specify this option:

options sastrace=off;

� Log output is much easier to read if you specify NOSTSUFFIX. Here is an example:

options sastrace=’,,,d’ sastraceloc=saslog nostsuffix;

ExampleThis example uses SASTRACE =’, , , d’ so that SQL statements can be reviewed.

data work.winter_birthdays;input empid birthdat date9. lastname $18.;format birthdat date9.;

datalines;678999 28DEC1966 PAVEO JULIANA 3451456788 12JAN1977 SHIPTON TIFFANY 3468890123 20FEB1973 THORSTAD EDVARD 3329;run;

options sastrace=’,,,d’ sastraceloc=saslog nostsuffix;libname mydblib "c:\sasdemo\demo.mdb" ;

proc delete data=mydblib.snow_birthdays; run;

data mydblib.snow_birthdays;set work.winter_birthdays;

run;

proc print data=mydblib.snow_birthdays; run;

Page 87: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The LIBNAME Engines � SASTRACE= System Option 79

libname mydblib clear;

Here are the SQL statements in the SAS log output.

1 data work.winter_birthdays;2 input empid birthdat date9. lastname $18.;3 format birthdat date9.;4 datalines;

NOTE: The data set WORK.WINTER_BIRTHDAYS has 3 observations and 3 variables.NOTE: DATA statement used (Total process time):

real time 0.06 secondscpu time 0.04 seconds

8 ;9 run;1011 options sastrace=’,,,d’ sastraceloc=saslog nostsuffix;12 libname mydblib "c:\sasdemo\demo.mdb" ;NOTE: Libref MYDBLIB was successfully assigned as follows:

Engine: ACCESSPhysical Name: c:\sasdemo\demo.mdb

1314 proc delete data=mydblib.snow_birthdays; run;

Jet_0: Executed:DROP TABLE ‘snow_birthdays‘

NOTE: Deleting MYDBLIB.snow_birthdays (memtype=DATA).NOTE: PROCEDURE DELETE used (Total process time):

real time 0.01 secondscpu time 0.00 seconds

1516 data mydblib.snow_birthdays;17 set work.winter_birthdays;18 run;

NOTE: SAS variable labels, formats, and lengths are not written to DBMS tables.

Jet_1: Executed:CREATE TABLE ‘snow_birthdays‘ (‘empid‘ Double,‘birthdat‘ DateTime,‘lastname‘

VarChar(18))

NOTE: There were 3 observations read from the data set WORK.WINTER_BIRTHDAYS.NOTE: The data set MYDBLIB.snow_birthdays has 3 observations and 3 variables.NOTE: Successfully Inserted 3 row(s)NOTE: DATA statement used (Total process time):

real time 0.03 secondscpu time 0.01 seconds

Page 88: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

80 SASTRACELOC= System Option � Chapter 7

1920 libname mydblib clear;NOTE: Libref MYDBLIB has been deassigned.

SASTRACELOC= System Option

Prints SASTRACE information to a specified location

Valid in: OPTIONS statement, configuration file, SAS invocationDefault value: stdout

SyntaxSASTRACELOC=stdout | SASLOG | FILE ’path-and-filename’

DetailsSASTRACELOC= enables you to specify where to put the trace messages that aregenerated by SASTRACE=. By default, the output goes to the default output locationfor your operating environment. You can send the output to a SAS log by specifyingSASTRACELOC=SASLOG.

ExampleThis example runs on a PC platform and writes trace information to the TRACE.LOGfile in the work directory on the C drive.

options sastrace=’d,,d,d’ sastraceloc=file ’c:\work\trace.log’;

Page 89: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

81

C H A P T E R

8LIBNAME Statement: PC Fileson Microsoft Windows

Overview: LIBNAME Statement for PC Files on Microsoft Windows 81Sorting PC Files Data 81

Using SAS Functions with PC Files Data 81

Assigning a Libref Interactively 82

LIBNAME Options for PC Files on Microsoft Windows 86

Data Set Options for PC Files on Microsoft Windows 93

Overview: LIBNAME Statement for PC Files on Microsoft WindowsThe SAS/ACCESS LIBNAME statement extends the SAS global LIBNAME

statement to support assigning a libref to Microsoft Excel and Microsoft Access files.This enables you to reference spreadsheets and databases directly in a DATA step orSAS procedure, and to read from and write to a Microsoft Access or Excel object as if itwere a SAS data set.

Sorting PC Files DataWhen you use the LIBNAME statement to associate a libref with PC files data, you

might observe some behavior that differs from that of normal SAS librefs. Becausethese librefs refer to database and workbook objects, such as tables, they are stored in aformat that differs from the format of normal SAS data sets. This is helpful toremember when you access and work with PC files data.

For example, you can sort the observations in a normal SAS data set and store theoutput to another data set. However, in a Microsoft Access database, sorting data hasno effect on how it is stored. Because your data might not be sorted in the external file,you must sort the data at the time of query. Furthermore, when you sort PC files data,the results might vary depending on whether the external spreadsheet or databaseplaces data with NULL values (which are translated in SAS to missing values) at thebeginning or the end of the result set.

Using SAS Functions with PC Files DataWhen you use librefs that refer to PC files data with SAS functions, some functions

might return a value that differs from what is returned when you use the functionswith normal SAS data sets. For example, the PATHNAME function might return aMicrosoft Excel filename assigned for the libref. For a normal SAS libref, it returns thepathname for the assigned libref.

Usage of some functions might also vary. For example, the LIBNAME function canaccept an optional SAS-data-library argument. When you use the LIBNAME function to

Page 90: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

82 Assigning a Libref Interactively � Chapter 8

assign or deassign a libref that refers to PC files data, you omit this argument. For fulldetails about how to use SAS functions, see the SAS Language Reference: Dictionary.

Assigning a Libref InteractivelyAn easy way to associate a libref with PC files data is to use the New Library

window. To open this window, issue the DMLIBASSIGN command from your SASsession command box or command line. You can also access the New Library window byright-clicking the libraries icon in the Explorer window and selecting New.

This list describes how to use the New Library window:� Name: Enter the libref that you want to assign to a SAS library or an external data

source.� Engine: Click the down arrow to select a name from the pull-down listing.� Enable at startup: Click this if you want the specified libref to be assigned

automatically when you open a SAS session.� Library Information: These fields represent the SAS/ACCESS connection

options and vary according to the SAS/ACCESS engine that you specify. Enter theappropriate information for your PC file format.

� OK: Click this button to assign the libref, or click Cancel to exit the windowwithout assigning a libref.

LIBNAME Statement Syntax for PC Files on Microsoft Windows

Associates a SAS libref with a workbook or database.

Valid in: anywhere

SyntaxLIBNAME libref <engine-name> <physical-file-name>

<SAS/ACCESS-engine-connection-options><SAS/ACCESS-libname-options>;

LIBNAME libref CLEAR | _ALL_ CLEAR;

LIBNAME libref LIST | _ALL_ LIST;

Arguments

librefis any SAS name that serves as an alias to associate SAS with a spreadsheet ordatabase. Like the global SAS LIBNAME statement, the SAS/ACCESS LIBNAMEstatement creates shortcuts or nicknames for data storage locations. While a SASlibref is an alias for a virtual or physical directory, a SAS/ACCESS libref for PC filesis an alias for the spreadsheet or database where your data is stored.

engine-nameis the SAS/ACCESS engine name for your PC file format. The engine name isoptional if physical-file-name is specified. The SAS/ACCESS LIBNAME statement

Page 91: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � LIBNAME Statement Syntax for PC Files on Microsoft Windows 83

associates a libref with a SAS/ACCESS engine that supports connections to aparticular PC file. Here are the valid values for engine-name:

EXCEL for Microsoft Excel data (5, 95, 97, 2000, 2002, 2003, or 2007).

ACCESS for Microsoft Access data (97, 2000, 2002, 2003, or 2007).

physical-file-nameis the path and filename, including extension (.xls, .xlsb, .xlsm, .xlsx, .mdb, or.accdb), of the data source.

Note: If you omit physical-file-name, your engine connection options shouldidentify the data source or you are prompted for a filename, unless PROMPT=NO orNOPROMPT is indicated in the engine connection options. �

CLEARdisassociates one or more currently assigned librefs.

Specify libref to disassociate a single libref. Specify _ALL_ to disassociate allcurrently assigned librefs.

_ALL_specifies that the CLEAR or LIST argument applies to all librefs that are currentlyassigned.

LISTwrites the attributes of one or more SAS/ACCESS libraries or SAS libraries to theSAS log.

Specify libref to list the attributes of a single SAS/ACCESS library or SAS library.Specify _ALL_ to list the attributes of all libraries that have librefs in your currentsession.

SAS/ACCESS-engine-connection-optionsprovide connection information to SAS/ACCESS to connect to your PC files. If theconnection options contain characters that are not allowed in SAS names, enclose thevalues of the arguments in quotation marks. In some instances, if you specify theappropriate system options or environment variables for your data source, you canomit the connection options.

See “Connection Options” on page 83 for detailed information about connectionoptions.

SAS/ACCESS-libname-optionsdefine how SAS interacts with your data source, providing enhanced control of theway that SAS processes data source objects. For example, some LIBNAME optionscan improve performance. For many tasks, you do not need to specify any of theseadvanced options.

See “LIBNAME Statement Syntax for PC Files on Microsoft Windows” on page 82for detailed information about LIBNAME options.

Connection OptionsSAS/ACCESS provides many ways to connect to your PC files.

INIT= "connection-string"specifies an initialization string that SAS uses when connecting to a data source,as in this example:

libname db ACCESS init="Provider=Microsoft.Jet.OLEDB.4.0Data Source=c:\temp\sasdemo.mdb"

Alias: INIT_STRING=

Page 92: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

84 LIBNAME Statement Syntax for PC Files on Microsoft Windows � Chapter 8

Note: This option should not be used with a physical filename or otherconnection options, such as PATH= and UDL=. �

PATH="path-for-file"specifies the data source file. This is the full path and filename for your MicrosoftAccess database file or Microsoft Excel workbook file. This option value is treatedthe same as the physical filename. You should use it only when you do not specifythe physical filename in the LIBNAME statement. However, use of this optionrequires the engine name to be specified. Always enter file extension .mdb forMicrosoft Access and .xls for Excel.

Alias: DATASRC=, DS=

PROMPT=YES | NO |REQUIRED | NOPROMPT | PROMPT | UDLdetermines whether you are prompted for connection information that supplies thedata source information.

YES enables prompting with a Data Link Properties dialog box. Towrite the initialization string to the SAS log, submit this codeimmediately after connecting to the data source:

%put %superq (SYSDBMSG);

NO does not enable prompting with a Data Link Properties dialogbox, and you must specify the data source (physical filename orPATH=).

REQUIRED enables connection without prompting for more informationonly if a valid physical filename is specified for a successfulconnection. Otherwise, you are prompted for the connectionoptions with a dialog box that enables you to change the datasource file and other properties.

NOPROMPT disables prompting with the Data Link Properties dialog box.

PROMPT enables prompting for connection information that supplies thedata source information.

UDL enables browsing so you can select an existing data link file(.udl).

UDL="path-for-udl-file"specifies the path and filename for a UDL file (a Microsoft data link file), as in thisexample:

UDL=’’C:\WinNT\profiles\me\desktop\MyDBLink.UDL’’;%put %superq(SYSDBMSG);

This option does not support SAS filerefs. Macro variable SYSDBMSG is set onsuccessful completion. For more information, refer to Microsoft documentationabout using data link.

Alias: UDL_FILE=

Note: This option should not be used with a physical filename or otherconnection options, such as PATH= and INIT=. �

Details

Using Data from a PC File You can use a LIBNAME statement to read from and writeto a data source table or view as if it were a SAS data set. The LIBNAME statementassociates a libref with a SAS/ACCESS engine to access tables or views in a spreadsheet

Page 93: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � LIBNAME Statement Syntax for PC Files on Microsoft Windows 85

or database. The SAS/ACCESS engine enables you to connect to a particular datasource and to specify an external data object name in a two-level SAS name.

For example, in MyPCLib.Employees_Q2, MyPCLib is a SAS libref that points to aparticular group of external data objects, and Employees_Q2 is a table name. When youspecify MyPCLib.Employees_Q2 in a DATA step or procedure, you dynamically accessthe external data object. SAS supports reading, updating, creating, and deletingexternal data objects dynamically.

Disassociating a Libref from a SAS Library To disassociate or clear a libref, use aLIBNAME statement, specifying the libref (MyPCLib, for example) and this CLEARoption:

libname mypclib CLEAR;

You can clear a single specified libref or all current librefs.SAS/ACCESS disconnects from the data source and closes any free threads or

resources that are associated with that libref’s connection.

Writing SAS Library Attributes to the SAS Log Use a LIBNAME statement and theLIST option to write the attributes of one or more SAS/ACCESS libraries or SASlibraries to the SAS log. Specify libref to list the attributes of a single SAS/ACCESSlibrary or SAS library, as follows:

libname mypclib LIST;

Specify _ALL_ to list the attributes of all libraries that have librefs in your currentsession.

Examples

Assigning a Libref with a SAS/ACCESS LIBNAME Statement This statement creates alibref, mymdb, as a Microsoft Access database file:

libname mymdb "c:\demo.mdb";

The Demo.mdb database contains a number of objects, including several tables, such asStaff. After you assign the libref, you can reference the Microsoft Access table like aSAS data set and use it as a data source in any DATA step or SAS procedure. In thisPROC SQL statement, MyMdb.Staff is the two-level SAS name for the Staff table in theMicrosoft Access database Demo.

proc sql;select idnum, lname

from mymdb.staffwhere state=’NY’order by lname;

quit;

You can use the Microsoft Access data to create a SAS data set:

data newds;set mymdb.staff(keep=idnum lname fname);

run;

You can also use the libref and data set with any other SAS procedure. Thisstatement prints the information in the Staff table:

proc print data=mymdb.staff;run;

Page 94: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

86 LIBNAME Options for PC Files on Microsoft Windows � Chapter 8

This statement lists the database objects in the MyMdb library:

proc datasets library=mymdb;quit;

This statement associates the SAS libref MYXLS with an Excel workbook:

libname myxls "c:\demo.xls";

See Also

“Overview: LIBNAME Statement for PC Files on Microsoft Windows” on page 81

LIBNAME Options for PC Files on Microsoft WindowsThese LIBNAME statement options provide enhanced control over the way that SAS

processes PC files data. For many tasks, you need not specify any of these advancedoptions.

Many of these options are also available as data set options.

ACCESS=READONLYindicates that tables and views can be read but not updated.

AUTOCOMMIT=YES | NOdetermines whether the ACCESS engine commits (saves) updates as soon as theuser submits them.

YESspecifies that updates are committed to a table as soon as they are submitted,and no rollback is possible.

NOspecifies that the SAS/ACCESS engine automatically performs the commitwhen it reaches the end of the file.

Default: NO

COMMAND_TIMEOUT=number-of-secondsspecifies the number of seconds that pass before a data source command times out.

Default: 0 [no time-out]Alias: TIMEOUT=

CONNECTION= SHAREDREAD | UNIQUE | GLOBALREADdetermines whether operations against a single libref share a connection to thedata source. Also determines whether operations against multiple librefs share aconnection to the data source.

SHAREDREADspecifies that all READ operations that access data source tables in a singlelibref share a single connection. A separate connection is established for eachtable that is opened for update or output operations.

Where available, this is usually the default value because it offers the bestperformance and it guarantees data integrity.

UNIQUEspecifies that a separate connection is established every time a data sourcetable is accessed by your SAS application.

Page 95: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � LIBNAME Options for PC Files on Microsoft Windows 87

Use UNIQUE if you want each use of a table to have its own connection.

GLOBALREADspecifies that all READ operations that access data source tables in multiplelibrefs share a single connection if these conditions are met:

� the participating librefs are created by LIBNAME statements thatspecify identical values for the CONNECTION= andCONNECTION_GROUP= options

� the participating librefs are created by LIBNAME statements thatspecify identical values for any data source connection options.

A separate connection is established for each table that is opened for updateor output operations.

GLOBALREAD is the default value for CONNECTION= when you specifyCONNECTION_GROUP=.

Default: SHAREDREAD

CONNECTION_GROUP= connection-groupcauses operations against multiple librefs to share a connection to the data source.Also causes operations against multiple Pass-Through Facility CONNECTstatements to share a connection to the data source.

CURSOR_TYPE=KEYSET_DRIVEN | STATICspecifies the cursor type for read-only cursors and for cursors to be updated. If youdo not set CURSOR_TYPE=, the Jet provider that you are using determines thedefault.

KEYSET_DRIVENspecifies that the cursor determines which rows belong to the result set whenyou open the cursor. Changes that are made to these rows are reflected as youmove the cursor. The OLE DB property DBPROP_OTHERUPDATEDELETEis set as TRUE for keyset cursors and FALSE for static cursors.

STATICspecifies that the complete result set is built when you open the cursor, butno changes that are made to the result set are reflected in the cursor. Staticcursors are read-only.

Default: none

Alias: CURSOR=

DBCOMMIT=number-of-rowsaffects update, delete, and insert processing. The number of rows that areprocessed includes rows that are not processed successfully. If you setDBCOMMIT=0, a commit is issued only once (after the procedure or DATA stepcompletes). If the DBCOMMIT= option is explicitly set, SAS/ACCESS fails anyupdate that has a WHERE clause.

Note: If you specify both DBCOMMIT= and ERRLIMIT=, and these optionscollide during processing, then the commit is issued first and the rollback is issuedsecond. Because the commit (caused by the DBCOMMIT= option) is issued beforethe rollback (caused by the ERRLIMIT= option), the DBCOMMIT= option is saidto override the ERRLIMIT= option in this situation. �

Default: 1,000 [inserting]0 [updating; commit occurs when data set or procedure completes]

Page 96: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

88 LIBNAME Options for PC Files on Microsoft Windows � Chapter 8

DBENCODING=12–byte-SAS-encoding-valuespecifies the encoding character set used in the Microsoft Access database or Excelworkbook file. For example, you can specify DBENCODING=’UTF-16’. For moredetailed information, see the DBENCODING= data set option“DBENCODING=Data Set Option” on page 97.

DBGEN_NAME=DBMS | SASspecifies that the data source columns are renamed and the format used for thenames.

DBMSspecifies that the data source columns are renamed to valid SAS variablenames. Disallowed characters are converted to underscores. If a column isconverted to an existing name, then a sequence number is appended to thenew name.

SASspecifies that data source columns are renamed to the format _COLn, wheren is the column number (starting with zero).

Default: DBMS

DBMAX_TEXT=nspecifies an integer between 1 and 32,767 that indicates the maximum length for acharacter string. Longer character strings are truncated. This option applies onlywhen you are reading, appending, and updating character data in a MicrosoftAccess database or Excel workbook from SAS. Although you can specify a value lessthan 256, it is not recommended for reading data from Microsoft Access database.

Default: 1,024

DBNULLKEYS=YES | NOspecifies column definitions.

YESIf there might be NULL values in the transaction table or the master tablefor the columns that you specify in the DBKEY= option, useDBNULLKEYS=YES. When you specify DBNULLKEYS=YES and specify acolumn that is not defined as NOT NULL in the DBKEY= data set option,SAS generates a WHERE clause that can find NULL values. For example, ifyou specify DBKEY=COLUMN and COLUMN is not defined as NOT NULL,SAS generates a WHERE clause with this syntax:

WHERE ((COLUMN = ?) OR ((COLUMN IS NULL) AND (? IS NULL)))

This syntax enables SAS to prepare the statement once and use it for anyvalue (NULL or NOT NULL) in the column. Note that this syntax has thepotential to be much less efficient than the shorter form of the WHEREclause (presented below).

NOWhen you specify DBNULLKEYS=NO or specify a column that is defined asNOT NULL in the DBKEY= option, SAS generates a simple WHERE clause.If you know that there are no NULL values in the transaction table or themaster table for the columns that you specify in the DBKEY= option, thenyou can use DBNULLKEYS=NO. If you specify DBNULLKEYS=NO andspecify DBKEY=COLUMN, SAS generates a shorter form of the WHEREclause—regardless of whether the column that DBKEY= specifies is definedas NOT NULL:

WHERE (COLUMN = ?)

Page 97: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � LIBNAME Options for PC Files on Microsoft Windows 89

Default: YES

DBSASLABEL=COMPAT | NONEspecifies whether SAS/ACCESS saves the data source column names as SAS labelnames. This option is valid only when you are reading data into SAS from thedata source.

COMPATspecifies that the data source column names are saved as SAS label names.This is compatible to the previous SAS releases.

NONEspecifies that the data source column names are not saved as SAS labelnames. SAS label names are left as null values.

Default: COMPAT

DEFER=NO | YESlets you specify when the connection to the data source occurs.

NOspecifies that the connection to the data source occurs when the libref isassigned by a LIBNAME statement.

YESspecifies that the connection to the data source occurs when a table in thedata source is opened.

Default: NO

DIRECT_SQL=YES | NO | NONE | specific-functionalityenables you to specify whether generated SQL is passed to the data source forprocessing.

YESspecifies that, whenever possible, generated SQL, except multiple outer joins,is passed to the data source for processing. This includes SQL that isgenerated from PROC SQL, SAS functions that can be converted into datasource functions, joins, and WHERE clauses.

NOspecifies that generated SQL from PROC SQL is not passed to the datasource for processing. This is the same as specifying the specific-functionalityvalue NOGENSQL.

NONEspecifies that generated SQL is not passed to the data source for processing.This includes SQL that is generated from PROC SQL, SAS functions that canbe converted into data source functions, joins, and WHERE clauses.

specific-functionalityidentifies types of processing to be handled by SAS instead of the data source.You can specify these values:

NOFUNCTIONScauses SAS to handle all SAS functions. The SAS functions are notconverted into data source functions and are not passed to the datasource for processing.

NOMULTOUTJOINScauses SAS to process outer joins that involve more than two tables.This option does not affect outer joins of two tables.

Note: This option is always turned ON for the Microsoft Jet engine. �

Page 98: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

90 LIBNAME Options for PC Files on Microsoft Windows � Chapter 8

NOGENSQLprevents PROC SQL from generating SQL to be passed to the datasource for processing.

NOWHEREprevents WHERE clauses from being passed to the data source forprocessing. This includes SAS WHERE clauses and PROC SQLgenerated or PROC SQL specified WHERE clauses.

Default: YES

FILELOCK= YES | NO [applies only to the Microsoft Excel LIBNAME engine; hasno effect on the Microsoft Access LIBNAME engine]

determines the type of access to the Microsoft Excel file. By default, FILELOCK= isnot set. SAS does not check whether the Excel file was opened by Excel or anotherapplication when you assign a LIBNAME statement for the file. A potential accessviolation can occur when a user attempts to update the Excel file using MicrosoftExcel. Specifying FILELOCK=YES indicates that the LIBNAME engine will checkand deny the connection if the file was opened by Excel or another application.

YESallows only one LIBNAME assignment with READ/WRITE permission toconnect to the file. The LIBNAME assignment is denied if the file has beenopened by Excel or another application. You can set FILELOCK=YES withACCESS=READONLY to assign a READONLY LIBNAME connection toallow other applications such as Microsoft Excel to open the Excel file inREADONLY mode to browse data at the same time.

NOspecifies that the Microsoft Excel LIBNAME engine behaves the same as inSAS 9.1.

Default: NO

INSERT_SQL= YES | NOdetermines the method that is used to insert rows into a data source.

YESspecifies that the SAS/ACCESS engine uses the data source’s SQL insertmethod to insert new rows into a table.

NOspecifies that the SAS/ACCESS engine uses an alternate (datasource-specific) method to add new rows to a table.

Default: NO

INSERTBUFF=number-of-rowsspecifies the number of rows for a multiple-rows insert. The value forINSERTBUFF= must be a positive number. If the INSERTBUFF= value is greaterthan the DBCOMMIT= value, the DBCOMMIT= value overrides it.

Note: When you assign a value that is greater than INSERTBUFF=1, the SASapplication notes that indicate the success or failure of the insert operation mightbe incorrect because these notes only represent information for a single insert,even when multiple inserts are performed. �

Default: 1

MSENGINE= ACE | JETdetermines the database engine used for accessing the Microsoft Excel file or theMicrosoft Access database. The Microsoft Jet engine is older and supports formatsup to 2003. The Microsoft Ace engine supports 2007 and older formats.

Page 99: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � LIBNAME Options for PC Files on Microsoft Windows 91

Restriction: It is recommended that you do not use this file option unless youare trying to create a 95 format file.

Default: ACE

READBUFF=number-of-rowsspecifies the number of rows to use when you are reading data from a data source.Setting a higher value for this option reduces I/O and increases performance, butalso increases memory usage. Additionally, if too many rows are read at once,values returned to SAS might be out of date.Default: 1Alias: ROWSET=

ROWSET_SIZE=

SCAN_TEXTSIZE=YES | NOspecifies whether to scan the length of text data for a data source column and usethe length of the longest string data found as the SAS column width.

YESscans the length of text data for a data source column and use the length ofthe longest string data found as the SAS variable width. However, if themaximum length found is greater than what is specified in theDBMAX_TEXT= option, the smaller value that is specified inDBMAX_TEXT= is applied as the SAS variable width.

For Microsoft Excel, this option applies to all character data type columns.For Microsoft Access, this applies only to the MEMO data type field and doesnot apply to the TEXT (less than 256 characters long) field.

NOdoes not scan the length of text data for a data source column. The columnlength that is returned from the Microsoft Jet provider is as the SAS variablewidth. However, if the returned column width is greater than what youspecify in DBMAX_TEXT=, the smaller value is applied as the SAS variablewidth.

Specify SCANTEXT=NO when you need to update data in the MicrosoftAccess database or Excel workbook.

Default: YES [Microsoft Excel workbook]NO [Microsoft Access database]

Alias: SCAN_TEXT=, SCANTEXT=, SCANMEMO=

SCAN_TIMETYPE=YES | NO | ANYspecifies whether to scan all row values for a DATETIME data type field andautomatically determine the TIME data type based on the setting. Option valuesYES and ANY turn on the scan function. Option value NO turns off the scanfunction.

YESspecifies that a column with all time values (internal value is less than 1) willbe assigned a TIME8. format.

NOspecifies that a column with date/time values will be assigned a DATE9.format or DATETIME19 format. Please refer to USE_DATETYPE= option formore information.

ANYspecifies that a column with any (one or more) time values will be assigned aTIME8. format.

Restriction: Available only for Microsoft Windows

Page 100: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

92 LIBNAME Options for PC Files on Microsoft Windows � Chapter 8

Default: NOAlias: SCAN_TIME=, SCANTIME=

SPOOL=YES | NOspecifies whether SAS creates a utility spool file during read transactions thatread data more than once.

YESspecifies that SAS creates a utility spool file into which it writes the rowsthat are read the first time. For subsequent passes through the data, therows are read from the utility spool file rather than being reread from thedata source table. This guarantees that the row set is the same for everypass through the data.

NOspecifies that the required rows for all passes of the data are read from thedata source table. No spool file is written. There is no guarantee that the rowset is the same for each pass through the data.

Default: YES

STRINGDATES=YES | NOspecifies whether datetime values are read from the data source as characterstrings or as numeric date values. STRINGDATES= is not available as a data setoption.

YESspecifies that SAS/ACCESS reads datetime values as character strings.

NOspecifies that SAS/ACCESS reads datetime values as numeric date values.

Default: NOAlias: STRDATES=

UNICODE=YES | NOdetermines whether the LIBNAME engine binds the character data type columnswith narrow or wide character mode. This option supersedes the DBENCODING=option. For DBCS (Chinese, Korean, and Japanese) users, it is recommended touse this option instead of the DBENCODING= option.

YESspecifies that SAS binds the character type columns with wide charactermode. This allows some character data such as DBCS to be returnedcorrectly. This setting works the same as setting DBENCODING="UTF-16".

NOspecifies that SAS binds the character type columns with narrow charactermode.

Default: NO

USE_DATETYPE=YES | NOspecifies whether to use DATE. format for datetime columns in the data sourcetable while importing data from Microsoft Access database or Excel workbook.

YESspecifies that the SAS DATE format is assigned for datetime columns in thedata source table.

NOspecifies that the SAS DATETIME format is assigned for datetime columns inthe data source table.

Page 101: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � AUTOCOMMIT= Data Set Option 93

Default: YES [Microsoft Excel workbook]NO {Microsoft Access database]

Alias: USE_DATE=, USEDATE=

Data Set Options for PC Files on Microsoft WindowsYou can specify SAS/ACCESS data set options on a SAS data set when you access PC

files data with the LIBNAME statement. A data set option applies only to the data seton which it is specified, and it remains in effect for the duration of the DATA step orprocedure.

This generic example illustrates the format of data set options:

LIBNAME libref engine-name;PROC PRINT libref.data-set-name(DATA_SET_OPTION=value)

You can use the CNTLLEV=, DROP=, FIRSTOBS=, IN=, KEEP=, OBS=, RENAME=,and WHERE= SAS data set options when you access PC files data. SAS/ACCESSinterfaces do not support the REPLACE= SAS data set option. For information aboutusing SAS data set options, refer to the SAS Language Reference: Dictionary.

Note: Specifying data set options in PROC SQL might reduce performance, becauseit prevents operations from being passed to the data source for processing. �

AUTOCOMMIT= Data Set Option

Determines whether the ACCESS engine commits (saves) updates as soon as the user submitsthem.

Valid in: DATA and PROC stepsDefault: LIBNAME option setting

SyntaxAUTOCOMMIT=YES | NO

Syntax Description

YESspecifies that updates are committed to a table as soon as they are submitted, and norollback is possible.

NOspecifies that the SAS/ACCESS engine automatically performs the commit when itreaches the end of the file.

Page 102: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

94 COMMAND_TIMEOUT= Data Set Option � Chapter 8

COMMAND_TIMEOUT= Data Set Option

Specifies the number of seconds to wait before a command times out.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: LIBNAME option setting

SyntaxCOMMAND_TIMEOUT=number-of-seconds

See AlsoTo assign this option to a group of tables, use the COMMAND_TIMEOUT= option

specified in “LIBNAME Options for PC Files on Microsoft Windows” on page 86.

CURSOR_TYPE= Data Set Option

Specifies the cursor type for read-only cursors and for cursors to be updated.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: LIBNAME option setting

SyntaxCURSOR_TYPE=KEYSET_DRIVEN | STATIC

Syntax Description

KEYSET_DRIVENspecifies that the cursor determines which rows belong to the result set when thecursor is opened. However, changes that are made to these rows are reflected as youmove the cursor.

STATICspecifies that the cursor builds the complete result set when the cursor is opened. Nochanges made to the rows in the result set after the cursor is opened are reflected inthe cursor. Static cursors are read-only.

DetailsBy default, this option is not set, and the Microsoft Jet provider uses a default. TheOLE DB properties applied to an open row set are as follows:

Page 103: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � DBCOMMIT= Data Set Option 95

CURSOR_TYPE= OLE DB Properties Applied

KEYSET_DRIVENDBPROP_OTHERINSERT=FALSE,DBPROP_OTHERUPDATEDELETE=TRUE

STATICDBPROP_OTHERINSERT=FALSE,DBPROP_OTHERUPDATEDELETE=FALSE

See your OLE DB programmer reference documentation for details about theseproperties.

See AlsoTo assign this option to a group of tables, use the CURSOR_TYPE= option specified

in “LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBCOMMIT= Data Set Option

Enables you to issue a commit statement automatically after a specified number of rows havebeen processed.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)

Default value: LIBNAME option setting

SyntaxDBCOMMIT=number-of-rows

Syntax Description

number-of-rowsis an integer greater than or equal to 0.

DetailsDBCOMMIT= affects update, delete, and insert processing. The number of rowsprocessed includes rows that are not processed successfully. When DBCOMMIT=0, acommit is issued only once (after the procedure or DATA step completes).

If the DBCOMMIT= option is explicitly set, SAS/ACCESS fails any update that has aWHERE clause.

Note: If you specify both DBCOMMIT= and ERRLIMIT=, and these options collideduring processing, then the commit is issued first and the rollback is issued second.Because the commit (caused by the DBCOMMIT= option) is issued before the rollback(caused by the ERRLIMIT= option), the DBCOMMIT= option is said to override theERRLIMIT= option in this situation. �

Page 104: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

96 DBCONDITION= Data Set Option � Chapter 8

Example

In this example a commit is issued after every 10 rows are inserted:

data myxls.dept(dbcommit=10);set mysas.staff;

run;

See AlsoTo assign this option to a group of tables, use the DBCOMMIT= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBCONDITION= Data Set Option

Specifies criteria for subsetting and ordering data.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: none

SyntaxDBCONDITION="SQL-query-clause"

Syntax Description

SQL-query-clauseis a data source-specific SQL query clause, such as WHERE, GROUP BY, HAVING,or ORDER BY.

DetailsThis option enables you to specify selection criteria in the form of data source-specificSQL query clauses, which the SAS/ACCESS engine passes directly to the data sourcefor processing. When selection criteria are passed directly to the data source forprocessing, performance is often enhanced. The data source checks the criteria forsyntax errors when it receives the SQL query.

The DBKEY= option is ignored when you use DBCONDITION=.

Page 105: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � DBENCODING= Data Set Option 97

DBCREATE_TABLE_OPTS= Data Set Option

Specifies data source-specific syntax to be added to the CREATE TABLE statement.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: LIBNAME option setting

SyntaxDBCREATE_TABLE_OPTS=’SQL-clauses’

Syntax Description

SQL-clausesare one or more data source-specific clauses that can be appended to the end of anSQL CREATE TABLE statement.

DetailsThis option enables you to add data source-specific clauses to the end of the SQLCREATE TABLE statement. The SAS/ACCESS engine passes the SQL CREATETABLE statement and its clauses to the data source, which executes the statement andcreates the table.

See AlsoTo assign this option to a group of tables, use the DBCREATE_TABLE_OPTS= option

specified in “LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBENCODING= Data Set Option

Specifies the encoding character set to use in the Microsoft Access database or in the Excelworkbook file.

Valid in: DATA and PROC steps.Default Value: NONE

SyntaxDBENCODING=’12–byte-SAS-encoding-value’;

Page 106: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

98 DBFORCE= Data Set Option � Chapter 8

Syntax Description

The 12–byte-SAS-encoding-value is an encoding value that SAS defines that can be upto 12 characters long. For a list of valid values, see the section “Encoding Values in SASLanguage Elements” in SAS National Language Support Reference Guide.

DetailsYou can use this option to specify the encoding character set to use in your Microsoft

Access database or Excel workbook file. Specify this option so SAS can transcodecharacter data between the SAS session encoding and the DBENCODING= value.

It is recommended that you use UNICODE=YES instead of DBENCODING=. SettingUNICODE=YES is equivalent to setting DBENCODING=’UTF-16’, which allows SAS tobind text data in wide character format and to transcode data between the SASsession—for example, Chinese BIG5 encoding—and the Microsoft Access or Excel file inunicode encoding. In a UTF-8 session, SAS assume that UNICODE=YES is set.

Transcoding is a process of converting text data from one encoding to anotherencoding. It does not translate from one language to another language. For example, itneither translates the English language to the Japanese language nor the Chineselanguage to the Japanese language, although it might map some Chinese characters toJapanese Hanzi characters.

DBFORCE= Data Set OptionSpecifies whether to force the truncation of data during insert processing.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: NO

SyntaxDBFORCE=YES | NO

Syntax Description

YESspecifies that the rows that contain data values that exceed the length of the columnare inserted, and the data values are truncated to fit the column length.

NOspecifies that the rows that contain data values that exceed the column length arenot inserted.

DetailsThis option determines how the SAS/ACCESS engine handles rows that contain datavalues that exceed the length of the column.

Page 107: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � DBKEY= Data Set Option 99

The SAS data set option FORCE= overrides this option when it is used with PROCAPPEND or the PROC SQL UPDATE statement. The PROC SQL UPDATE statementdoes not provide a warning before truncating the data.

DBGEN_NAME= Data Set OptionSpecifies whether to rename columns automatically when they contain disallowed characters.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: LIBNAME option setting

SyntaxDBGEN_NAME=DBMS | SAS

Syntax Description

DBMSspecifies that disallowed characters are converted to underscores.

SASspecifies that columns that contain disallowed characters are converted into validSAS variable names, using the format _COLn, where n is the column number(starting with zero). If a name is converted to a name that already exists, a sequencenumber is appended to the end of the new name.

DetailsSAS retains column names when reading data, unless a column name containscharacters that SAS does not allow, such as $ or @. SAS allows alphanumericcharacters and the underscore (_).

This option is intended primarily for National Language Support, notably theconversion of kanji to English characters because the English characters converted fromkanji are often those that are not allowed in SAS. If you specify DBGEN_NAME=SAS,a column named DEPT$AMT is renamed to _COLn where n is the column number. Ifyou specify DBGEN_NAME=DBMS, a column named DEPT$AMT is renamed toDEPT_AMT.

See AlsoTo assign this option to a group of tables, use the DBGEN_NAME= option specified

in “LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBKEY= Data Set OptionImproves performance for a join with a large data source table and a small SAS data set(specifies a column to use as an index).

Page 108: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

100 DBLABEL= Data Set Option � Chapter 8

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)

Default value: none

SyntaxDBKEY=(<’>column-1<’> <... <’>column-n<’>>)

Syntax Description

columnis the name of the column that forms the index on the data source table.

DetailsWhen processing a join that involves a large data source table and a relatively smallSAS data set, you might be able to use DBKEY= to improve performance.

CAUTION:Improper use of this option can harm performance. �

DBLABEL= Data Set Option

Specifies whether to use SAS variable labels as data source column names during outputprocessing.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)

Default value: NO

SyntaxDBLABEL=YES | NO

Syntax Description

YESspecifies that SAS variable labels are used as data source column names duringoutput processing.

NOspecifies that SAS variable names are used as data source column names.

DetailsThis option is valid only for creating data source tables.

Page 109: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � DBMAX_TEXT= Data Set Option 101

No more than 64 characters of SAS variable labels are written to Microsoft Access orMicrosoft Excel files.

Example

In this example, the SAS data set New is created with one variable C1, which isassigned a label of DeptNum. In the second DATA step, the MyDBLib.MyDept table iscreated by using DeptNum as the data source column name. By settingDBLABEL=YES, you can use the label as the column name.

data new;label c1=’deptnum’;c1=001;

run;

data mydblib.mydept(dblabel=yes);set new;

run;

proc print data=mydblib.mydept;run;

DBMAX_TEXT= Data Set Option

Determines the length of a very long data source character data type that is read into SAS orwritten from SAS when you are using a SAS/ACCESS engine.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: LIBNAME option setting

SyntaxDBMAX_TEXT= integer

Syntax Description

integeris a number between 1 and 32,767.

DetailsThis option applies to reading, appending, and updating rows in an existing table. Itdoes not apply when you are creating a table.

DBMAX_TEXT= is usually used with a very long character data type.Although you can specify a value less than 256, it is not recommended for reading

data from Microsoft Access database.

Page 110: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

102 DBNULL= Data Set Option � Chapter 8

See AlsoTo assign this option to a group of tables, use the DBMAX_TEXT= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBNULL= Data Set Option

Indicates whether NULL is a valid value for the specified columns when a table is created.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)

Default value: YES

SyntaxDBNULL= (column-name-1=YES | NO <...column-name-n=YES | NO > |_ALL_=YES

| NO)

Syntax Description

YESspecifies that the NULL value is valid for the specified columns.

NOspecifies that the NULL value is not valid for the specified columns.

DetailsThis option is valid only for creating data source tables. If you specify more than onecolumn name, the names must be separated with spaces.

The DBNULL= option processes values from left to right, so if you specify a columnname twice, or if you use the _ALL_ value, the last value overrides the first valuespecified for the column.

Only the Access engine—not the Excel engine—supports this option.

Examples

In this example, using the DBNULL= option prevents the EmpId and Jobcodecolumns in the new MyDBLib.MyDept2 table from accepting null values. If theEmployees table contains null values in the EmpId or Jobcode columns, the DATA stepfails.

data mydblib.mydept2(dbnull=(empid=no jobcode=no));set mydblib.employees;

run;

In this example, all columns in the new MyDBLib.MyDept3 table except for theJobcode column are prevented from accepting null values. If the Employees tablecontains null values in any column other than the Jobcode column, the DATA step fails.

Page 111: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � DBSASLABEL= Data Set Option 103

data mydblib.mydept3(dbnull=(_ALL_=no jobcode=YES));set mydblib.employees;

run;

DBNULLKEYS= Data Set Option

Controls the format of the WHERE clause when you use the DBKEY= data set option.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: LIBNAME setting

SyntaxDBNULLKEYS= YES | NO

DetailsIf there might be NULL values in the transaction table or the master table for thecolumns that you specify in the DBKEY= option, then use DBNULLKEYS=YES. Whenyou specify DBNULLKEYS=YES and specify a column that is not defined as NOTNULL in the DBKEY= data set option, SAS generates a WHERE clause that can findNULL values. For example, if you specify DBKEY=COLUMN and COLUMN is notdefined as NOT NULL, SAS generates a WHERE clause with this syntax:

WHERE ((COLUMN = ?) OR ((COLUMN IS NULL) AND (? IS NULL)))

This syntax enables SAS to prepare the statement once and use it for any value (NULLor NOT NULL) in the column. Note that this syntax has the potential to be much lessefficient than the shorter form of the WHERE clause (presented below). When youspecify DBNULLKEYS=NO or specify a column that is defined as NOT NULL in theDBKEY= option, SAS generates a simple WHERE clause.

If you know that there are no NULL values in the transaction table or the mastertable for the columns that you specify in the DBKEY= option, you can useDBNULLKEYS=NO. If you specify DBNULLKEYS=NO and specifyDBKEY=COLUMN, SAS generates a shorter form of the WHERE clause—regardless ofwhether the column that DBKEY= specifies is defined as NOT NULL:

WHERE (COLUMN = ?)

See AlsoTo assign this option to a group of tables, use the DBNULLKEYS= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBSASLABEL= Data Set Option

Specifies whether SAS/ACCESS saves the data source’s column names as SAS label names.

Page 112: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

104 DBSASTYPE= Data Set Option � Chapter 8

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: COMPAT

SyntaxDBSASLABEL= COMPAT | NONE

Syntax Description

COMPATspecifies that SAS/ACCESS saves the data source’s column names as SAS labelnames. This is compatible to the previous SAS releases.

NONEspecifies that SAS/ACCESS does not save the data source’s column names as SASlabel names. SAS label names are left as NULLs.

DetailsThis option is valid only while you are reading data into SAS from the data source.

DBSASTYPE= Data Set Option

Specifies data type(s) to override the default SAS data type(s) during input processing of data.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: none

SyntaxDBSASTYPE=(column-name-1=<’>SAS-data-type<’>

<...column-name-n=<’>SAS-data-type<’>>)

Syntax Description

column-namespecifies a data source column name.

SAS-data-typespecifies a SAS data type. SAS data types include CHAR(n), NUMERIC,DATETIME, DATE, TIME.

DetailsBy default, SAS/ACCESS converts each data source data type to a SAS data typeduring input processing. When you need a different data type, you can use this option

Page 113: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � ERRLIMIT= Data Set Option 105

to override the default and assign a SAS data type to each specified data source column.Some conversions might not be supported. If a conversion is not supported, SAS printsan error to the log.

DBTYPE= Data Set OptionSpecifies a data type to use instead of the default data source data type when SAS creates a datasource table.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: none

SyntaxDBTYPE=(column-name-1=<’>data-source-type<’>

<...column-name-n=<’>data-source-type<’>>)

Syntax Description

column-namespecifies a data source column name.

data-source-typespecifies a data source data type. See the documentation for your SAS/ACCESSinterface for the default data types for your data source.

DetailsBy default, SAS/ACCESS converts each SAS data type to a predetermined data sourcedata type when outputting data to your data source. When you need a different datatype, use DBTYPE= to override the default data type chosen by the SAS/ACCESSengine.

Example

In this example, DBTYPE= specifies the data types that are used when you createcolumns in the table.

data mydblib.newdept(dbtype=(deptno=’double’ city=’char(25)’));set mydblib.dept;

run;

ERRLIMIT= Data Set OptionSpecifies the number of errors that are allowed before SAS stops processing and issues a rollback.

Page 114: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

106 INSERT_SQL= Data Set Option � Chapter 8

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: 1

SyntaxERRLIMIT=integer

Syntax Description

integeris a positive integer that represents the number of errors after which SAS stopsprocessing and issues a rollback.

DetailsSAS calls the data source to issue a rollback after a specified number of errors occursduring the processing of inserts, deletes, updates, and appends. If ERRLIMIT= is set to0, SAS processes all rows, regardless of the number of errors that occur. The SAS logdisplays the total number of rows processed and the number of failed rows, if applicable.

The DBCOMMIT= option overrides the ERRLIMIT= option. If you specify a value forDBCOMMIT= other than zero, then rollbacks affected by the ERRLIMIT= option mightnot include records that are processed unsuccessfully because they were alreadycommitted by DBCOMMIT=.

Note: This option cannot be used from a SAS client session in a SAS/SHAREenvironment. �

Example

In this example, SAS stops processing and issues a rollback to the data source at theoccurrence of the tenth error. The MyDBLib libref was assigned in a prior LIBNAMEstatement.

data mydblib.employee3 (errlimit=10);set mydblib.employees;where salary > 40000;

run;

INSERT_SQL= Data Set Option

Determines the method that is used to insert rows into a data source.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: LIBNAME option setting

Page 115: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � INSERTBUFF= Data Set Option 107

SyntaxINSERT_SQL=YES | NO

Syntax Description

YESspecifies that the SAS/ACCESS engine uses the data source’s SQL insert method toinsert new rows into a table.

NOspecifies that the SAS/ACCESS engine uses an alternate (data source-specific)method to add new rows to a table.

See AlsoTo assign this option to a group of tables, use the INSERT_SQL= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

INSERTBUFF= Data Set Option

Specifies the number of rows in a single insert.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: LIBNAME option setting

SyntaxINSERTBUFF=number-of-rows

Syntax Description

number-of-rowsspecifies the number of rows to insert. The value must be a positive integer.

DetailsSAS allows the maximum number of rows that is allowed by the data source. Theoptimal value for this option varies with factors such as network type and availablememory. You might need to experiment with different values to determine the bestvalue for your site.

When you assign a value that is greater than INSERTBUFF=1, the SAS applicationnotes that indicate the success or failure of the insert operation might be incorrectbecause these notes only represent information for a single insert, even when multipleinserts are performed.

If the DBCOMMIT= option is specified with a value that is less than the value ofINSERTBUFF=, then DBCOMMIT= overrides INSERTBUFF=.

Page 116: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

108 NULLCHAR= Data Set Option � Chapter 8

Note: When you are inserting with the VIEWTABLE window or the FSEDIT orFSVIEW procedure, use INSERTBUFF=1 to prevent the data source interface fromtrying to insert multiple rows. These features do not support inserting more than onerow at a time. �

See AlsoTo assign this option to a group of tables, use the INSERTBUFF= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

NULLCHAR= Data Set Option

Indicates how SAS character missing values are handled during insert, update, and DBKEY=processing.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: YES

SyntaxNULLCHAR= YES | NO

Syntax Description

YESindicates that character missing values in SAS data sets are treated as NULL valuesif the data source allows them. Otherwise, an error is returned.

NOindicates that character missing values in SAS data sets are treated as theNULLCHARVAL= value (regardless of whether the data source allows NULLs for thecolumn).

DetailsThis option affects insert and update processing and also applies when you use theDBKEY= option.

This option works in conjunction with the NULLCHARVAL= data set option, whichdetermines what is inserted when NULL values are not allowed.

All SAS numeric missing values (represented in SAS as ’.’) are treated by the datasource as NULLs.

NULLCHARVAL= Data Set Option

Defines the character string that replaces SAS character missing values during insert, update, andDBKEY= processing.

Page 117: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Microsoft Windows � READBUFF= Data Set Option 109

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)

Default value: a blank character

SyntaxNULLCHARVAL=’character-string’

DetailsThis option affects insert and update processing and also applies when you use theDBKEY= option.

This option works with the NULLCHAR= option, which determines whether a SAScharacter NULL value is treated as a NULL value.

If NULLCHARVAL= is longer than the maximum column width, one of these actionsoccurs:

� The string is truncated if DBFORCE=YES.

� The operation fails if DBFORCE=NO.

READBUFF= Data Set Option

Specifies the number of rows of data to read into the buffer.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)

Default value: LIBNAME option setting

SyntaxREADBUFF=number-of-rows

Syntax Description

number-of-rowsis the maximum value that is allowed by the data source.

DetailsThis option improves performance by specifying a number of rows that can be held inmemory for input into SAS. Buffering data reads can decrease network activities andincrease performance. However, because SAS stores the rows in memory, higher valuesfor READBUFF= use more memory. In addition, if too many rows are selected at once,then the rows that are returned to the SAS application might be out of date.

When READBUFF=1, only one row is retrieved at a time. The higher the value forREADBUFF=, the more rows the SAS/ACCESS engine retrieves in one fetch operation.

ROWSET_SIZE is an alias for this option.

Page 118: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

110 SASDATEFMT= Data Set Option � Chapter 8

See AlsoTo assign this option to a group of tables, use the READBUFF= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

SASDATEFMT= Data Set Option

Changes the SAS date format of a data source column.

Valid in: DATA and PROC steps (when accessing PC files data using SAS/ACCESSsoftware)Default value: none

SyntaxSASDATEFMT=(data-source-date-column-1=’SAS-date-format’

<... data-source-date-column-n=’SAS-date-format’>)

Syntax Description

data-source-date-columnspecifies the name of a date column in a data source table.

SAS-date-formatspecifies a SAS date format that has an equivalent (like-named) informat. Forexample, DATETIME21.2 is both a SAS format and a SAS informat, so it is a validvalue for the SAS-date-format argument.

DetailsIf the date format of a SAS column does not match the date format of the correspondingdata source column, you must convert the SAS date values to the appropriate datasource date values. The SASDATEFMT= option enables you to convert date values fromthe default SAS date format to another SAS date format that you specify.

Use the SASDATEFMT= option to prevent date type mismatches under thesecircumstances:

� during input operations to convert data source date values to the correct SASDATE, TIME, or DATETIME values

� during output operations to convert SAS DATE, TIME, or DATETIME values tothe correct data source date values

If the SAS date format and the data source date format match, this option is notneeded.

The default SAS date format is data source-specific and is determined by the datatype of the data source column. See the documentation for your SAS/ACCESS interface.

Note: For non-English date types, SAS automatically converts the data to the SAStype of NUMBER. The SASDATEFMT= option does not currently handle these datetypes, but you can use a PROC SQL view to convert the data source data to a SAS dateformat as you retrieve the data, or use a format statement in other contexts. �

Page 119: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

111

C H A P T E R

9The Pass-Through Facility forPC Files on Microsoft Windows

Overview: Pass-Through Facility for PC Files on Microsoft Windows 111Syntax for the Pass-Through Facility for PC Files 112

Return Codes 112

Example 112

Microsoft Jet and Microsoft Ace Provider Supported Data Types 120

Examples 121Special Jet and Ace Queries 122

Examples 123

Special Jet Commands 124

Examples 124

Overview: Pass-Through Facility for PC Files on Microsoft WindowsThe SQL procedure implements the Structured Query Language (SQL) for SAS. See

the SQL procedure topic in Base SAS Procedures Guide for information about PROCSQL. You can send data source-specific SQL statements directly to a data source usingan extension to the SQL procedure called the Pass-Through Facility.

This facility uses SAS/ACCESS to connect to a data source and to send statementsdirectly to the data source for execution. This facility is an alternative to theSAS/ACCESS LIBNAME statement. It enables you to use the SQL syntax of your datasource, and it supports any non-ANSI standard SQL that is supported by your datasource.

You can use the Pass-Through Facility for these tasks:� establish and terminate connections with a data source using Pass-Through

Facility CONNECT and DISCONNECT statements� send dynamic, non-query, data source-specific SQL statements to a data source

using the facility’s EXECUTE statement� retrieve data directly from a data source using the facility’s CONNECTION TO

component in the FROM clause of a PROC SQL SELECT statement

You can use Pass-Through Facility statements in a PROC SQL query or you canstore them in a PROC SQL view. When you create a PROC SQL view, any argumentsthat you specify in the CONNECT statement are stored with the view. Therefore, whenthe view is used in a SAS program, SAS can establish the appropriate connection to thedata source.

Page 120: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

112 Syntax for the Pass-Through Facility for PC Files � Chapter 9

Syntax for the Pass-Through Facility for PC FilesThis section presents the syntax for the Pass-Through Facility statements and the

CONNECTION TO component. You can use this component with the PROC SQLSELECT statement to query data from a data source.

PROC SQL <options-list>;

CONNECT TO data-source-name <AS alias> <(<connect-statement-arguments><database-connection-arguments>)>;

DISCONNECT FROM data-source-name | alias;

EXECUTE (data-source-specific-SQL-statement) BY data-source-name | alias;

SELECT column-list FROM CONNECTION TO data-source-name | alias(data-source-query)

Return CodesAs you use the PROC SQL statements that are available in the Pass-Through

Facility, any error conditions are written to the SAS log. The Pass-Through Facilitygenerates return codes and messages that are available to you through these SASmacro variables:

SQLXRCcontains the data source return code that identifies the data source error.

SQLXMSGcontains descriptive information about the data source error that is generated bythe data source.

The contents of the SQLXRC and SQLXMSG macro variables are printed in the SASlog using the %PUT macro. They are reset after each Pass-Through Facility statementhas been executed.

ExampleTo connect to an Excel 2007 .xlsx file and query the INVOICE table (range) within

the Excel workbook:

PROC SQL DQUOTE=ANSI;CONNECT TO EXCEL (PATH="c:\sasdemo\sasdemo.xlsx");SELECT * FROM CONNECTION TO EXCEL

(SELECT * FROM INVOICE);DISCONNECT FROM EXCEL;QUIT;

Page 121: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The Pass-Through Facility for PC Files on Microsoft Windows � CONNECT Statement 113

CONNECT Statement

Establishes a connection with the data source.

Valid in: PROC SQL steps

SyntaxCONNECT TO data-source-name <AS alias> <(<connect-statement-arguments>

<database-connection-arguments>)>;

Argumentsdata-source-name

identifies the data source to which you want to connect, such as ACCESS forMicrosoft Access or EXCEL for Microsoft Excel. You can also specify an optionalalias in the CONNECT statement.

aliasspecifies an optional alias for the connection that has 1 to 32 characters. If youspecify an alias, the keyword AS must appear before the alias. If an alias is notspecified, the data source name is used as the name of the Pass-Throughconnection.

connect-statement-argumentsspecifies arguments that indicate whether you can make multipleconnections—shared or unique, or other connections—to the database. Thesearguments are optional.

database-connection-argumentsspecifies the data source-specific arguments that are needed by PROC SQL toconnect to the data source. These arguments are not required, and the defaultbehavior opens a dialog box.

Database Connection ArgumentsThe arguments that are listed below are available with the Pass-Through Facility forPC files.These arguments provide information to the Pass-Through Facility in order to connectto the PC files or to a database.

INIT= "connection-string"specifies an initialization string (that is, a connection string) when connecting to adata source.

PATH="path-for-file"specifies the data source file location for the Microsoft Access database file orMicrosoft Excel workbook file.

PROMPT=YES | NO |REQUIRED | NO PROMPT | PROMPT | UDLdetermines whether you are prompted for connection information to supply to thedata source information.

YES enables you to be prompted with the Data Link Propertieswindow.

Page 122: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

114 CONNECT Statement � Chapter 9

NO does not enable you to be prompted with a window. It requiresyou to specify the physical-filename.

REQUIRED lets you connect without prompting for more information only ifa valid physical filename is specified for a successfulconnection. Otherwise, you are prompted for the connectionoptions with a window that enables you to change the datasource file and other properties.

NOPROMPT disables the prompt of the Data Link Properties window.

PROMPT enables you to be prompted for connection information tosupply the data source information.

UDL enables you to browse and select an existing data link file (.udl).

Note: This statement also applies to the INIT= and UDL=options. �

UDL="path-for-udl-file"specifies the path and filename for a UDL (a Microsoft data link file), as in thisexample:

UDL_FILE="C:\WinNT\profiles\me\desktop\MyDBLink.udl’’;%put %superq(SYSDBMSG);

This option does not support SAS filerefs. The macro variable SYSDBMSG isset on successful completion. For more information, see Microsoft documentationon the data link API.

CONNECT Statement ArgumentsThe arguments that are listed below are available with the Pass-Through FacilityCONNECT statement for PC files. These arguments extend some of the LIBNAMEstatement connection management features to the Pass-Through Facility.

AUTOCOMMIT=YES | NOdetermines whether the ACCESS engine commits (saves) updates as soon as theuser submits them.

YESspecifies that updates are committed (that is, saved) to table as soon as theyare submitted, and no rollback is possible.

NOspecifies that the SAS/ACCESS engine automatically performs the commitwhen it reaches the end of the file.

Default: YES [different from the LIBNAME option default]

COMMAND_TIMEOUT=number-of-secondsspecifies the number of seconds that pass before a data source command times out.Default: 0 (no time-out)Alias: TIMEOUT=

CONNECTION= SHARED | GLOBALspecifies whether multiple CONNECT statements for a data source can use thesame connection. The CONNECTION= option enables you to control the numberof connections, and therefore transactions, that your SAS/ACCESS engine executesand supports for each CONNECT statement.

SHARED

Page 123: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The Pass-Through Facility for PC Files on Microsoft Windows � CONNECT Statement 115

specifies that the CONNECT statement makes one connection to the DBMS.Only Pass-Through statements that use this alias share the connection.

GLOBALspecifies that multiple CONNECT statements can share the same connectionto the DBMS if they use identical values for CONNECTION=,CONNECTION_GROUP=, and any database connection arguments.

Default: SHARED

CONNECTION_GROUP= connection-groupcauses operations against multiple librefs to share a connection to the data source.Also causes operations against multiple Pass-Through Facility CONNECTstatements to share a connection to the data source.

CURSOR_TYPE=KEYSET_DRIVEN | STATICspecifies the cursor type for read-only cursors and for cursors to be updated.

KEYSET_DRIVENspecifies that the cursor determines which rows belong to the result set whenthe cursor is opened. However, changes that are made to these rows arereflected as you move the cursor. The OLE DB propertyDBPROP_OTHERUPDATEDELETE is set as TRUE for keyset cursors andFALSE for static cursors.

STATICspecifies that the complete result set is built when the cursor is opened, butno changes made to the result set are reflected in the cursor. Static cursorsare read-only.

Default: none

Alias: CURSOR=

DBENCODING=12–byte-SAS-encoding-valuespecifies the encoding character set used in the Microsoft Access database or Excelworkbook file. For more information, see the DBENCODING= data setoptionDBENCODING= data set option“DBENCODING= Data Set Option” on page97.

DBGEN_NAME=DBMS | SASspecifies that the data source columns are renamed, and specifies the format thatthe new names follow.

DBMSspecifies that the data source columns are renamed to valid SAS variablenames. Disallowed characters are converted to underscores. If a column isconverted to a name that already exists, then a sequence number is appendedto the end of the new name.

SASspecifies that data source columns are renamed to the format _COLn, wheren is the column number (starting with zero).

Default: DBMS

DBMAX_TEXT=nspecifies an integer between 1 and 32,767 that indicates the maximum length for acharacter string. Longer character strings are truncated. This option applies onlywhen you are reading, appending, and updating Microsoft Access or Excelcharacter data from SAS.

Note: Although you can specify a value less than 256, it is not recommended. �

Page 124: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

116 CONNECT Statement � Chapter 9

Default: 1,024

DEFER=NO | YESenables you to specify when the connection to the data source occurs.

NOspecifies that the connection to the data source occurs when the libref isassigned by a LIBNAME statement.

YESspecifies that the connection to the data source occurs when a table in thedata source is opened.

Default: NO

MSENGINE= ACE | JETdetermines the database engine used for accessing the Microsoft Excel file or theMicrosoft Access database. The Microsoft Jet engine is older and supports formatsup to 2003. The Microsoft Ace engine supports 2007 and older formats.Restriction: It is recommended that you do not use this file option unless you

are trying to create a 95 format file.Default: ACE

READBUFF=number-of-rowsspecifies the number of rows to use when you are reading data from a data source.Setting a higher value for this option reduces I/O and increases performance, butalso increases memory usage. Additionally, if too many rows are read at once,values returned to SAS might be out of date.Default: 1Alias: ROWSET=

ROWSET_SIZE=

STRINGDATES=YES | NOspecifies whether datetime values are read from the data source as characterstrings or as numeric date values. STRINGDATES= is not available as a data setoption.

YESspecifies that SAS/ACCESS reads datetime values as character strings.

NOspecifies that SAS/ACCESS reads datetimes values as numeric date values.

Default: NOAlias: STRDATES

USE_DATETYPE=YES | NOspecifies whether to use DATE. format for date/time columns/fields in the datasource table while importing data from Microsoft Access database or Excelworkbook.

YESspecifies that SAS DATE format is assigned for datetime columns in the datasource table.

NOspecifies SAS DATETIME format is assigned for datetime columns in thedata source table.

Default: NOAlias: STRDATES

Page 125: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The Pass-Through Facility for PC Files on Microsoft Windows � DISCONNECT Statement 117

DetailsThe CONNECT statement establishes a connection with the data source. You establisha connection to send data source-specific SQL statements to the data source or toretrieve data source data. The connection remains in effect until you issue aDISCONNECT statement or terminate the SQL procedure.

Follow these steps to connect to a data source using the Pass-Through Facility:1 Initiate a PROC SQL step.2 Use the Pass-Through Facility’s CONNECT statement, identify the data source

(such as Microsoft Access or Excel), and assign an alias if you want.3 Specify any arguments needed to connect to the database.4 Specify any attributes for the connection.

The CONNECT statement is optional for some data sources. However, if you do notspecify it, default values for all database connection arguments are used.

Any return code or message that the data source generates is available in the macrovariables SQLXRC and SQLXMSG after the statement executes. See “Return Codes” onpage 112 for more information about these macro variables.

Example

This example uses the CONNECT statement with PATH= option to connect to theMicrosoft Access database file, c:/demo.mdb:

proc sql;connect to access as db (path="c:\demo.mdb");

DISCONNECT StatementTerminates the connection to the data source.

Valid in: PROC SQL steps

SyntaxDISCONNECT FROM data-source-name | alias

Argumentsdata-source-name

specifies the data source from which you want to disconnect. You can use an aliasin the DISCONNECT statement. The DISCONNECT statement’s data sourcename or alias must match the name or alias that you specified in the CONNECTstatement.

aliasspecifies an alias that was defined in the CONNECT statement.

DetailsThe DISCONNECT statement ends the connection with the data source. If theDISCONNECT statement is omitted, an implicit DISCONNECT is performed when

Page 126: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

118 EXECUTE Statement � Chapter 9

PROC SQL terminates. The SQL procedure continues to execute until you submit aQUIT statement, another SAS procedure, or a DATA step.

Any return code or message that is generated by the data source is available in themacro variables SQLXRC and SQLXMSG after the statement executes. See “ReturnCodes” on page 112 for more information about these macro variables.

Example

This example uses the QUIT statement to quit the SQL procedure after theconnection and SQL processing uses the DISCONNECT statement to disconnect theconnection from the database:

disconnect from db;quit;

EXECUTE Statement

Sends data source-specific, non-query SQL statements to the data source.

Valid in: PROC SQL steps

SyntaxEXECUTE (data-source-specific-SQL-statement) BY data-source-name | alias;

Arguments(data-source-specific-SQL-statement)

a dynamic nonquery, data source-specific SQL statement. This argument isrequired and must be enclosed in parentheses. However, the SQL statementcannot contain a semicolon because a semicolon represents the end of a statementin SAS. Depending on your data source, the SQL statement can be case-sensitive.It is passed to the data source exactly as you type it.

Any return code or message that is generated by the data source is available inthe macro variables SQLXRC and SQLXMSG after the statement executes. See“Return Codes” on page 112 for more information about these macro variables.

data-source-nameidentifies the data source to which you direct the data source-specific SQLstatement. The keyword BY must appear before the data-source-name argument.You must specify either the data source name or an alias.

aliasspecifies an alias that was defined in the CONNECT statement. (You cannot usean alias if the CONNECT statement is omitted.)

DetailsThe EXECUTE statement sends dynamic nonquery, data source-specific SQLstatements to the data source and processes those statements.

Page 127: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The Pass-Through Facility for PC Files on Microsoft Windows � CONNECTION TO Component 119

The EXECUTE statement cannot be stored as part of a Pass-Through Facility queryin a PROC SQL view.

Useful Statements to Include in EXECUTE StatementsYou can pass these statements to the data source by using the Pass-Through FacilityEXECUTE statement.

CREATEcreates a data source table, view, index, or other data source object, depending onhow the statement is specified.

DELETEdeletes rows from a data source table.

DROPdeletes a data source table, view, or other data source object, depending on howthe statement is specified.

INSERTadds rows to a data source table.

UPDATEmodifies the data in the specified columns of a row in a data source table.

For more information about these and other SQL statements, see the SQLdocumentation for your data source.

ExampleThis example uses the EXECUTE statement to drop a table, create a table, and insert arow of data after the connection:

execute(drop table ‘ My Invoice ‘ ) by db;execute(create table ‘ My Invoice ‘ (‘ Invoice Number ‘ LONG not null,‘ Billed To ‘ VARCHAR(20),‘ Amount ‘ CURRENCY,‘ BILLED ON ‘ DATETIME)) by db;execute(insert into ‘ My Invoice ‘values( 12345, ’John Doe’, 123.45, #11/22/2003#)) by db;

CONNECTION TO Component

Retrieves and uses data source data in a PROC SQL query or view.

Valid in: PROC SQL step SELECT statements

SyntaxCONNECTION TO data-source-name<AS alias><(database-connection-options)>

Page 128: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

120 Microsoft Jet and Microsoft Ace Provider Supported Data Types � Chapter 9

Argumentsdata-source-name

identifies the data source (Microsoft Access or Excel) to which you direct the datasource-specific SQL statement.

aliasspecifies an alias, if one was defined in the CONNECT statement.

database-connection-argumentsspecifies the data source-specific arguments that are needed by PROC SQL toconnect to the data source. These arguments are not required and the defaultbehavior opens a dialog box.

DetailsThe CONNECTION TO component specifies the data source connection that you wantto use or that you want to create (if you have omitted the CONNECT statement).CONNECTION TO then enables you to retrieve data source data directly through aPROC SQL query.

You use the CONNECTION TO component in the FROM clause of a PROC SQLSELECT statement:

SELECT column-listFROM CONNECTION TO data source-name (data source-query);

CONNECTION TO can be used in any FROM clause, including those in nestedqueries (that is, in subqueries).

You can store a Pass-Through Facility query in a PROC SQL view and then use thatview in SAS programs. When you create a PROC SQL view, any options that youspecify in the corresponding CONNECT statement are stored too. Thus, when thePROC SQL view is used in a SAS program, SAS can establish the appropriateconnection to the data source.

Because external data sources and SAS have different naming conventions, somedata source column names might be changed when you retrieve data source datathrough the CONNECTION TO component.

Note: You must use back quotes ( ‘ ), not single (’) or double quotes ("), to enclosenames that contain a space. �

Example

This example uses the CONNECTION TO component to query a table or a subtableafter the connection:

select * from connection to db(select * from ‘my invoice‘);select * from connection to db(select ‘Invoice Number‘, Amount from ‘my invoice‘);

Microsoft Jet and Microsoft Ace Provider Supported Data Types

The following table lists the valid data types that are supported by Jet provider. Youcan use these data types when you use the CREATE statement using the SQL

Page 129: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The Pass-Through Facility for PC Files on Microsoft Windows � Examples 121

Pass-Through Facility to create a table. You can also use the data types when you usedata set option DBTYPE= to change the data type for a loaded column.

Table 9.1 Microsoft Jet Provider Supported Data Types

Data Type Column SizeCreate

Parameters

Prefix/

SuffixComments

BIT 2

BYTE 3

SHORT 5

LONG 10

SINGLE 7

DOUBLE 15

DECIMAL 28 precision, scale See Note 1

COUNTER 10 See Note 2

GUID 16

CURRENCY 19

DATETIME 8 # See Note 3

VARCHAR 255 max length See Note 4

LONGTEXT 536,870,910 See Note 5

VARBINARY 255 See Note 4

BIGBINARY 4000

LONGBINARY 1,073,741,823 See Note 5

1 When using the data type DECIMAL, you can specify precision and scale.2 When using the option DBTYPE=, the data type COUNTER is valid only when you set

INSERT_SQL=YES. The data type COUNTER is supported only in the Pass-Through Facilitywhile creating a table.

3 When using the Pass-Through Facility to set a date/time value, you need to add the prefix andsuffix, #; for example, #01/01/2001#, and #03/12/1999 12:12:12#.

4 When using the data types VARCHAR or VARBINARY, you need to specify the maximum length.5 When using the data types LONGTEXT or LONGBINARY, you do not need to specify the

maximum length.

All Excel columns are nullable. You should not specify NOT NULL for a columnwhile creating an Excel table. However, you can specify NULL or NULL attributes for afield while creating an Excel table.

ExamplesThis first example connects to Excel, drops a table named DEMO, and creates a new

table.

proc sql;connect to excel as db (path=’c:\temp\demo.xls’filelock=yes);execute(drop table demo) by db;execute(create table demo(EmpID long, FirstName char(10),

Salary decimal(10,2), hiredate datetime)) by db;

Page 130: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

122 Special Jet and Ace Queries � Chapter 9

execute(insert into demo values(12345678, ’Michael’,123456.78, #07/01/2001#)) by db;

execute(insert into demo values(23456789, ’Howard’, 234567.89,#04/01/1983#)) by db;

execute(insert into demo values(34567890, ’Nancy’, null,#02/01/1982#)) by db;

execute(insert into demo values(34567890, ’Andy’, 456789.01,null)) by db;

select * from connection to db(select * from demo);disconnect from db;quit;

This next example connects to Access, drops a table named DEMO, and creates anew table.

proc sql;connect to Access as db (path=’c:\temp\demo.mdb’);execute(drop table demo) by db;execute(create table demo(EmpID long not null, FirstName char(10) not null,

Salary decimal(10,2), hiredate datetime)) by db;execute(insert into demo values(12345678, ’Michael’,

123456.78, #07/01/2001#)) by db;execute(insert into demo values(23456789, ’Howard’, 234567.89,

#04/01/1983#)) by db;execute(insert into demo values(34567890, ’Nancy’, null,

#02/01/1982#)) by db;execute(insert into demo values(34567890, ’Andy’, 456789.01,

null)) by db;select * from connection to db(select * from demo);disconnect from db;quit;

Special Jet and Ace Queries

SAS/ACCESS Interface to PC Files supports a number of special queries that returninformation such as available tables, columns, and procedures.

Here is the general format of special queries:

ACE | JET::schema-rowset<"parameter-1",...,"parameter-n">

where

ACE | JET::is required to distinguish special queries from regular queries.

schema-rowsetis the specific schema rowset that is being called. The valid schema rowsets arelisted below.

"parameter-n"is a quoted string. Parameters are separated from one another by commas. Allparameters are optional, but the parentheses must be included. If you specifysome, but not all, parameters within an argument, use commas to indicate theomitted parameters.

Page 131: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The Pass-Through Facility for PC Files on Microsoft Windows � Examples 123

These special queries are supported:

ACE | JET::CHECK_CONSTRAINTSreturns the check constraints that are defined in the database file.

ACE | JET::COLUMNS <“table-name”, “column-name”>returns the columns of the tables that are defined in the database file.

ACE | JET::CONSTRAINT_COLUMN_USAGE <“table-name”, “column-name”>returns the columns that are used by referential constraints, unique constraints,check constraints, and assertions that are defined in the database file.

ACE | JET::FOREIGN_KEYS <“primary-key-table-name”, “foreign-key-table-name”>returns the foreign key columns that are defined in the database file.

ACE | JET::INDEXES <“index-name”, “table-name”>returns the indexes that are defined in the database file.

ACE | JET::KEY_COLUMN_USAGE <“constraint-name”, “table-name”,“column-name”>

returns the key columns that are defined in the database file.

ACE | JET::PRIMARY_KEYS <“table-name”">returns the primary key columns that are defined in the database file.

ACE | JET::PROCEDURES <“procedure-name”>returns the procedures that are defined in the database file.

ACE | JET::PROVIDER_TYPESreturns information on the base data types that are supported by the Jet dataprovider.

ACE | JET::REFERENTIAL_CONSTRAINTS <“constraint-name”>returns the referential constraints that are defined in the database file.

ACE | JET::STATISTICS <“table-name”>returns the statistics that are defined in the database file.

ACE | JET::TABLE_CONSTRAINTS <“constraint-name”, “table-name”,“constraint-type”>

returns the table constraints that are defined in the database file.

ACE | JET::TABLES <“table-name”, “table-type”>returns the tables that are defined in the database file.

ACE | JET::VIEWS <“table-name”>returns the viewed tables that are defined in the database file.

ExamplesThis first example retrieves a rowset that displays all tables in the NorthWind

database:

proc sql;* connect to access database;connect to Access as db (path="c:\NorthWind.mdb");* list all tables including system tables and pass-through;select * from connection to db(jet::tables);* list table name and type where table type is TABLE only;select table_name, table_type from connection to db(jet::tables ,"TABLE";disconnect from db;‘

quit;

Page 132: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

124 Special Jet Commands � Chapter 9

In this next example, information is retrieved of all data types that the Ace or Jetprovider for Microsoft Access supports:

proc sql;connect to access (path="c:\NorthWind.mdb");select * from connection to access(jet::provider_types);

quit;

Special Jet CommandsMicrosoft Access and Microsoft Excel engines support several special commands in

the Pass-Through Facility.Here is the general format of special commands:

JET::command

where

JET::is required to distinguish special queries from regular queries.

These special commands are supported:

JET::COMMITcommits the transaction.

JET::ROLLBACKcauses a rollback in the transaction.

JET::AUTOCOMMITsets the COMMIT mode to AUTO and commits the transaction immediately.

JET::NOAUTOCOMMITsets the COMMIT mode to MANUAL. When the COMMIT mode is set toMANUAL, you must issue a COMMIT or ROLLBACK command to commit orrollback the transaction.

ExamplesThis example specifies the AUTOCOMMIT=NO connection option.

Note: Although these examples state indicate that they are for Microsoft Access, thesyntax is the same for both Microsoft Access and Microsoft Excel. �

proc sql;connect to access( path="d:\dbms\access\test.mdb" autocommit= no );

execute(create table x (c1 int) ) by access;execute(insert into x values( 1 ) ) by access;

/* To commit the table create and insert ; */execute(jet::commit) by access;

execute(insert into x values( 2 ) ) by access;/* To rollback the previous insert ; */

execute(jet::rollback) by access;

Page 133: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The Pass-Through Facility for PC Files on Microsoft Windows � Examples 125

execute(jet::autocommit) by access;/* the insert is automatically committed, you cannot rollback the insert. */

execute(insert into x values( 3 ) ) by access;

/* you should have a table created with 2 rows. */disconnect from access; quit;

Page 134: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

126

Page 135: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

127

C H A P T E R

10File-Specific Reference

Microsoft Excel Workbook Files 127Statements 127

Connection Options 128

Data Types Conversion 130

Processing Date/Time Values between SAS and Microsoft Excel 132

Microsoft Access Files 132Statements 132

Connection Options 132

Data Types Conversion 133

Processing Date/Time Values between SAS and Microsoft Access 136

Microsoft Excel Workbook Files

Statements

By default, the SAS LIBNAME statement connects to a Microsoft Excel file in limitedREAD/WRITE mode. Although you can read data, delete a table, or create a new table,you cannot update data or append a new data row. To allow data update and append,you can set the LIBNAME option, SCANTEXT-NO.

Because the SAS PROC SQL pass-through connects to a Microsoft Excel file inREAD/WRITE mode, you can read, write, and update data by passing SQL commandstatements.

CAUTION:Due to the use of the Microsoft Jet Excel engine and the Microsoft Ace Excel engine, theSAS engines for Excel have limited update and delete capability and also have someunsolved issues. You should therefore avoid using the update and delete features. Back upyour Excel files before you try using any update functions. �

CAUTION:Although SAS allows you to connect to an Excel file while the application is opening it, anyupdates to the Excel file can cause the SAS Excel engine to malfunction. It isrecommended that you close the application that is using the Excel file, disconnect, andthen reconnect the file in SAS. You can set the LIBNAME option, FILELOCK=YES, to makesure that Excel or other applications has not opened the connected Excel file. �

Page 136: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

128 Connection Options � Chapter 10

Connection OptionsYou can use this connection options in the LIBNAME statement or in the PROC SQL

CONNECT statement.

HEADER= YES | NOdetermines whether the first row of data in a Microsoft Excel range (orspreadsheet) are column names when SAS is reading data from a Microsoft Excelfile.

Aliases: HDR=, GETNAMES=

Default: YES

YES specifies to use the first row of data in an Excel range (orspreadsheet) as column names when SAS is reading data froman Excel file.

NO specifies not to use the first row of data as column names in anExcel range (or spreadsheet) when SAS is reading data from anExcel file. SAS generates and uses the variable names F1, F2,F3, and so on.

Note: This connection option is only for reading Microsoft Excel spreadsheets.This option is ignored when you are writing data to an Excel spreadsheet. �

MIXED=YES | NO; (available only for DBMS=EXCEL)specifies whether to convert numeric data values into character data values for acolumn that contains mixed data types. This option is valid only when you import(read) data from Excel. The Microsoft Ace/Jet Excel engine handles this option.

YESassigns a SAS character type for the column and converts all numeric datavalues to character data values when mixed data types are found. When youspecify MIXED=YES, the connection is set in import mode and no updatesare allowed.

CAUTION:Due to a limitation in the Microsoft Ace/Jet Excel engine, using MIXED=YEScould result in improper text variable lengths. �

NOassigns numeric or character type for the column, depending on the majorityof the type data that is found. Both numeric data in a character column andcharacter data in a numeric column are imported as missing values.

Default: NO

Restriction: This option is available only for Windows and for reading Excel datainto SAS. You cannot use this option for delimited files.

Registry settings might affect the behavior of the MIXED= option.For Microsoft Jet engine, these settings are located in the

[\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel]key of the Windows registry.

For Microsoft Ace engine, these settings are located in the[\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\AccesConnectivity Engine] key of the Windows registry.

Page 137: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � Connection Options 129

Table 10.1 Registry Settings for the MIXED Option

TypeGuessRows an integer type with a default value of 8. You can use the number ofrows in the worksheet range in scans to determine column types. Ifyou set this type to 0, all rows in the range are checked. Microsoftstates that the valid range of TypeGuessRows is 0–16. However,you could set as high as 16384 and it would still operate correctly.

CAUTION:Not only can changing the TypeGuessRows value cause ascan to fail if you set it higher than 16384, but it affectsany software that uses the Microsoft Jet provider to accessExcel file data, including accessing Excel data in aMicrosoft Access database. The TypeGuessRows value isregistered with and controlled by Microsoft. It is thereforerecommended that you set the value to 0. �

ImportMixedTypes a string type with a default value of Text. If a column contains morethan one type of data while scanning TypeGuessRows rows, the typeof the column is determined to be Text if the value of the setting isText. If the value of the setting is Majority, the most common typein the column determines the column type.

For the MIXED=YES option to work correctly, you should youchange TypeGuessingRows to 0 in the Microsoft Windows registryso that all rows in the specified range are scanned. As a result,when you use MIXED=YES, the Jet provider always assignscharacter type for columns with data of mixed data types andconverts numeric data to character data.

TypeGuessRows an integer type with a default value of 8. The number of rowsin the worksheet range is used to scan and determine columntypes. If set to 0, then all rows in the range are checked.Microsoft states that the valid range of TypeGuessRows is 0 to16. However, it can be set as high as 16384 and still operatecorrectly.

ImportMixedTypes a string type with a default value of Text. If a column containsmore than one type of data (during the scan of TypeGuessRowsrows), the type of the column is determined to be Text if thevalue of the setting is Text. If the value of the setting isMajority, then the most common type in the column determinesthe column type.

For the MIXED=YES option to work correctly, it is strongly recommended thatyou change TypeGuessingRows to 0 in the Windows registry so that all rows in thespecified range are scanned. As a result, when you use MIXED=YES, the Jetprovider always assigns character type for columns with mixed data types andconverts numeric data to character data.

CAUTION:These settings are registered by the Microsoft Jet Engine. Changing settings such asTypeGuessRows for Microsoft Jet Excel engine in the Windows registry affects allsoftware that uses Microsoft Jet engine to import data. This includes Microsoft Officeproducts, as well as other database products and application software. �

Page 138: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

130 Data Types Conversion � Chapter 10

VERSION=’2007’ |’2003’ | ’2002’ | ’2000’ | ’97’ | ’95’ | ’5’specifies the version of the file that you want to create if the file does not exist.Valid values are 2003, 2002, 2000, 97, 95, and 5. The default value is 97.Alias: VER=

Note: You do not need to specify this option if you do not know the version ofyour Microsoft Excel file. However, if you want to create a new Microsoft Excelfile, you can use this option to specify the version that you want to create. There isno need to specify the VERSION= value if you want to create a 2007 Excel .xlsb or.xlsx file. The file extension tells SMS the VERSION= value. �

Note: Versions 2003, 2002, 2000, and 97 are treated as the same format.Versions 95 and 5 are also treated as the same format. �

Data Types ConversionThis table shows the default SAS variable formats that SAS/ACCESS assigns to

Excel data types. These data types are assigned when you read data from MicrosoftExcel spreadsheets using the LIBNAME engine.

Table 10.2 Default SAS Formats Assigned for Excel Formats

Excel Column

Format

SAS Variable

Format

SAS Variable

Type

Text $w. Character

General Numeric

Number Numeric

Scientific Numeric

Percentage (See Note 3) Numeric

Fraction (See Note 3) Numeric

Currency DOLLAR21.2 Numeric

Accounting DOLLAR21.2 Numeric

Date DATE9. (See Note 1

and Note 2)

Numeric

Datetime DATE9. (See Note 1

and Note 2)

Numeric

Time DATE9. (See Note 1

and Note 2)

Numeric

1 The default format is DATE9. You can use USEDATE=NO to change format fromDATE. to DATETIME. You can also use the SASDATEFMT option to change the formatto other SAS date or date/time format.

2 Note that the SAS date/time value uses 01Jan1960 as a cutoff line, while the Jetprovider date/time value uses 30Dec1899 as a cutoff line for internal values.

3 To access Fraction or Percent format data in your Excel file, you can use theFORMAT statement to assign the FRACT. or PERCENT. format in your DATA step code.

The following table shows the default Excel data types that SAS/ACCESS assigns toSAS variable formats. These data types are assigned when you write SAS data to an

Page 139: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � Data Types Conversion 131

Excel file using the LIBNAME engine. You can override these default conversions byusing “DBTYPE= Data Set Option” on page 105 during output processing.

Table 10.3 Default Excel Formats Assigned for SAS Variable Formats

SAS Variable

Format

XLS Column

Data Type

$BINARYw. Text

$CHARw. Text

$HEX w. Text

$w. Text

w.d Number

BESTw. Number

BINARYw. Number

COMMA w.d Number

COMMAXw.d Number

Ew. Number

FRACTw. Number

HEXw. Number

NEGPARENw.d Number

PERCENTw.d Number

DOLLARw.d Currency

DOLLARXw.d Currency

DATEw. Date/Time

DATETIMEw.d Date/Time

DDMMYYw. Date/Time

HHMMw.d Date/Time

JULDAYw. Date/Time

JULIANw. Date/Time

MMDDYYw. Date/Time

MMYYw.d Date/Time

MONTHw. Date/Time

MOYYw. Date/Time

WEEKDATEw. Date/Time

WEEKDATXw. Date/Time

WEEKDAYw. Date/Time

Page 140: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

132 Processing Date/Time Values between SAS and Microsoft Excel � Chapter 10

SAS Variable

Format

XLS Column

Data Type

WORDDATEw. Date/Time

WORDDATXw. Date/Time

Processing Date/Time Values between SAS and Microsoft ExcelTo import date/time values from a Microsoft Excel file, the SAS LIBNAME engine

reads date/time values using the DATE format by default. However, you can set theLIBNAME option, USEDATE=NO, or the LIBNAME statement, USEDATE=NO. Usingthe IMPORT procedure, you can have date/time values read in using the DATETIMEformat.

To export SAS data values with DATE, TIME, or DATETIME format to a MicrosoftExcel file, SAS values are written into the Excel file using the DATE format. When yousee values with the date 1/0/1900 in Microsoft Excel, you need to format them using theTIME format before you can see the correct time values.

Microsoft Access Files

StatementsThe SAS LIBNAME statement connects to a Microsoft Access database MDB file in

READ/WRITE mode by default. The SAS CONNECT statement in PROC SQL alsoconnects in READ/WRITE mode by default. You can set the LIBNAME optionACCESS=READONLY to connect to the file in READONLY mode.

The SAS engine for the Microsoft Access database uses the Microsoft Jet Provider toconnect to Microsoft Access data in the MDB file. A connection requires an existingMDB file. The engine knows the version of the MDB file that the Microsoft Accessdatabase saves.

The engine supports some special queries, which return information such asavailable tables, primary keys, foreign keys, and indexes. For more information, seeChapter 9, “The Pass-Through Facility for PC Files on Microsoft Windows,” on page 111

Connection OptionsYou can use these connection options in the LIBNAME statement or in the PROC

SQL statement.

Note: You can use USER=, PASSWORD=, DBPASSWORD=, and DBSYSFILE= toaccess your .mdb files, but it does not change your current security settings for thosefiles. �

DBPASSWORD="database-file-password";enables you to access your file if you have database-level security set in your .mdbfile. A database password is case sensitive and can be defined in addition touser-level security. Do not include ampersands, quotation marks, or invisiblecharacters in your password.

Page 141: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � Data Types Conversion 133

Aliases: DBPWD=, DBPW=

DBSYSFILE=“workgroup-information-file”contains information about the users in a workgroup based on information thatyou define for your Microsoft Access database. Any user and group accounts orpasswords that you create are saved in the workgroup information file.

Alias: DBSYS=, WGB=

PASSWORD="user-password";specifies a password for the user account. A password can be 1 to 14 characterslong and can include any characters except ASCII character 0 (null). Passwordsare case sensitive. Do not include ampersands, quotation marks, or invisiblecharacters in your password.

Note: If you have user-level security set in your .mdb file, you need to use thisoption and the USER= option to be able to access your file. �Aliases: PWD=, PW=

USER= "user-ID";specifies a user account name. User names can be 1 to 20 characters long and caninclude alphabetic characters, accented characters, numbers, and spaces.

Note: If you have user-level security set in your .mdb file, you need to use thisoption and the PASSWORD= option to be able to access your file. �Aliases: UID=, USERID=

Data Types ConversionThe following table shows the default SAS variable formats that SAS/ACCESS

assigns to .mdb data types. These formats are assigned when you read data fromMicrosoft Access files using the LIBNAME engine.

Table 10.4 Default SAS Formats Assigned for MDB Data Types

MDB Field Data Type SAS Variable Format SAS Variable Type

YES|NO 2. Numeric

Number (FieldSize=Byte) 4. Numeric

Number(FieldSize=Integer)

6. Numeric

Number (FieldSize=LongInteger)

11. Numeric

Number (FieldSize=Single) Numeric

Number(FieldSize=Double)

Numeric

AutoNumber(FieldSize=Long Integer)

11. Numeric

AutoNumber(FieldSize=Replication ID)

$38. Character

CURRENCY DOLLAR21.2 Numeric

Date/Time DATETIME.

(See Note 1 and Note 2)

Numeric

Page 142: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

134 Data Types Conversion � Chapter 10

MDB Field Data Type SAS Variable Format SAS Variable Type

Text $w. (See Note 3) Character

Memo $w. (See Note 4) Character

OLE Object $w. (See Note 4) Character

Hyperlink $w. (See Note 4) Character

1 The default format is DATETIME. You can use USEDATE=YES to change formatfrom DATETIME. to DATE. You can also use the SASDATEFMT option to change theformat to other date or date/time formats.

2 The SAS date/time value uses 01Jan1960 as the cutoff date. The Jet provider date/time value uses 30Dec1899 as the cutoff date.

3 The width of $w. is equal to the field size of the column defined in your MicrosoftAccess table.

4 When SCANMEMO=YES (the default is value NO), the width value of $w. isdetermined by the longest string of data that is scanned in the field, or by the valuespecified in the DBMAX_TEXT option, whichever is less. Otherwise, when the optionSCAN_TEXT=NO, the width value of $w. is equal to the value specified inDBMAX_TEXT option.

The following table shows the default .mdb data types that SAS/ACCESS assigns toSAS variable formats. These data types are assigned when you write SAS data to an.mdb file using the LIBNAME engine. You can override these default conversions byusing “DBTYPE= Data Set Option” on page 105 during output processing.

Table 10.5 Default \DB Data Types Assigned for SAS Variable Formats

SAS Variable Format MDB Data Type

$BINARYw. Text (VarChar) or Memo (LongText) (See Note 1)

$CHARw. Text (VarChar) or Memo (LongText) (See Note 1)

HEX w. Text (VarChar) or Memo (LongText) (See Note 1)

$w. Text (VarChar) or Memo (LongText) (See Note 1)

w.d Number (See Note 2)

BESTw. Number (See Note 2)

BINARYw. Number (See Note 2)

COMMA w.d Number (See Note 2)

COMMAXw.d Number (See Note 2)

Ew. Number (See Note 2)

FRACTw. Number (See Note 2)

HEXw. Number (See Note 2)

NEGPARENw.d Number (See Note 2)

PERCENTw.d Number (See Note 2)

DOLLARw.d Currency

DOLLARXw.d Currency

DATEw. Date/Time

Page 143: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � Data Types Conversion 135

SAS Variable Format MDB Data Type

DATETIMEw.d Date/Time

DDMMYYw. Date/Time

HHMMw.d Date/Time

JULDAYw. Date/Time

JULIANw. Date/Time

MMDDYYw. Date/Time

MMYYw.d Date/Time

MONTHw. Date/Time

MOYYw. Date/Time

WEEKDATEw. Date/Time

WEEKDATXw. Date/Time

WEEKDAYw. Date/Time

WORDDATEw. Date/Time

WORDDATXw. Date/Time

1 If the character format length is greater than 255 characters, the loaded format isMemo; otherwise, the loaded format is Text.

2 For Microsoft Access 2000, 2002, and 2003, a SAS numeric data type with no formatspecified is converted to a number data type with a double field size. If the format isspecified as w. in SAS, the loaded data type in Microsoft Access is a number data typewith a long integer field size. If the format is specified as w.d in SAS, the loaded datatype in Microsoft Access is a number data type with a decimal field size. For MicrosoftAccess 97, if the format is specified as w. in SAS, the loaded data type in MicrosoftAccess is a number data type with a long integer field size. Otherwise, the SAS numericdata type is converted to a number data type with a double field size. However, you canset the SAS environment variable, LOAD_CBL=YES, to force a SAS numeric data typeto be loaded into a numeric data type with a Double field size. Here is an example:

data test;format j 5. k 6.2;i=123.45; j=12345; k=123.45;

run;

* The following PROC loads the Test1 table, which containsColumn i with a Double field size,Column j with a Long Integer field size,and Column k with a Decimal field size.

PROC EXPORT DATA=testOUTTABLE= "Test1"DBMS=ACCESS REPLACE;

DATABASE="c:\temp\test.mdb";RUN;

* The following PROC loads the Test2 table, which containsColumns i, j, and k, all of which have a Double field size.

options set=load_dbl yes;PROC EXPORT DATA=test

OUTTABLE= "Test2"DBMS=ACCESS REPLACE;

Page 144: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

136 Processing Date/Time Values between SAS and Microsoft Access � Chapter 10

DATABASE="c:\temp\test.mdb";RUN;

Processing Date/Time Values between SAS and Microsoft AccessTo import date/time values from a Microsoft Access database, the SAS LIBNAME

engine reads in the date/time values using the DATETIME format by default. However,you can set the LIBNAME option, USEDATE=YES, or the LIBNAME statement,USEDATE=YES. Using the IMPORT procedure, you can have date/time values read inusing the DATE format.

To export SAS data values with DATE, TIME, or DATETIME format to a MicrosoftAccess database, SAS values are written into the Microsoft Access database using theDate/Time data type. However, Microsoft Access can identify and display the values inthe correct DATE, TIME, or DATETIME format.

Page 145: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

137

P A R T4

LIBNAME Statement and Pass-ThroughFacility on Linux, UNIX, and 64-Bit MicrosoftWindows

Chapter 11. . . . . . . . .The PC Files Server on 32-Bit Microsoft Windows 139

Chapter 12. . . . . . . . .LIBNAME Statement: PC Files on Linux, UNIX, and 64-BitMicrosoft Windows 147

Chapter 13. . . . . . . . .Pass-Through Facility: PC Files on Linux, UNIX, and 64-BitMicrosoft Windows 177

Page 146: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

138

Page 147: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

139

C H A P T E R

11The PC Files Server on 32-BitMicrosoft Windows

Overview 139PC Files Server Modes 140

PC Files Server Installation 141

Running the PC Files Server as a Desktop Application 141

Configuring the PC Files Server 143

Port Number or Service Name 143Maximum Connections 143

Data Encryption 143

Running the PC Files Server as a Windows Service 144

Configuring the PC Files Server 144

Constraints 144

Shared Information 145

OverviewSAS PC Files Server is an application that listens to client requests. The Server

runs on either Microsoft 32-bit Windows or 64-bit Windows with Windows-on-Windows64-bit subsystem support (WOW64, an x86 emulator).

To access PC data, SAS/ACCESS Interface to PC Files must be installed on theclient. The PC Files Server must be installed and running on the Windows PC wherethe data resides.

Page 148: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

140 PC Files Server Modes � Chapter 11

Figure 11.1 PC Files Server

PC Files Server ModesStarting with SAS/ACCESS 9.2, the SAS PC Files Server can be run in two modes:

Server Mode (available before 9.2) and the enhanced Service Mode.

Server Moderuns the PC Files Server as a Windows desktop application. The user interface isa central location used to display server settings, client activity, and enablechanges to certain server settings.

Service Moderuns the PC Files Server as a Windows Service. The service runs the server in thebackground, and can be set to automatically start the server each time Windows isstarted.

CAUTION:Only one instance of the PC Fillers Server (Server Mode or Service Mode) can be runningon a single PC at any given time. �

Page 149: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The PC Files Server on 32-Bit Microsoft Windows � Running the PC Files Server as a Desktop Application 141

PC Files Server Installation

The installation sets the mode to Service Mode by default. If the installation is runwith the default settings, the PC Files Server is started and runs in Service Mode whenthe installation is complete.

To run the PC Files Server in Server Mode, clear the Service Mode option during theinstallation process. To run in Server Mode, as a desktop application, manual start-upis always required.

Note: By default, both modes are configured to listen to the same port; therefore,Server Mode and Service Mode cannot run concurrently. �

Running the PC Files Server as a Desktop ApplicationTo run the PC Files Server as a desktop application:1 Stop the server if it is running in Service Mode. See “Running the PC Files Server

as a Windows Service” on page 144.2 Start the server as a desktop application. Start � All Programs � SAS � PC

Files Server. The PC Files Server is started, and the application window isdisplayed on the desktop.

Page 150: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

142 Running the PC Files Server as a Desktop Application � Chapter 11

Figure 11.2 SAS PC Files Server

Main Menu: Server� Change Options: enables the Server Options to be modified� Restart Server: restarts the PC Files Server with the modified settings� Shutdown Server: stops the PC Files Server, closes the application window

Main Menu: Help� About PC Files Server: information about the PC Files Server

Server Name: Windows PC that started, and is running the PC Files ServerServer Options Group: connection information� Service/Port: port that listens for client requests to PC Files Server (default

8621)

Page 151: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The PC Files Server on 32-Bit Microsoft Windows � Configuring the PC Files Server 143

� Max Connections: maximum number of connections on this Server (default: ten)� Data Encryption: check to encrypt data during transfer� Change Options: enables the Server Options to be modified� Restart Server: restarts the PC Files Server with the modified settings� Shutdown Server: stops the PC Files Server, closes the application window� Host Name: populated when there is an active connection� User ID: populated when there is an active connection� DSN/File Access: populated when there is an active connection� Current Client Connections: current number of client connections

Note: When a single user opens multiple connections, the most currentinformation is displayed. �

� Peak Client Connections: greatest number of client connections

For changes to take effect, you must restart the server.

Configuring the PC Files ServerBoth Server Mode and Service Mode store the PC Files Server configuration settings

in the Windows registry. Changing the settings while in Server Mode affects the PCFiles Server running Service Mode.

Port Number or Service NameThe PC Files Server Port Number must be unique on a given PC. You cannot run

multiple servers (of any kind) that use the same port number on a single PC. You can,however, use the same PC Files Server Port Number on different PCs.

The Port Number for the PC Files Server defaults to 8621. 8621 is also the defaultport number used by the SAS LIBNAME statement for connections to PCFILES. If youchange the port number on the PC Files Server, everyone accessing that server mustadd the option PORT=number to their LIBNAME statement.

The Port Number or Service Name is saved in the Microsoft Windows registry. Theinformation is used each time the PC Files Server is run in Server Mode or Service Mode.

Maximum ConnectionsThe Max Connections field specifies the number of concurrent connections that the

server can support. The default is ten. Configure the number of connections based onthe load that you expect from your SAS clients.

When calculating potential connections, estimate one connection for every concurrentLIBNAME statement. Estimate two connections for every concurrent Import or Exportexecution. For example, if you have ten LIBNAME based connections executing Importor Export executions concurrently, set the Max Connections value to 20.

Client connections from an individual user are reused. Multiple LIBNAMEstatements can run on one client connection. If clients are using a mixture ofLIBNAME and procedure statements, increase the number of Max Connections.

The number of Max Connections is saved in the Microsoft Windows registry. Theinformation is used each time the PC Files Server is run in Server Mode or Service Mode.

Data EncryptionTo enable data encryption between the SAS/ACCESS Interface to PC Files on the

client and the SAS PC Files Server, check the Data Encryption check box.

Page 152: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

144 Running the PC Files Server as a Windows Service � Chapter 11

The state of the Data Encryption check box is saved in the Microsoft Windowsregistry. The information is used each time the PC Files Server is run in Server Modeor Service Mode.

Note: For any changes to take effect, it is required to restart the server. �

Running the PC Files Server as a Windows ServiceThe PC Files Server can be run as a Windows Service, even if Service Mode was not

selected during the PC Files Server installation.To manage the PC Files Server as a Windows Service, open the Services window:

Start � Control Panel � Administrative Tools � Services .Locate SAS PC Files Server in the list of services. Select Properties with the right

mouse button.Modify Startup type:

� Automatic: to start the PC Files Server as a Windows Service automatically whenthe system starts

� Manual: to manually start the PC Files Server as needed� Disable: to prevent the service from being started by the system, a user, or any

dependent device

Service status: reflects the current service status

� Start: The Windows Service starts the PC Files Server.� Stop: The Windows Service stops the PC Files Server.� Pause: The Windows Service pauses the PC Files Server.� Resume: The Windows Service resumes running the PC Files Server, after a pause.

Configuring the PC Files ServerIf you are running the PC Files Server in Service Mode, a separate user interface is

not provided. The default configuration should be sufficient for most installations. Tochange the configuration options, run the Server in Server Mode.

1 Stop the Windows Service that runs PC Files Server. See “Running the PC FilesServer as a Windows Service” on page 144.

2 Start the PC Files Server desktop application. See “PC Files Server Installation”on page 141.

3 Change the desired options.4 Stop the PC Files Server desktop application.5 Start the Windows Service that runs PC Files Server.

Constraints

� The PC Files Server can run in Server Mode or Service Mode; however, only oneinstance of the PC Files Server can be running on a single PC at any given time.

� Service names and port numbers must be unique on a given PC.� For any server changes to take effect, it is required to restart the server.

Page 153: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The PC Files Server on 32-Bit Microsoft Windows � Shared Information 145

� Each time you stop or restart the server or service, all users’ sessions are closed.Closing these sessions might result in loss of data.

� Although you can change PC Files Server configuration only in Server Mode, theupdated values also apply when running in Service Mode. When you stop the PCFiles Server in Server Mode, and start the PC Files Server in Service Mode, thenew settings are in effect.

Shared InformationOnce the PC Files Server is started and running, the clients need the following

information to access the PC Files Server:

� server name (host name, or IP address of the PC running PC Files Server)

� port number or service name. If you do not use the default value, you must specifythe port number in the LIBNAME statement on the client PC.

PORT=value

� path to any files, or ODBC data sources to which they have access that is relativeto the files system on the server PC, such as "C:\Excel files\mysheet.xls". Enclosethe path in double–quotes.

Page 154: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

146

Page 155: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

147

C H A P T E R

12LIBNAME Statement: PC Fileson Linux, UNIX, and 64-BitMicrosoft Windows

Overview: LIBNAME Statement for PC Files on Linux, UNIX, and 64-Bit Microsoft Windows 147Sorting PC Files Data 147

Using SAS Functions with PC Files Data 147

LIBNAME Options for PC Files on Linux and UNIX 153

Data Set Options for PC Files on Linux and UNIX 159

Overview: LIBNAME Statement for PC Files on Linux, UNIX, and 64-BitMicrosoft Windows

For PC files, the SAS/ACCESS LIBNAME statement extends the SAS globalLIBNAME statement to support assigning a libref to Microsoft Excel, Microsoft Access,and ODBC data sources. This enables you to reference spreadsheets, databases, andODBC sources directly in a DATA step or SAS procedure, and to read from and write toa Microsoft Access, Microsoft Excel, or ODBC table as if it were a SAS data set. Thissection specifies the “LIBNAME Statement Syntax for PC Files on Linux and UNIX” onpage 148 for this statement and provides “Examples” on page 151.

Sorting PC Files DataBecause librefs that refer to PC data refer to database and workbook objects such as

tables, they are stored in a format that differs from that of normal SAS data sets. Thisis important to remember when you access and work with PC files data.

For example, you can sort the observations in a normal SAS data set and store theoutput to another data set. However, in a Microsoft Access database, sorting data hasno effect on how it is stored. Because your data might not be sorted in the external file,you must sort the data at the time of query.

Furthermore, when you sort PC files data, the results might vary depending onwhether the external spreadsheet or database places data with NULL values (which aretranslated in SAS to missing values) at the beginning or the end of the result set.

Using SAS Functions with PC Files DataWhen you use librefs that refer to PC files data with SAS functions, some functions

might return a value different from what is returned when you use the functions withnormal SAS data sets. For example, the PATHNAME function normally returns thepathname for the assigned libref. However, when the libref refers to PC files data, thefunction might return a Microsoft Excel filename assigned for the libref.

Page 156: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

148 LIBNAME Statement Syntax for PC Files on Linux and UNIX � Chapter 12

Usage of some functions might also vary. For example, the LIBNAME function canaccept an optional SAS-data-library argument. When you use the LIBNAME functionto assign or deassign a libref that refers to PC files data, however, you omit thisargument. For full details about how to use SAS functions, see the SAS LanguageReference: Dictionary.

LIBNAME Statement Syntax for PC Files on Linux and UNIX

Associates a SAS libref with a workbook, database, or ODBC data source.

Valid in: anywhere

Syntaxu LIBNAME libref pcfiles

<connection-options><libname-options>;

v LIBNAME libref CLEAR | _ALL_ CLEAR;

w LIBNAME libref LIST | _ALL_ LIST;

Arguments

librefis any SAS name that serves as an alias to associate SAS with a spreadsheet, datasource, or database. Like the global SAS LIBNAME statement, the SAS/ACCESSLIBNAME statement creates shortcuts or nicknames for data storage locations.While a SAS libref is an alias for a virtual or physical directory, a SAS/ACCESS librefis an alias for the spreadsheet, data source, or database where your data is stored.

pcfilesis the SAS/ACCESS engine name for the interface to PC files on Linux and UNIX.

CLEARdeassigns one or more currently assigned librefs.

Specify libref to deassign a single libref. Specify _ALL_ to deassign all currentlyassigned librefs.

_ALL_specifies that the CLEAR or LIST argument applies to all currently assigned librefs.

LISTwrites the attributes of one or more SAS/ACCESS libraries or SAS libraries to theSAS log.

Specify libref to list the attributes of a single SAS/ACCESS library or SAS library.Specify _ALL_ to list the attributes of all libraries that have librefs in your currentsession.

connection-optionsprovide connection information to SAS/ACCESS to connect to your PC files. If theconnection options contain characters that are not allowed in SAS names, enclose thevalues of the arguments in quotation marks. In some instances, if you specify the

Page 157: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � LIBNAME Statement Syntax for PC Files on Linux and UNIX 149

appropriate system options or environment variables for your data source, you canomit the connection options.

See “Connection Options” on page 149 for detailed information about connectionoptions.

libname-optionsdefine how SAS interacts with your data source, and provide enhanced control of theway that SAS processes data source objects. For example, some LIBNAME optionscan improve performance. For many tasks, you do not need to specify any of theseadvanced options.

See “LIBNAME Options for PC Files on Microsoft Windows” on page 86 fordetailed information about LIBNAME options.

Connection OptionsSAS/ACCESS provides many ways to connect to your PC files.

Use these options when you are connecting to the PC Files Server.

DSN=“data-source-name”specifies the ODBC data source name that is used to access the PC data throughan ODBC driver on the PC.

Note: This ODBC data source must be defined on the PC where the PC FilesServer is currently running. �

CONNECT_STRING= “connection-string”specifies connection options for your data source or database. Separate multipleoptions with a semicolon. This is an advanced connection method that you shoulduse only when you know the exact syntax of all connection options that the ODBCdriver requires for a successful connection.

PATH=“pathname”specifies the location of the data file. This is the full path and filename for yourMicrosoft Access database file or Microsoft Excel workbook file. Always enter fileextension .mdb for Microsoft Access and .xls for Excel.

PORT=“port-number”specifies the port or service name that the SAS PC Files Server is listening on thePC. This port or service name is displayed on the PC Files Server control panelscreen when it is started on the PC. This is a required field when connecting to thePC Files Server for data.

Aliases: SERVICE, SERVICE_NAMEDefault 8621

SERVER=“pc-server-hostname”specifies the computer name of the PC on which you started the PC Files Server.This name is required by Linux and UNIX users to connect to this server machineand is reflected on the server control panel. This is a required field when you areconnecting to the PC Files Server for data.

You can specify this host name as a simple computer name (wxp320), a fullyqualified network name (wxp320.domain.com), or an IP address.

Use this option only for Microsoft Excel workbooks.

VERSION=2007|2003 | 2002 | 2000 | 97 | 95 | 5sets the version of Microsoft Excel workbook. The default value is 97.

Alias: VER

Note: You do not need to specify this option for an existing Microsoft Excel file.However, if you want to create a new Microsoft Excel workbook file, you can use

Page 158: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

150 LIBNAME Statement Syntax for PC Files on Linux and UNIX � Chapter 12

this option to specify the version that you want to create. Note that version 2007has unique file formats. Versions 97, 2000, and 2003 share the same file format.Versions 95 and 5 share a separate file format. �

Note: This option is ignored when connecting to a Microsoft Access database. �

Use these options only for Microsoft Access.

DBPASSWORD=“database-file-password”enables you to access your file if you have database-level security set in your .mdbfile. A database password is case sensitive, and you can define it instead ofuser-level security.

Aliases: DBPWD, DBPW, PASS, PASSWORD

DBSYSFILE=“workgroup-information-file”contains information about the users in a workgroup based on information thatyou define for your Microsoft Access database. Any user and group accounts orpasswords that you create are saved in the workgroup information file.

Alias: SYSTEMDB

MSENGINE= ACE | JETdetermines the database engine used for accessing the Microsoft Excel file or theMicrosoft Access database. The Microsoft Jet engine is older and supports formatsup to 2003. The Microsoft Ace engine supports 2007 and older formats.

Restriction: It is recommended that you do not use this file option unless youare trying to create a 95 format file.

Default: ACE

PASSWORD=“user-password”specifies a password for the user account, if required by the data source.Passwords are case sensitive.

Aliases: PWD, PW, PASS, PASSWORD

USER=“user-ID”specifies a user account name, if one is required to connect to the data source. ForMicrosoft Access, if you have user-level security set in your .mdb file, you need touse this option and the PASSWORD= option to be able to access your file.

Alias: UID

Use this option for Microsoft Excel or Microsoft Access.

TYPE=“file-type”specifies the file type of the file in the PATH= statement. Valid values of TYPE=are EXCEL or ACCESS. Use TYPE= if the file identified in the PATH= statementdoes not have the .xls or .mdb extension at the end of the name.

This example assigns the libref db for an Excel file:

libname db pcfiles server=D2323 port=8621 path=’c:\demo.xls’;

Details

Using Data from a PC File

You can use SAS/ACCESS Interface to PC Files on Linux and UNIX to directlyaccess PC data from Linux and UNIX. You can read from and write to a variety of PCfile data residing on a PC, including Microsoft Excel, Microsoft Access, and any otherODBC data source.

Page 159: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � LIBNAME Statement Syntax for PC Files on Linux and UNIX 151

The engine uses ODBC to support assigning a libref to Microsoft Excel and MicrosoftAccess files residing on a PC from Linux and UNIX. This enables you to referencespreadsheets, databases, and other ODBC data sources directly in a DATA step or SASprocedure, and to read from and write to a Microsoft Access or Excel object as if it werea SAS data set.

Disassociating a Libref from a SAS Library To disassociate or clear a libref, use aLIBNAME statement, specifying the libref (mypclib, for example) and this CLEARoption:

libname mypclib CLEAR;

You can clear a single specified libref or all current librefs.SAS/ACCESS disconnects from the data source and closes any free threads or

resources that are associated with that libref’s connection.

Writing SAS Library Attributes to the SAS Log Use a LIBNAME statement to write theattributes of one or more SAS/ACCESS libraries or SAS libraries to the SAS log.Specify libref to list the attributes of a single SAS/ACCESS library or SAS library, asshown here:

libname mypclib LIST;

Specify _ALL_ to list the attributes of all libraries that have librefs in your currentsession, as follows:

libname _ALL_ LIST;

Examples

Assigning a Libref to a Microsoft Access Database This statement creates the librefmymdb:

libname mymdb pcfiles server=D2323 port=8621 path="c:\demo.mdb";

The demo.mdb database contains a number of objects, including several tables, such asStaff. After you assign the libref, you can reference the Microsoft Access table like aSAS data set and use it as a data source in any DATA step or SAS procedure. In thisPROC SQL statement, mymdb.staff is the two-level SAS name for the Staff table in theMicrosoft Access database Demo.

proc sql;select idnum, lname

from mymdb.staffwhere state=’NY’order by lname;

quit;

You can use the Microsoft Access data to create a SAS data set:

data newds;set mymdb.staff(keep=idnum lname fname);

run;

You can also use the libref with any SAS procedure such as PROC SQL, PROCPRINT, PROC CONTENTS, and PROC DATASETS. This example uses PROCDATASETS to list all database objects in the library.

Proc datasets library=mymdb;Quit;

Page 160: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

152 LIBNAME Statement Syntax for PC Files on Linux and UNIX � Chapter 12

To improve performance, it is recommended that you use the data set optionsINSERTBUFF= and READBUFF= and set an appropriate value. This example creates atable named Invoice in a Microsoft Access database from a SAS data set named invoice:

Proc SQL;Create table mymdb.Invoice (insertbuff=25) as select * from invoice ;

Quit;

Assigning a Libref to a Microsoft Excel Workbook This statement creates a libref,myxls, for an Excel workbook:

libname myxls pcfiles server=D2323 port=8621 path="c:\demo.xls";

The demo.xls workbook contains a number of sheets, such as sheet1. After you assignthe libref, you can reference the Microsoft Excel spreadsheet like a SAS data set anduse it as a data source in any DATA step or SAS procedure. In this example a SAS dataset is created from an Excel sheet:

data a;set myxls.’sheet1$’n;

run;

Note: When using a LIBNAME statement with Excel, you must refer to Excelsheets as n-literals because of the “$” character. If you are referencing a named rangein an Excel spreadsheet, it is not necessary to refer to it as an n-literal.

This example shows how to reference a named range called pageone in an Excelworkbook:

data a;set myxls.pageone;

run;

You can also create an Excel file and use a SAS data set to populate a sheet in thatfile. A named range is also created for that sheet.

data myxls.air;set sashelp.air;

run;

You can also use the libref with any SAS procedure such as PROC SQL, PROCPRINT, PROC CONTENTS, and PROC DATASETS. This example uses PROCDATASETS to list all database objects in the library.

Proc datasets library=mymdb;Quit;

To improve performance, it is recommended that you use the data set optionREADBUFF= and set an appropriate value. This example reads in data from a rangecalled Invoice in the Microsoft Excel workbook.

Proc SQL;Select * from myxls.Invoice (readbuff=25) ;

Quit;

Note: Although you can set a value greater than 1 for the INSERTBUFF= option, itis ignored because the PC Files Server does not support the INSERTBUFF= option withvalue higher than 1 when writing data to an Excel file. �

Page 161: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � LIBNAME Options for PC Files on Linux and UNIX 153

Assigning a Libref to a Microsoft SQL Server Database This statement creates a libref,mysqlsrv, to a Microsoft SQL Server database via ODBC, using the server on the PC:

libname mysqlsrv pcfiles server=D2323 port=8621 dsn=MQIS user=scottpwd=tiger schema=dbo;

Using the mysqlsrv libref, a SAS data set called sqltest is created from the crimetable in the Microsoft SQL Server database:

data work.sqltest;set mysqlsrv.crime;

run;

or

proc sql;create table work.sqltest as select * from mysqlsrv.crime;

quit;

Using the mysqlsrv libref, a SQL Server table called newtable is created from theSAS data set, sqltest:

data mysqlsrv.newtable;set sqltest;

run;

Assigning a Libref to an Oracle Database This statement creates a libref, ora, to anOracle database table via ODBC, using the PC Files Server on the PC:

libname ora pcfiles server=D2323 port=8621 dsn=ORA9MSuser=scott pwd=tiger preserve_tab_names=yes;

Using the ora libref, an Oracle table, oratab, is created from a SAS data setsashelp.class:

data ora.oratab;set sashelp.class;

run;

Using the ora libref, a SAS data set, sastab, is created from the Oracle table emp:

data sastab;set ora.emp;

run;

LIBNAME Options for PC Files on Linux and UNIX

The following LIBNAME statement options provide enhanced control over the way thatSAS processes PC files data. Note that these are advanced options and you do not needto specify these options for many of the tasks you perform.

Many of these LIBNAME options are also available as data set options.

ACCESS=READONLYindicates that tables and views can be read but not updated.

AUTOCOMMIT=YES | NOdetermines whether the ACCESS engine commits (saves) updates as soon as theuser submits them.

Page 162: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

154 LIBNAME Options for PC Files on Linux and UNIX � Chapter 12

YESspecifies that updates are committed to a table as soon as they are submitted,and no rollback is possible.

NOspecifies that the SAS/ACCESS engine automatically performs the commitwhen it reaches the end of the file.

Default: NO

COMMAND_TIMEOUT=number-of-secondsspecifies the number of seconds that pass before a data source command times out.Default: 0 (no time-out)Alias: TIMEOUT=

CONNECTION= SHAREDREAD | UNIQUE | GLOBALREADdetermines whether operations against a single libref share a connection to thedata source. Also determines whether operations against multiple librefs share aconnection to the data source.

SHAREDREADspecifies that all READ operations that access data source tables in a singlelibref share a single connection. A separate connection is established for eachtable that is opened for update or output operations.

Where available, this is usually the default value because it offers the bestperformance and it guarantees data integrity.

UNIQUEspecifies that a separate connection is established every time a data sourcetable is accessed by your SAS application.

Use UNIQUE if you want each use of a table to have its own connection.

GLOBALREADspecifies that all READ operations that access data source tables in multiplelibrefs share a single connection if these conditions are met:

� the participating librefs are created by LIBNAME statements thatspecify identical values for the CONNECTION= andCONNECTION_GROUP= options

� the participating librefs are created by LIBNAME statements thatspecify identical values for any data source connection options.

A separate connection is established for each table that is opened for updateor output operations.

GLOBALREAD is the default value for CONNECTION= when you specifyCONNECTION_GROUP=.

Default: SHAREDREAD

CONNECTION_GROUP= connection-groupcauses operations against multiple librefs to share a connection to the data source.Also causes operations against multiple Pass-Through Facility CONNECTstatements to share a connection to the data source.

CURSOR_TYPE=DYNAMIC | FORWARD_ONLY | KEYSET_DRIVEN | STATICspecifies the cursor type for read-only cursors and for cursors to be updated.

DYNAMICspecifies that the cursor reflects all changes that are made to the rows in aresult set as you move the cursor. The data values and the membership ofrows in the cursor can change dynamically on each fetch. This is the defaultfor the DB2 UNIX, PC files, and Microsoft SQL Server interfaces.

Page 163: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � LIBNAME Options for PC Files on Linux and UNIX 155

FORWARD_ONLYspecifies that the cursor behaves like a DYNAMIC cursor, except that it onlysupports fetching the rows sequentially.

KEYSET_DRIVENspecifies that the cursor determines which rows belong to the result set whenthe cursor is opened. Note that changes that are made to these rows arereflected as you scroll around the cursor.

STATICspecifies that the complete result set is built when the cursor is opened. Nochanges that are made to the rows in the result set after the cursor is openedare reflected in the cursor. Static cursors are read-only.

Default: none

Alias: CURSOR=

DBCOMMIT=number-of-rowsaffects update, delete, and insert processing. The number of rows that areprocessed includes rows that are not processed successfully. If you setDBCOMMIT=0, a commit is issued only once (after the procedure or DATA stepcompletes). If the DBCOMMIT= option is explicitly set, SAS/ACCESS fails anyupdate that has a WHERE clause.

Note: If you specify both DBCOMMIT= and ERRLIMIT=, and these optionscollide during processing, then the commit is issued first and the rollback is issuedsecond. Because the commit (caused by the DBCOMMIT= option) is issued beforethe rollback (caused by the ERRLIMIT= option), the DBCOMMIT= option is saidto override the ERRLIMIT= option in this situation. �

Default: 1,000 (inserting) or 0 (updating; commit occurs when data set orprocedure completes)

DBGEN_NAME=DBMS | SASspecifies that the data source columns are renamed and the format that the namesfollow.

DBMSspecifies that the data source columns are renamed to valid SAS variablenames. Disallowed characters are converted to underscores. If a column isconverted to a name that already exists, then a sequence number is appendedto the end of the new name.

SASspecifies that data source columns are renamed to the format _COLn, wheren is the column number (starting with zero).

Default: DBMS

DBMAX_TEXT=nspecifies an integer between 1 and 32,767 that indicates the maximum length for acharacter string. Longer character strings are truncated. This option applies onlywhen you are reading, appending, and updating character data in a MicrosoftAccess database or Excel workbook from SAS. Although you can specify a value lessthan 256, it is not recommended for reading data from Microsoft Access database.

Default: 1,024

DBNULLKEYS=YES | NOspecifies column definitions.

Page 164: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

156 LIBNAME Options for PC Files on Linux and UNIX � Chapter 12

YESIf there might be NULL values in the transaction table or the master tablefor the columns that you specify in the DBKEY= option, useDBNULLKEYS=YES. When you specify DBNULLKEYS=YES and specify acolumn that is not defined as NOT NULL in the DBKEY= data set option,SAS generates a WHERE clause that can find NULL values. For example, ifyou specify DBKEY=COLUMN and COLUMN is not defined as NOT NULL,SAS generates a WHERE clause with this syntax:

WHERE ((COLUMN = ?) OR ((COLUMN IS NULL) AND (? IS NULL)))

This syntax enables SAS to prepare the statement once and use it for anyvalue (NULL or NOT NULL) in the column. Note that this syntax has thepotential to be much less efficient than the shorter form of the WHEREclause (presented below).

NOWhen you specify DBNULLKEYS=NO or specify a column that is defined asNOT NULL in the DBKEY= option, SAS generates a simple WHERE clause.If you know that there are no NULL values in the transaction table or themaster table for the columns that you specify in the DBKEY= option, thenyou can use DBNULLKEYS=NO. If you specify DBNULLKEYS=NO andspecify DBKEY=COLUMN, SAS generates a shorter form of the WHEREclause (regardless of whether or not the column specified in DBKEY= isdefined as NOT NULL):

WHERE (COLUMN = ?)

Default: YES

DBSASLABEL=COMPAT | NONEspecifies whether SAS/ACCESS saves the data source column names as SAS labelnames. This option is valid only when you are reading data into SAS from thedata source.

COMPATspecifies that the data source column names are saved as SAS label names.This is compatible to the previous SAS releases.

NONEspecifies that the data source column names are not saved as SAS labelnames. SAS label names are left as NULLs.

Default: COMPAT

DEFER=NO | YESenables you to specify when the connection to the data source occurs.

NOspecifies that the connection to the data source occurs when the libref isassigned by a LIBNAME statement.

YESspecifies that the connection to the data source occurs when a table in thedata source is opened.

Default: NO

DIRECT_SQL=YES | NO | NONE | specific-functionalityenables you to specify whether generated SQL is passed to the data source forprocessing.

Page 165: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � LIBNAME Options for PC Files on Linux and UNIX 157

YESspecifies that, whenever possible, generated SQL, except multiple outer joins,is passed to the data source for processing. This includes SQL that isgenerated from PROC SQL, SAS functions that can be converted into datasource functions, joins, and WHERE clauses.

NOspecifies that generated SQL from PROC SQL is not passed to the datasource for processing. This is the same as specifying the specific-functionalityvalue NOGENSQL.

NONEspecifies that generated SQL is not passed to the data source for processing.This includes SQL that is generated from PROC SQL, SAS functions that canbe converted into data source functions, joins, and WHERE clauses.

specific-functionalityidentifies types of processing to be handled by SAS instead of the data source.You can specify these values:

NOFUNCTIONScauses SAS to handle all SAS functions. The SAS functions are notconverted into data source functions and are not passed to the datasource for processing.

NOMULTOUTJOINScauses SAS to process outer joins that involve more than two tables.This option does not affect outer joins of two tables.

Note: This option is always turned ON for the Microsoft Jet engine. �

NOGENSQLprevents PROC SQL from generating SQL to pass to the data source forprocessing.

NOWHEREprevents WHERE clauses from being passed to the data source forprocessing. This includes SAS WHERE clauses and PROCSQL-generated or PROC SQL0specified WHERE clauses.

Default: YES

INSERTBUFF=number-of-rowsspecifies the number of rows for a multiple-row insert. The value forINSERTBUFF= must be a positive number. If the INSERTBUFF= value is greaterthan the DBCOMMIT= value, the DBCOMMIT= value overrides it. When youassign a value that is greater than INSERTBUFF=1, the SAS application notesthat indicate the success or failure of the insert operation might be incorrectbecause these notes represent information only for a single insert, even whenmultiple inserts are performed.Default: 1

READBUFF=number-of-rowsspecifies the number of rows to use when you are reading data from a data source.Setting a higher value for this option reduces I/O and increases performance, butalso increases memory usage. Additionally, if too many rows are read at once,values returned to SAS might be out of date.Default: 1Alias: ROWSET=

ROWSET_SIZE=

Page 166: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

158 LIBNAME Options for PC Files on Linux and UNIX � Chapter 12

SCAN_TEXTSIZE= YES | NOspecifies whether to scan the length of text data for a data source column and usethe length of the longest string data found as the SAS column width.

YESscans the length of text data for a data source column and use the length ofthe longest string data found as the SAS variable width. However, if themaximum length found is greater than what is specified in theDBMAX_TEXT= option, the smaller value that is specified inDBMAX_TEXT= is applied as the SAS variable width.

For Microsoft Excel, this option applies to all character data type columns.For Microsoft Access, this applies only to the MEMO data type field and doesnot apply to the TEXT (less than 256 characters long) field.

NOdoes not scan the length of text data for a data source column. The columnlength returned from Microsoft Jet provider is used as the SAS variablewidth. However, if the returned column width is greater than what isspecified in the DBMAX_TEXT= option, the smaller value specified inDBMAX_TEXT= is applied as the SAS variable width.

Note: Specify SCANTEXT=NO when you need to update data in theMicrosoft Access database or Excel workbook. �

Default: YES for Microsoft Excel workbookNO for Microsoft Access database

Alias: SCAN_TEXT=, SCANTEXT=, SCANMEMO=

SCAN_TIMETYPE=YES | NOspecifies whether to scan all row values for a DATETIME data type field andautomatically determine the TIME data type based on the setting. Option valuesYES turn on the scan function. Option value NO turns off the scan function.

YESspecifies that a column with all time values (internal value is less than 1) isassigned a TIME8. format.

NOspecifies that a column with date/time values is assigned a DATE9. format orDATETIME19 format. Please refer to USE_DATETYPE= option for moreinformation.

Default: NO

Alias: SCAN_TIME=, SCANTIME=

SPOOL=YES | NOspecifies whether SAS creates a utility spool file during read transactions thatread data more than once.

YESspecifies that SAS creates a utility spool file into which it writes the rowsthat are read the first time. For subsequent passes through the data, therows are read from the utility spool file rather than being reread from thedata source table. This guarantees that the row set is the same for everypass through the data.

NOspecifies that the required rows for all passes of the data are read from thedata source table. No spool file is written. There is no guarantee that the rowset is the same for each pass through the data.

Page 167: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � AUTOCOMMIT= Data Set Option 159

Default: YES

STRINGDATES=YES | NOspecifies whether datetime values are read from the data source as characterstrings or as numeric date values. STRINGDATES= is not available as a data setoption.

YESspecifies that SAS/ACCESS reads datetime values as character strings.

NOspecifies that SAS/ACCESS reads datetime values as numeric date values.

Default: NOAlias: STRDATES=

USE_DATETYPE=YES | NOspecifies whether to use DATE. format for datetime columns in the data sourcetable while importing data from Microsoft Access database or Excel workbook.

YESspecifies that the SAS DATE format is assigned for datetime columns in thedata source table.

NOspecifies that the SAS DATETIME format is assigned for datetime columns inthe data source table.

Default: YES for Microsoft Excel workbookNO for Microsoft Access database

Alias: USE_DATE=, USEDATE=

Data Set Options for PC Files on Linux and UNIX

You can specify SAS/ACCESS data set options on a SAS data set when you access PCfiles data with the “LIBNAME Statement Syntax for PC Files on Linux and UNIX” onpage 148LIBNAME statement. A data set option applies only to the data set on whichit is specified, and it remains in effect for the duration of the DATA step or procedure.

This generic example shows the format of data set options:

LIBNAME libref engine-name;PROC PRINT libref.data-set-name(DATA_SET_OPTION=value)

You can use the CNTLLEV=, DROP=, FIRSTOBS=, IN=, KEEP=, OBS=, RENAME=,and WHERE= SAS data set options when you access PC files data. The REPLACE=SAS data set option is not supported by SAS/ACCESS interfaces. For information aboutusing SAS data set options, refer to the SAS Language Reference: Dictionary.

Note: Specifying data set options in PROC SQL might reduce performance, becauseit prevents operations from being passed to the data source for processing. �

AUTOCOMMIT= Data Set Option

Determines whether the ACCESS engine commits (saves) updates as soon as the user submitsthem.

Page 168: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

160 COMMAND_TIMEOUT= Data Set Option � Chapter 12

Valid in: DATA and PROC steps

Default:LIBNAME option setting

SyntaxAUTOCOMMIT=YES | NO

Syntax Description

YESspecifies that updates are committed to a table as soon as they are submitted, and norollback is possible.

NOspecifies that the SAS/ACCESS engine automatically performs the commit when itreaches the end of the file.

COMMAND_TIMEOUT= Data Set Option

Specifies the number of seconds to wait before a command times out.

Valid in: DATA and PROC steps

Default value: LIBNAME option setting

SyntaxCOMMAND_TIMEOUT=number-of-seconds

See AlsoTo assign this option to a group of tables, use the COMMAND_TIMEOUT= option

specified in “LIBNAME Options for PC Files on Microsoft Windows” on page 86.

CURSOR_TYPE= Data Set Option

Specifies the cursor type for read-only cursors and cursors to update.

Valid in: DATA and PROC steps

Default value: none

Alias: CURSOR=

Page 169: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � DBCOMMIT= Data Set Option 161

SyntaxCURSOR_TYPE=DYNAMIC | FORWARD_ ONLY | KEYSET_DRIVEN | STATIC

Syntax Description

DYNAMICspecifies that the cursor reflects all changes that are made to the rows in a result setas you move the cursor. The data values and the membership of rows in the cursorcan change dynamically on each fetch. This is the default for the DB2 UNIX, PCfiles, and Microsoft SQL Server interfaces.

FORWARD_ONLYspecifies that the cursor behaves like a DYNAMIC cursor, except that it supportsonly fetching the rows sequentially.

KEYSET_DRIVENspecifies that the cursor determines which rows belong to the result set when thecursor is opened. Note that changes that are made to these rows are reflected as youscroll around the cursor.

STATICspecifies that the complete result set is built when the cursor is opened. No changesthat are made to the rows in the result set after the cursor is opened are reflected inthe cursor. Static cursors are read-only.

See AlsoTo assign this option to a group of tables, use the CURSOR_TYPE= option specified

in “LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBCOMMIT= Data Set Option

Lets you issue a commit statement automatically after a specified number of rows have beenprocessed.

Valid in: DATA and PROC steps

Default value: LIBNAME option setting

SyntaxDBCOMMIT=number-of-rows

Syntax Description

number-of-rowsis an integer greater than or equal to 0.

Page 170: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

162 DBCONDITION= Data Set Option � Chapter 12

DetailsDBCOMMIT= affects update, delete, and insert processing. The number of rowsprocessed includes rows that are not processed successfully. When DBCOMMIT=0, acommit is issued only once—after the procedure or DATA step completes.

If the DBCOMMIT= option is explicitly set, SAS/ACCESS fails any update that has aWHERE clause.

Note: If you specify both DBCOMMIT= and ERRLIMIT=, and these options collideduring processing, then the commit is issued first and the rollback is issued second.Because the commit (caused by the DBCOMMIT= option) is issued before the rollback(caused by the ERRLIMIT= option), the DBCOMMIT= option is said to override theERRLIMIT= option in this situation. �

Example

In this example, a commit is issued after every 10 rows are inserted:

data myxls.dept(dbcommit=10);set mysas.staff;

run;

See AlsoTo assign this option to a group of tables, use the DBCOMMIT= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBCONDITION= Data Set Option

Specifies criteria for subsetting and ordering data.

Valid in: DATA and PROC stepsDefault value: none

SyntaxDBCONDITION="SQL-query-clause"

Syntax Description

SQL-query-clauseis a data source-specific SQL query clause, such as WHERE, GROUP BY, HAVING,or ORDER BY.

DetailsThis option enables you to specify selection criteria in the form of data source-specificSQL query clauses, which the SAS/ACCESS engine passes directly to the data sourcefor processing. When selection criteria are passed directly to the data source for

Page 171: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � DBFORCE= Data Set Option 163

processing, performance is often enhanced. The data source checks the criteria forsyntax errors when it receives the SQL query.

The DBKEY= option is ignored when you use DBCONDITION=.

DBCREATE_TABLE_OPTS= Data Set Option

Specifies data source-specific syntax to add to the CREATE TABLE statement.

Valid in: DATA and PROC steps

Default value: LIBNAME option setting

SyntaxDBCREATE_TABLE_OPTS=’SQL-clauses’

Syntax Description

SQL-clausesare one or more data source-specific clauses that can be appended to the end of anSQL CREATE TABLE statement.

DetailsThis option enables you to add data source-specific clauses to the end of the SQLCREATE TABLE statement. The SAS/ACCESS engine passes the SQL CREATETABLE statement and its clauses to the data source, which executes the statement andcreates the table.

See AlsoTo assign this option to a group of tables, use the DBCREATE_TABLE_OPTS= option

specified in “LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBFORCE= Data Set Option

Specifies whether to force the truncation of data during insert processing.

Valid in: DATA and PROC steps

Default value: NO

SyntaxDBFORCE=YES | NO

Page 172: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

164 DBGEN_NAME= Data Set Option � Chapter 12

Syntax Description

YESspecifies that the rows that contain data values that exceed the length of the columnare inserted, and the data values are truncated to fit the column length.

NOspecifies that the rows that contain data values that exceed the column length arenot inserted.

DetailsThis option determines how the SAS/ACCESS engine handles rows that contain datavalues that exceed the length of the column.

The SAS data set option FORCE= overrides this option when it is used with PROCAPPEND or the PROC SQL UPDATE statement. The PROC SQL UPDATE statementdoes not provide a warning before truncating the data.

DBGEN_NAME= Data Set Option

Specifies whether to rename columns automatically when they contain disallowed characters.

Valid in: DATA and PROC stepsDefault value: LIBNAME option setting

SyntaxDBGEN_NAME=DBMS | SAS

Syntax Description

DBMSspecifies that disallowed characters are converted to underscores.

SASspecifies that columns that contain disallowed characters are converted into validSAS variable names, using the format _COLn, where n is the column number(starting with zero). If a name is converted to a name that already exists, a sequencenumber is appended to the end of the new name.

DetailsSAS retains column names when reading data, unless a column name containscharacters that SAS does not allow, such as $ or @. SAS allows alphanumericcharacters and the underscore (_).

This option is intended primarily for National Language Support, notably theconversion of kanji to English characters because the English characters that areconverted from kanji are often not allowed in SAS. If you specify DBGEN_NAME=SAS,

Page 173: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � DBLABEL= Data Set Option 165

a column named DEPT$AMT is renamed to _COLn where n is the column number. Ifyou specify DBGEN_NAME=DBMS, a column named DEPT$AMT is renamed toDEPT_AMT.

See AlsoTo assign this option to a group of tables, use the DBGEN_NAME= option specified

in “LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBKEY= Data Set Option

Improves performance by specifying a column to use as an index when you process a join thatinvolves a large data source table and a small SAS data set.

Valid in: DATA and PROC stepsDefault value: none

SyntaxDBKEY=(<’>column-1<’> <... <’>column-n<’>>)

Syntax Description

columnis the name of the column that forms the index on the data source table.

DetailsWhen processing a join that involves a large data source table and a relatively smallSAS data set, you might be able to use DBKEY= to improve performance.

CAUTION:Improper use of this option can harm performance. �

DBLABEL= Data Set Option

Specifies whether to use SAS variable labels as data source column names during outputprocessing.

Valid in: DATA and PROC stepsDefault value: NO

SyntaxDBLABEL=YES | NO

Page 174: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

166 DBMAX_TEXT= Data Set Option � Chapter 12

Syntax Description

YESspecifies that SAS variable labels are used as data source column names duringoutput processing.

NOspecifies that SAS variable names are used as data source column names.

Details

This option is valid only for creating data source tables.

Note: Only up to 64 characters of SAS variable labels are written to MicrosoftAccess or Microsoft Excel files. �

Example

In this example, the SAS data set New is created with one variable C1. This variableis assigned a label of DeptNum. In the second DATA step, the MyDBLib.MyDept tableis created by using DeptNum as the data source column name. When DBLABEL=YES,you can use the label as the column name.

data new;label c1=’deptnum’;c1=001;

run;

data mydblib.mydept(dblabel=yes);set new;

run;

proc print data=mydblib.mydept;run;

DBMAX_TEXT= Data Set Option

Determines the length of a very long data source character data type that is read into SAS orwritten from SAS when you are using a SAS/ACCESS engine.

Valid in: DATA and PROC steps

Default value: LIBNAME option setting

SyntaxDBMAX_TEXT= integer

Page 175: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � DBNULL= Data Set Option 167

Syntax Description

integeris a number between 1 and 32,767.

DetailsThis option applies to reading, appending, and updating rows in an existing table. Itdoes not apply when you are creating a table.

DBMAX_TEXT= is usually used with a very long character data type.Although you can specify a value less than 256, it is not recommended for reading

data from Microsoft Access database.

See AlsoTo assign this option to a group of tables, use the DBMAX_TEXT= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBNULL= Data Set Option

Indicates whether NULL is a valid value for the specified columns when a table is created.

Valid in: DATA and PROC steps

Default value: YES

SyntaxDBNULL= (column-name-1=YES | NO <...column-name-n=YES | NO > |_ALL_=YES

| NO)

Syntax Description

YESspecifies that the NULL value is valid for the specified columns.

NOspecifies that the NULL value is not valid for the specified columns.

DetailsThis option is valid only for creating data source tables. If you specify more than onecolumn name, the names must be separated with spaces.

The DBNULL= option processes values from left to right, so if you specify a columnname twice, or if you use the _ALL_ value, the last value overrides the first valuespecified for the column.

Only the Access engine—not the Excel engine—supports this option.

Page 176: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

168 DBNULLKEYS= Data Set Option � Chapter 12

Examples

In this example, by using the DBNULL= option, the EmpId and Jobcode columns inthe new MyDBLib.MyDept2 table are prevented from accepting null values. If theEmployees table contains null values in the EmpId or Jobcode columns, the DATA stepfails.

data mydblib.mydept2(dbnull=(empid=no jobcode=no));set mydblib.employees;

run;

In this example, all columns in the new MyDBLib.MyDept3 table except for theJobcode column are prevented from accepting null values. If the Employees tablecontains null values in any column other than the Jobcode column, the DATA step fails.

data mydblib.mydept3(dbnull=(_ALL_=no jobcode=YES));set mydblib.employees;

run;

DBNULLKEYS= Data Set Option

Controls the format of the WHERE clause when you use the DBKEY= data set option.

Valid in: DATA and PROC steps

Default value: LIBNAME setting

SyntaxDBNULLKEYS= YES | NO

DetailsIf there might be NULL values in the transaction table or the master table for thecolumns that you specify in the DBKEY= option, then use DBNULLKEYS=YES. Whenyou specify DBNULLKEYS=YES and specify a column that is not defined as NOTNULL in the DBKEY= data set option, SAS generates a WHERE clause that can findNULL values. For example, if you specify DBKEY=COLUMN and COLUMN is notdefined as NOT NULL, SAS generates a WHERE clause with this syntax:

WHERE ((COLUMN = ?) OR ((COLUMN IS NULL) AND (? IS NULL)))

This syntax enables SAS to prepare the statement once and use it for any value (NULLor NOT NULL) in the column. Note that this syntax has the potential to be much lessefficient than the shorter form of the WHERE clause (presented below). When youspecify DBNULLKEYS=NO or specify a column that is defined as NOT NULL in theDBKEY= option, SAS generates a simple WHERE clause.

If you know that there are no NULL values in the transaction table or the mastertable for the columns that you specify in the DBKEY= option, you can useDBNULLKEYS=NO. If you specify DBNULLKEYS=NO and specifyDBKEY=COLUMN, SAS generates a shorter form of the WHERE clause (regardless ofwhether or not the column specified in DBKEY= is defined as NOT NULL):

Page 177: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � DBTYPE= Data Set Option 169

WHERE (COLUMN = ?)

See AlsoTo assign this option to a group of tables, use the DBNULLKEYS= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

DBSASTYPE= Data Set Option

Specifies one or more data types to override one or more default SAS data types during inputprocessing of data.

Valid in: DATA and PROC steps

Default value: none

SyntaxDBSASTYPE=(column-name-1=<’>SAS-data-type<’>

<...column-name-n=<’>SAS-data-type<’>>)

Syntax Description

column-namespecifies a data source column name.

SAS-data-typespecifies a SAS data type. SAS data types include CHAR(n), NUMERIC,DATETIME, DATE, TIME.

DetailsBy default, SAS/ACCESS converts each data source data type to a SAS data typeduring input processing. When you need a different data type, you can use this optionto override the default and assign a SAS data type to each specified data source column.Some conversions might not be supported. If a conversion is not supported, SAS printsan error to the log.

DBTYPE= Data Set Option

Specifies a data type to use instead of the default data source data type when SAS creates a datasource table.

Valid in: DATA and PROC steps

Default value: none

Page 178: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

170 ERRLIMIT= Data Set Option � Chapter 12

SyntaxDBTYPE=(column-name-1=<’>data-source-type<’>

<...column-name-n=<’>data-source-type<’>>)

Syntax Description

column-namespecifies a data source column name.

data-source-typespecifies a data source data type. See the documentation for your SAS/ACCESSinterface for the default data types for your data source.

DetailsBy default, SAS/ACCESS converts each SAS data type to a predetermined data sourcedata type when outputting data to your data source. When you need a different datatype, use DBTYPE= to override the default data type chosen by the SAS/ACCESSengine.

Example

In this example, DBTYPE= specifies the data types that are used when you createcolumns in the table.

data mydblib.newdept(dbtype=(deptno=’double’ city=’char(25)’));set mydblib.dept;

run;

ERRLIMIT= Data Set Option

Specifies the number of errors that are allowed before SAS stops processing and issues a rollback.

Valid in: DATA and PROC stepsDefault value: 1

SyntaxERRLIMIT=integer

Syntax Description

integeris a positive integer that represents the number of errors after which SAS stopsprocessing and issues a rollback.

Page 179: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � INSERT_SQL= Data Set Option 171

DetailsSAS calls the data source to issue a rollback after a specified number of errors occursduring the processing of inserts, deletes, updates, and appends. If ERRLIMIT= is set to0, SAS processes all rows, regardless of the number of errors that occur. The SAS logdisplays the total number of rows processed and the number of failed rows, if applicable.

The DBCOMMIT= option overrides the ERRLIMIT= option. If you specify a value forDBCOMMIT= other than zero, then rollbacks affected by the ERRLIMIT= option mightnot include records that are processed unsuccessfully because they were alreadycommitted by DBCOMMIT=.

Note: This option cannot be used from a SAS client session in a SAS/SHAREenvironment. �

Example

In this example, SAS stops processing and issues a rollback to the data source at theoccurrence of the tenth error. The MyDBLib libref was assigned in a prior LIBNAMEstatement.

data mydblib.employee3 (errlimit=10);set mydblib.employees;where salary > 40000;

run;

INSERT_SQL= Data Set OptionDetermines the method to use to insert rows into a data source.

Valid in: DATA and PROC stepsDefault value: LIBNAME option setting

SyntaxINSERT_SQL=YES | NO

Syntax Description

YESspecifies that the SAS/ACCESS engine uses the data source’s SQL insert method toinsert new rows into a table.

NOspecifies that the SAS/ACCESS engine uses an alternate (data source-specific)method to add new rows to a table.

See AlsoTo assign this option to a group of tables, use the INSERT_SQL= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

Page 180: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

172 INSERTBUFF= Data Set Option � Chapter 12

INSERTBUFF= Data Set Option

Specifies the number of rows in a single insert.

Valid in: DATA and PROC stepsDefault value: LIBNAME option setting

SyntaxINSERTBUFF=number-of-rows

Syntax Description

number-of-rowsspecifies the number of rows to insert. The value must be a positive integer.

DetailsSAS allows the maximum number of rows that is allowed by the data source. Theoptimal value for this option varies with factors such as network type and availablememory. You might need to experiment with different values to determine the bestvalue for your site.

When you assign a value that is greater than INSERTBUFF=1, the SAS applicationnotes that indicate the success or failure of the insert operation might be incorrectbecause these notes represent only information for a single insert, even when multipleinserts are performed.

Note: PC Files Server does not support INSERTBUFF= option with a value higherthan 1 for writing data to Excel. It ignores this option when writing data to Excel. �

If the DBCOMMIT= option is specified with a value that is less than the value ofINSERTBUFF=, then DBCOMMIT= overrides INSERTBUFF=.

Note: When you are inserting with the VIEWTABLE window or the FSEDIT orFSVIEW procedure, use INSERTBUFF=1 to prevent the data source interface fromtrying to insert multiple rows. These features do not support inserting more than onerow at a time. �

See AlsoTo assign this option to a group of tables, use the INSERTBUFF= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

NULLCHAR= Data Set Option

Indicates how SAS character missing values are handled during insert, update, and DBKEY=processing.

Valid in: DATA and PROC steps

Page 181: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � NULLCHARVAL= Data Set Option 173

Default value: SAS

SyntaxNULLCHAR= YES | NO

Syntax Description

YESindicates that character missing values in SAS data sets are treated as NULL valuesif the data source allows them. Otherwise, an error is returned.

NOindicates that character missing values in SAS data sets are treated as theNULLCHARVAL= value, regardless of whether the data source allows NULLs for thecolumn.

DetailsThis option affects insert and update processing and also applies when you use theDBKEY= option.

This option works in conjunction with the NULLCHARVAL= data set option.NULLCHARVAL= determines what is inserted when NULL values are not allowed.

All SAS numeric missing values (represented in SAS as ’.’) are treated by the datasource as NULLs.

NULLCHARVAL= Data Set Option

Defines the character string that replaces SAS character missing values during insert, update, andDBKEY= processing.

Valid in: DATA and PROC stepsDefault value: a blank character

SyntaxNULLCHARVAL=’character-string’

DetailsThis option affects insert and update processing and also applies when you use theDBKEY= option.

This option works with the NULLCHAR= option. NULCHAR= determines whetheror not a SAS character NULL value is treated as a NULL value.

If NULLCHARVAL= is longer than the maximum column width, one of these actionsoccurs:

� The string is truncated if DBFORCE=YES.

Page 182: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

174 READBUFF= Data Set Option � Chapter 12

� The operation fails if DBFORCE=NO.

READBUFF= Data Set Option

Specifies the number of rows of data to read into the buffer.

Valid in: DATA and PROC steps

Default value: LIBNAME option setting

SyntaxREADBUFF=number-of-rows

Syntax Description

number-of-rowsis the maximum value that is allowed by the data source.

DetailsThis option improves performance by specifying a number of rows that can be held inmemory for input into SAS. Buffering data reads can decrease network activities andincrease performance. However, because SAS stores the rows in memory, higher valuesfor READBUFF= use more memory. In addition, if too many rows are selected at once,then the rows that are returned to the SAS application might be out of date.

When READBUFF=1, only one row is retrieved at a time. The higher the value forREADBUFF=, the more rows the SAS/ACCESS engine retrieves in one fetch operation.

ROWSET_SIZE is an alias for this option.

See AlsoTo assign this option to a group of tables, use the READBUFF= option specified in

“LIBNAME Options for PC Files on Microsoft Windows” on page 86.

SASDATEFMT= Data Set Option

Changes the SAS date format of a data source column.

Valid in: DATA and PROC steps

Default value: none

SyntaxSASDATEFMT=(data-source-date-column-1=’SAS-date-format’

<... data-source-date-column-n=’SAS-date-format’>)

Page 183: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

LIBNAME Statement Syntax for PC Files: Linus and UNIX � SASDATEFMT= Data Set Option 175

Syntax Description

data-source-date-columnspecifies the name of a date column in a data source table.

SAS-date-formatspecifies a SAS date format that has an equivalent (like-named) informat. Forexample, DATETIME21.2 is both a SAS format and a SAS informat, so it is a validvalue for the SAS-date-format argument.

DetailsIf the date format of a SAS column does not match the date format of the correspondingdata source column, you must convert the SAS date values to the appropriate datasource date values. The SASDATEFMT= option enables you to convert date values fromthe default SAS date format to another SAS date format that you specify.

Use SASDATEFMT= to prevent date type mismatches under these circumstances:

� during input operations to convert data source date values to the correct SASDATE, TIME, or DATETIME values

� during output operations to convert SAS DATE, TIME, or DATETIME values tothe correct data source date values

If the SAS date format and the data source date format match, this option is notneeded.

The default SAS date format is data source-specific and is determined by the datatype of the data source column. See the documentation for your SAS/ACCESS interface.

Note: For non-English date types, SAS automatically converts the data to the SAStype of NUMBER. The SASDATEFMT= option does not currently handle these datetypes, but you can use a PROC SQL view to convert the data source data to a SAS dateformat as you retrieve the data, or use a format statement in other contexts. �

Page 184: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

176

Page 185: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

177

C H A P T E R

13Pass-Through Facility: PC Fileson Linux, UNIX, and 64-BitMicrosoft Windows

Overview: Pass-Through Facility for PC Files on Linux, UNIX, and 64-Bit Microsoft Windows 177Syntax for the Pass-Through Facility for PC Files 177

Return Codes 178

Special PC Files Queries 187

Overview: Pass-Through Facility for PC Files on Linux, UNIX, and64-Bit Microsoft Windows

The SQL procedure implements the Structured Query Language (SQL) for SAS. Seethe SQL procedure topic in Base SAS Procedures Guide for information about PROCSQL. You can send data source-specific SQL statements directly to a data source usingan extension to the SQL procedure called the Pass-Through Facility.

This facility uses SAS/ACCESS to connect to a data source and to send statementsdirectly to the data source for execution. This facility is a complement to theSAS/ACCESS LIBNAME statement. It enables you to use the SQL syntax of your datasource, which can include any non-ANSI standard SQL that is supported by your datasource.

Using the Pass-Through Facility, here is what you can do:

� establish and terminate connections with a data source using its CONNECT andDISCONNECT statements

� send dynamic, non-query, data source-specific SQL statements to a data sourceusing its EXECUTE statement

� retrieve data directly from a data source using its CONNECTION TO componentin the FROM clause of a PROC SQL SELECT statement

You can use Pass-Through Facility statements in a PROC SQL query or you canstore them in a PROC SQL view. When you create a PROC SQL view, any argumentsthat you specify in the CONNECT statement are stored with the view. Therefore, whenthe view is used in a SAS program, SAS can establish the appropriate connection to thedata source.

Syntax for the Pass-Through Facility for PC Files

This section contains syntax for the Pass-Through Facility statements and theCONNECTION TO component. You can use the component with the PROC SQLSELECT statement to query data from a data source.

Page 186: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

178 Return Codes � Chapter 13

PROC SQL <options-list>;

CONNECT TO data-source-name <AS alias> <(<connect-statement-arguments><database-connection-arguments>)>;

DISCONNECT FROM data-source-name | alias;

EXECUTE (data-source-specific-SQL-statement) BY data-source-name | alias;

SELECT column-list FROM CONNECTION TO data-source-name | alias(data-source-query)

Return CodesAs you use the PROC SQL statements that are available in the Pass-Through

Facility, any error conditions are written to the SAS log. The Pass-Through Facilitygenerates return codes and messages that are available to you through the followingtwo SAS macro variables:

SQLXRCcontains the data source return code that identifies the data source error.

SQLXMSGcontains descriptive information about the data source error that is generated bythe data source.

The contents of the SQLXRC and SQLXMSG macro variables are printed in the SASlog using the %PUT macro. They are reset after each Pass-Through Facility statementhas been executed.

CONNECT Statement

Establishes a connection with the data source.

Valid in: PROC SQL steps

SyntaxCONNECT TO data-source-name <AS alias> <(<connect-statement-arguments>

<database-connection-arguments>)>;

Argumentsdata-source-name

identifies the data source to which you want to connect. Since this methodrequires connecting through the PC Files Server, you must use PCFILES as yourdata source. You can also specify an optional alias in the CONNECT statement.

aliasspecifies an optional alias for the connection that has 1 to 32 characters. If youspecify an alias, the keyword AS must appear before the alias. If an alias is notspecified, the data source name is used as the name of the Pass-Throughconnection.

Page 187: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Pass-Through Facility: PC Files on Linux, UNIX, and 64-Bit Microsoft Windows � CONNECT Statement 179

connect-statement-argumentsspecifies arguments that indicate whether you can make multiple connections,shared or unique connections, and so on, to the database. Some of thesearguments are optional.

database-connection-argumentsspecifies the data source-specific arguments that are needed by PROC SQL toconnect to the data source. These arguments are not required and the defaultbehavior opens a dialog box that prompts you for information they provide.

Database Connection ArgumentsThe arguments that are listed below are available with the Pass-Through Facility forPC files. These arguments provide information to the Pass-Through Facility to connectto the PC files or to the database.

The following options are used when connecting to the PC Files Server.

DSN=“data-source-name”specifies the ODBC data source name that is used to access the PC data throughan ODBC driver on the PC.

Note: This ODBC data source must be defined on the PC where the PC FilesServer is currently running. �

CONNECT_STRING= “connection-string”specifies connection options for your data source or database. Separate multipleoptions with a semicolon. This is an advanced connection method that you shoulduse only when you know the exact syntax of all connection options that the ODBCdriver requires for a successful connection.

PATH=“path-for-file”specifies the data source file location for the Microsoft Access database file orMicrosoft Excel workbook file.

PORT=“port-number”The port or service name on the PC that the SAS PC Files Server is listening on.This port or service name is displayed on the SAS PC Files Server window when itis started on the PC. This is a required field when connecting to the PC FilesServer for data.Aliases: SERVICE=, SERVICE_NAME=

SERVER=“pc-server-hostname ”specifies the computer name of the PC on which you started the PC Files Server.This name is required by UNIX users to connect to this server machine and isreflected on the server control panel. This is a required field when connecting tothe PC Files Server for data.

You can specify this hostname as a simple computer name (for example,wxp320), a fully qualified network name (for example, wxp320.domain.com), or anIP address.

Use these options only for Microsoft Access.

DBPASSWORD=“database-file-password”enables you to access your file if you have database-level security set in your MDBfile. A database password is case sensitive, and you can define it instead ofuser-level security

DBSYSFILE=“workgroup-information-file”contains information about the users in a workgroup based on information thatyou define for your Microsoft Access database. Any user and group accounts orpasswords you create are saved in the new workgroup information file.

Page 188: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

180 CONNECT Statement � Chapter 13

PASSWORD=“user-password”specifies a password for the user account, if required by the data source.Passwords are case sensitive.

MSENGINE= ACE | JETdetermines the database engine used for accessing the Microsoft Excel file orMicrosoft Access database. The Microsoft Jet engine is older and supports formatsup to 2003. The Microsoft Ace engine supports 2007 and older formats.Restriction: It is recommended that you do not use this file option unless you

are trying to create a 95 format file.Default: ACE

USER=“user-ID”specifies a default user account name. The default value is Admin. User namescan be 1 to 20 characters long and can include alphabetic characters, accentedcharacters, numbers, and spaces. If you have user-level security set in your MDBfile, you need to use this option and the PASSWORD= option to access your file.

Use this option only for Microsoft Excel workbooks.

VERSION=2007 | 2003 | 2002 | 2000 | 97 | 95 | 5sets the version of Microsoft Excel workbook. The default value is 97.

Alias: VER

Note: You do not need to specify this option for an existing Microsoft Excel file.However, if you want to create a new Microsoft Excel workbook file, you can usethis option to specify the version that you want to create. Note that versions 97,2000, and 2003 share the same file format. Versions 95 and 5 share a separate fileformat. �

Note: This option is ignored when connecting to a Microsoft Access database. �

CONNECT Statement ArgumentsThe arguments that are listed below are available with the Pass-Through FacilityCONNECT statement for PC Files. These arguments extend some of the LIBNAMEstatement connection management features to the Pass-Through Facility.

AUTOCOMMIT=YES | NOdetermines whether the ACCESS engine commits (saves) updates as soon as theuser submits them.

YESspecifies that updates are committed (saved) to the table as soon as they aresubmitted. No rollback is possible.

NOspecifies that the SAS/ACCESS engine automatically performs the commitwhen it reaches the end of the file.

Default: YES

Note: The default value for this option is different from the LIBNAMEoption. �

COMMAND_TIMEOUT=number-of-secondsspecifies the number of seconds that pass before a data source command times out.Default: 0 (no time-out)Alias: TIMEOUT=

Page 189: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Pass-Through Facility: PC Files on Linux, UNIX, and 64-Bit Microsoft Windows � CONNECT Statement 181

CONNECTION= SHARED |GLOBALspecifies whether multiple CONNECT statements for a data source can use thesame connection. The CONNECTION= option enables you to control the numberof connections, and therefore transactions, that your SAS/ACCESS engine executesand supports for each CONNECT statement.

SHAREDspecifies that the CONNECT statement makes one connection to the DBMS.Only Pass-Through statements that use this alias share the connection.

GLOBALspecifies that multiple CONNECT statements can share the same connectionto the DBMS if they use identical values for CONNECTION=,CONNECTION_GROUP=, and any database connection arguments.

Default: SHARED

CONNECTION_GROUP= connection-groupcauses operations against multiple librefs to share a connection to the data source.Also causes operations against multiple Pass-Through Facility CONNECTstatements to share a connection to the data source.

CURSOR_TYPE= DYNAMIC | FORWARD_ONLY | KEYSET_DRIVEN | STATICspecifies the cursor type for read-only cursors and for cursors to be updated.

DYNAMICspecifies that the cursor reflects all changes that are made to the rows in aresult set as you move the cursor. The data values and the membership ofrows in the cursor can change dynamically on each fetch. This is the defaultfor the DB2 UNIX, PC files, and Microsoft SQL Server interfaces.

FORWARD_ONLYspecifies that the cursor behaves like a DYNAMIC cursor, except that itsupports only fetching the rows sequentially.

KEYSET_DRIVENspecifies that the cursor determines which rows belong to the result set whenthe cursor is opened. However, changes that are made to these rows arereflected as you scroll around the cursor.

STATICspecifies that the complete result set is built when the cursor is opened. Nochanges that are made to the rows in the result set after the cursor is openedare reflected in the cursor. Static cursors are read-only.

Default: noneAlias: CURSOR=

DBGEN_NAME=DBMS | SASspecifies that the data source columns are renamed, and specifies the format thatthe new names follow.

DBMSspecifies that the data source columns are renamed to valid SAS variablenames. Disallowed characters are converted to underscores. If a column isconverted to a name that already exists, then a sequence number is appendedto the end of the new name.

SASspecifies that data source columns are renamed to the format _COLn, wheren is the column number (starting with zero).

Default: DBMS

Page 190: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

182 CONNECT Statement � Chapter 13

DBMAX_TEXT=nspecifies an integer between 1 and 32,767 that indicates the maximum length for acharacter string. Longer character strings are truncated. This option applies onlywhen you are reading, appending, and updating Microsoft Access or Excelcharacter data from SAS.

Note: Although you can specify a value less than 256, it is not recommended. �Default: 1,024

DEFER=NO | YESenables you to specify when the CONNECT statement occurs.

NOspecifies that the connection to the data source occurs when the libref isassigned by a LIBNAME statement.

YESspecifies that the connection to the data source occurs when a table in thedata source is opened.

Default: NO

READBUFF=number-of-rowsspecifies the number of rows to use when you are reading data from a data source.Setting a higher value for this option reduces I/O and increases performance, butalso increases memory usage. Additionally, if too many rows are read at once,values returned to SAS might be out of date.Default: 1Alias: ROWSET=

ROWSET_SIZE=

STRINGDATES=YES | NOspecifies whether datetime values are read from the data source as characterstrings or as numeric date values. STRINGDATES= is not available as a data setoption.

YESspecifies that SAS/ACCESS reads datetime values as character strings.

NOspecifies that SAS/ACCESS reads datetimes values as numeric date values.

Default: NOAlias: STRDATES

DetailsThe CONNECT statement establishes a connection with the data source. You establisha connection to send data source-specific SQL statements to the data source or toretrieve data source data. The connection remains in effect until you issue aDISCONNECT statement or terminate the SQL procedure.

To connect to a data source using the Pass-Through Facility, complete the followingsteps:

1 Initiate a PROC SQL step.2 Use the Pass-Through Facility CONNECT statement with the PC files engine

name and then assign an alias if you want.3 Specify any arguments needed to connect to the database.4 Specify any attributes for the connection.

Page 191: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Pass-Through Facility: PC Files on Linux, UNIX, and 64-Bit Microsoft Windows � DISCONNECT Statement 183

The CONNECT statement is optional for some data sources. However, if you do notspecify it, default values for all database connection arguments are used.

Any return code or message that is generated by the data source is available in themacro variables SQLXRC and SQLXMSG after the statement executes. See “ReturnCodes” on page 112 for more information about these macro variables.

Example

The following example uses the CONNECT statement with the PATH= option toconnect to the Microsoft Access database file, c:\demo.mdb:

proc sql;connect to pcfiles as db (server=d2323 path="c:\demo.mdb");

DISCONNECT Statement

Terminates the connection to the data source.

Valid in: PROC SQL steps (when accessing PC files data using SAS/ACCESS software)

Syntax

DISCONNECT FROM PCFILES | alias

Arguments

aliasspecifies an alias for the connection that was defined in the CONNECT statement.

Details

The DISCONNECT statement ends the connection with the data source. If theDISCONNECT statement is omitted, an implicit DISCONNECT is performed whenPROC SQL terminates. The SQL procedure continues to execute until you submit aQUIT statement, another SAS procedure, or a DATA step.

Any return code or message that is generated by the data source is available in themacro variables SQLXRC and SQLXMSG after the statement executes. See “ReturnCodes” on page 112 for more information about these macro variables.

Example

After connection and SQL processing, this example uses the DISCONNECTstatement to disconnect the connection from the database and the QUIT statement toquit the SQL procedure:

disconnect from pcfiles;quit;

Page 192: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

184 EXECUTE Statement � Chapter 13

EXECUTE Statement

Sends data source-specific, nonquery SQL statements to the data source.

Valid in: PROC SQL steps

SyntaxEXECUTE (data-source-specific-SQL-statement) BY PCFILES | alias;

Arguments(data-source-specific-SQL-statement)

a dynamic nonquery, data source-specific SQL statement. This argument isrequired and must be enclosed in parentheses. However, the SQL statementcannot contain a semicolon because a semicolon represents the end of a statementin SAS. Depending on your data source, the SQL statement can be case-sensitive.It is passed to the data source exactly as you type it.

Any return code or message that is generated by the data source is available inthe macro variables SQLXRC and SQLXMSG after the statement executes. See“Return Codes” on page 112 for more information about these macro variables.

aliasspecifies an alias for the connection that was defined in the CONNECT statement.(You cannot use an alias if the CONNECT statement is omitted.)

DetailsThe EXECUTE statement sends dynamic nonquery, data source-specific SQLstatements to the data source and processes those statements.

The EXECUTE statement cannot be stored as part of a Pass-Through Facility queryin a PROC SQL view.

Useful Statements to Include in EXECUTE StatementsYou can pass the following statements to the data source by using the Pass-ThroughFacility’s EXECUTE statement.

CREATEcreates a data source table, view, index, or other data source object, depending onhow the statement is specified.

DELETEdeletes rows from a data source table.

DROPdeletes a data source table, view, or other data source object, depending on howthe statement is specified.

GRANTgives users the authority to access or modify objects such as tables or views.

INSERTadds rows to a data source table.

Page 193: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Pass-Through Facility: PC Files on Linux, UNIX, and 64-Bit Microsoft Windows � CONNECTION TO Component 185

REVOKErevokes the access or modification privileges that were given to users by theGRANT statement.

UPDATEmodifies the data in the specified columns of a row in a data source table.

For more information about these and other SQL statements, see the SQLdocumentation for your data source.

ExampleThe following example, after the connection, uses the EXECUTE statement to drop atable, create a table, and insert a row of data:

execute(drop table ‘ My Invoice ‘ ) by pcfiles;execute(create table ‘ My Invoice ‘ (‘ Invoice Number ‘ LONG not null,‘ Billed To ‘ VARCHAR(20),‘ Amount ‘ CURRENCY,‘ BILLED ON ‘ DATETIME)) by pcfiles;execute(insert into ‘ My Invoice ‘

values( 12345, ’John Doe’, 123.45, #11/22/2003#)) by pcfiles;

CONNECTION TO Component

Retrieves and uses data source data in a PROC SQL query or view.

Valid in: PROC SQL step SELECT statements

SyntaxCONNECTION TO PCFILES <AS alias> <(database-connection-options)>

Argumentsalias

specifies an alias if one was defined in the CONNECT statement.

database-connection-argumentsspecifies the data source-specific arguments that are needed by PROC SQL toconnect to the data source. These arguments are not required and the defaultbehavior opens a dialog box.

DetailsThe CONNECTION TO component specifies the data source connection that you wantto use or that you want to create (if you have omitted the CONNECT statement).CONNECTION TO then enables you to retrieve data source data directly through aPROC SQL query.

Page 194: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

186 CONNECTION TO Component � Chapter 13

You use the CONNECTION TO component in the FROM clause of a PROC SQLSELECT statement:

SELECT column-list

FROM CONNECTION TO data source-name (data source-query);

CONNECTION TO can be used in any FROM clause, including those in nestedqueries (that is, in subqueries).

You can store a Pass-Through Facility query in a PROC SQL view and then use thatview in SAS programs. When you create a PROC SQL view, any options that youspecify in the corresponding CONNECT statement are also stored. So when the PROCSQL view is used in a SAS program, SAS can establish the appropriate connection tothe data source.

Because external data sources and SAS have different naming conventions, somedata source column names might be changed when you retrieve data source datathrough the CONNECTION TO component.

Examples1 Query Tables or Subtables

After the connection, this example uses the CONNECTION TO component toquery a table or a subtable:

select * from connection to pcfiles(select * from ‘my invoice‘);select * from connection to pcfiles(select ‘Invoice Number‘, Amount from ‘my invoice‘);

2 Create a SAS Data Set from a Microsoft Access Table

This example creates a SAS data set called Newtable from a Microsoft Accesstable:

proc sql;connect to pcfiles(server=d2323 port=8621

path="c:\temp\household.inventory.mdb");create table newtable as select * from;connect to pcfiles(select * from rooms);disconnect from pcfiles;quit;

3 Query a Table Range in an Excel Workbook

This example connects to an Excel file and queries the INVOICE table (range)within the Excel workbook:

proc sql dquote=ansi;connect to pcfiles (path="c:\sasdemo\sasdemo.xls" server=d2323 port=8621);select * from connection to pcfiles

(select * from invoice);disconnect from pcfiles;quit;

4 Use PC Files Server to Create a SAS Data Set

This example uses a PC Files Server through ODBC to create a SAS data setcalled Work from a list of tables in a Microsoft SQL Server database:

proc sql dquote=ansi;connect to pcfiles (server=d2323 port=8621 dsn=mqis user=scott pwd=tiger);

Page 195: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Pass-Through Facility: PC Files on Linux, UNIX, and 64-Bit Microsoft Windows � Special PC Files Queries 187

create table work as select * from connection to pcfiles (PCFILES::SQLTABLES);disconnect from pcfiles;quit;

Special PC Files QueriesSAS/ACCESS Interface to PC Files on UNIX supports the following special queries.

Many databases provide or use system tables that allow queries to return the list ofavailable tables, columns, procedures, and other useful information. In PC files, muchof this functionality is provided through special APIs (application programminginterfaces) in order to accommodate databases that do not follow the SQL tablestructure. You can use these special queries on non-SQL and SQL databases. Here isthe general format of the special queries:

PCFILES::SQLAPI “parameter 1”,”parameter n”

PCFILES::is required to distinguish special queries from regular queries.

SQLAPIis the specific API that is being called. Both PCFILES:: and SQLAPI are casesensitive.

"parameter n"is a quoted string that is delimited by commas.

Within the quoted string, two characters are universally recognized: the percent sign(%) and the underscore (_). The percent sign matches any sequence of zero or morecharacters; the underscore represents any single character. Each driver also has anescape character that can be used to place characters within the string. Consult thedriver’s documentation to determine the valid escape character.

The values for the special query arguments are DBMS specific. For example, yousupply the fully qualified table name for a “Catalog” argument. In dBASE, the value of“Catalog” might be c:\dbase\tst.dbf and in SQL Server, the value might betest.customer. In addition, depending on the DBMS that you are using, valid valuesfor “Schema” argument might be a user ID, a database name, or a library. Allarguments are optional. If you specify some but not all arguments within a parameter,use a comma to indicate the omitted parameters. If you do not specify any parameters,commas are not necessary.

Note: These special queries might not be available for all PCFILES drivers. �

The following special queries are supported:

PCFILES::SQLTables <"Catalog", "Schema", "Table-name", "Type">returns a list of all tables that match the specified arguments. If no arguments arespecified, all accessible table names and information are returned.

PCFILES::SQLColumns <"Catalog", "Schema", "Table-name", "Column-name">returns a list of all columns that match the specified arguments. If no argumentsare specified, all accessible column names and information are returned.

PCFILES::SQLColumnPrivileges <"Catalog", "Schema", "Table-name","Column-name">

returns a list of all column privileges that match the specified arguments. If noarguments are specified, all accessible column names and privilege information arereturned.

Page 196: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

188 Special PC Files Queries � Chapter 13

PCFILES::SQLForeignKeys <"PK-catalog", "PK-schema", "PK-table-name","FK-catalog", "FKschema", "FKtable-name">

returns a list of all columns that comprise foreign keys that match the specifiedarguments. If no arguments are specified, all accessible foreign key columns andinformation are returned.

PCFILES::SQLPrimaryKeys <"Catalog", "Schema", "Table-name">returns a list of all columns that compose the primary key that matches thespecified table. A primary key can be composed of one or more columns. If no tablename is specified, this special query fails.

PCFILES::SQLProcedureColumns <"Catalog", "Schema", "Procedure-name","Column-name">

returns a list of all procedure columns that match the specified arguments. If noarguments are specified, all accessible procedure columns are returned.

PCFILES::SQLProcedures <"Catalog", "Schema", "Procedure-name">returns a list of all procedures that match the specified arguments. If noarguments are specified, all accessible procedures are returned.

PCFILES::SQLSpecialColumns <"Identifier-type", "Catalog-name", "Schema-name","Table-name", "Scope", "Nullable">

returns a list of the optimal set of columns that uniquely identify a row in thespecified table.

PCFILES::SQLStatistics <"Catalog", "Schema", "Table-name">returns a list of the statistics for the specified table name, with options ofSQL_INDEX_ALL and SQL_ENSURE set in the SQLStatistics API call. If thetable name argument is not specified, this special query fails.

PCFILES::SQLTablePrivileges <"Catalog", "Schema", "Table-name">returns a list of all tables and associated privileges that match the specifiedarguments. If no arguments are specified, all accessible table names andassociated privileges are returned.

PCFILES::SQLGetTypeInforeturns information about the data types that are supported in the data source.

Page 197: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

189

P A R T5

ACCESS and DBLOAD Procedures

Chapter 14. . . . . . . . .The ACCESS Procedure for PC Files 191

Chapter 15. . . . . . . . .The DBLOAD Procedure for PC Files 215

Chapter 16. . . . . . . . .File-Specific Reference for the ACCESS and DBLOADProcedures 225

Page 198: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

190

Page 199: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

191

C H A P T E R

14The ACCESS Procedure for PCFiles

Overview: ACCESS Procedure for PC Files 191Using ACCESS Procedure Statements 192

SAS/ACCESS Descriptors for PC Files 193

Overview 193

Access Descriptors 193

View Descriptors 193SAS Passwords for Descriptors 193

Performance and Efficient View Descriptors for PC Files 194

General Guidelines 194

Extracting Data Using a View 194

ACCESS Procedure Syntax 194

PROC ACCESS Statement 195ASSIGN Statement 196

CREATE Statement 197

DROP Statement 200

FORMAT Statement 201

LIST Statement 202MIXED Statement 203

PATH= Statement 204

QUIT Statement 204

RENAME Statement 205

RESET Statement 206SELECT Statement 208

SUBSET Statement 209

TYPE Statement 209

UNIQUE Statement 210

UPDATE Statement 211

Overview: ACCESS Procedure for PC FilesThe ACCESS procedure for PC files is available only under Windows operating

environments. You can use the ACCESS procedure with DBF, DIF, WK1, WK3, WK4,Excel 4, Excel 5, and Excel 95 file formats.You can use the ACCESS procedure to create access descriptors, view descriptors, andSAS data files. Descriptor files describe PC files data so that you can directly read,update, or extract PC files data while working within a SAS program. See “SAS/ACCESS Descriptors for PC Files” on page 193 for more information.

Page 200: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

192 Using ACCESS Procedure Statements � Chapter 14

CAUTION:Altering a PC file might invalidate defined descriptors. Altering the format of a PC filethat has descriptor files defined on it might cause these descriptors to be out-of-dateor invalid. For example, if you add a column to a file and an existing accessdescriptor is defined on that file, the access descriptor and any view descriptors basedon it do not show the new column. You must recreate the descriptors to be able toshow and select the new column. �

The descriptor files are compatible with SAS 6. The view descriptor saves a columnname with up to eight characters in uppercase. Any column name longer than eightcharacters is truncated. When duplicate names occur after truncation, a unique nameis generated with a number appended to it. However, the view descriptor also saves fullcolumn names as is in the label fields. Full column names can be read from variablelabels.

Using ACCESS Procedure StatementsThe following table presents a task-oriented overview of the statements you use

inside a PROC ACCESS program block to create or modify access and view descriptors.See “ACCESS Procedure Syntax” on page 194 for the complete syntax for this procedure.

Table 14.1 Options and Statements Required for the ACCESS Procedure

Task Options and Statements That You Use

create an access descriptor PROC ACCESS DBMS=DBF|DIF|WKn|XLS;CREATE libref.member-name.ACCESS;

required-database-description-statements;optional-editing-statements;

RUN;

create an access descriptor anda view descriptor

PROC ACCESS DBMS=DBF|DIF|WKn| XLS;CREATE libref.member-name.ACCESS;

required-database-description-statements;optional-editing-statements;

CREATE libref.member-name.VIEW;SELECT column-list;

optional-editing-statements;

RUN;

create a view descriptor from anexisting access descriptor

PROC ACCESS DBMS=DBF|DIF|WKn|XLSACCDESC=libref.access-descriptor;

CREATE libref.member-name.VIEW;SELECT column-list;

optional-editing-statements;

RUN;

As the table indicates, you can create one or more access descriptors and viewdescriptors in one execution of PROC ACCESS, or you can create the descriptors in

Page 201: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � SAS Passwords for Descriptors 193

separate executions. See “CREATE Statement” on page 197 for additional informationabout statement order.

SAS/ACCESS Descriptors for PC Files

OverviewSAS/ACCESS descriptor files are the tools that the ACCESS procedure uses to

establish a connection to a PC file. To create descriptor files, use the ACCESSprocedure. There are two types of descriptor files: access descriptors and viewdescriptors. The next sections provide an overview of these files.

Access DescriptorsAn access descriptor holds essential information about the structure of the PC file

that you want to access. For example, you can access the file’s format and name, itsdatabase field or column names, and its data types. Access descriptors can also containthe corresponding SAS information such as the SAS variable names and formats.Typically, you have only one access descriptor for each PC file.

An access descriptor describes only a PC file format and contents to SAS; that is, it isa master description file of the PC file for SAS. You cannot use an access descriptor in aSAS program. Instead, you use an access descriptor to create other SAS files, calledview descriptors, that you use in SAS programs.

View DescriptorsA view descriptor defines some or all of the data that is described by one access

descriptor (and, therefore, one PC file). For example, you might want to use only threeof nine possible database columns and only some of the rows in a PC file. The viewdescriptor enables you to do this by selecting the database fields or columns that youwant to use and specifying criteria to retrieve only the rows you want. Typically, youcreate several view descriptors based on one access descriptor, where each viewdescriptor selects a different subset of the PC files data.

A view descriptor is a SAS data set or, more specifically, a SAS data view. You use aview descriptor in a SAS program much as you would any SAS data set. For example,you can specify a view descriptor in the DATA= statement of a SAS procedure or theSET statement of a DATA step. You can use a view descriptor in a SELECT statementof the SQL procedure to join view descriptor data with SAS data, for example.

You can use a view descriptor to update data directly in some of the PC file formats,such as the DBF file format.

In some cases, you might also want to create a SAS data file from data stored in aPC file. Using a view descriptor to copy PC files data into a SAS data file is calledextracting the data.

SAS Passwords for DescriptorsSAS enables you to control access to SAS data sets and access descriptors by

associating one or more SAS passwords with them.

Page 202: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

194 Performance and Efficient View Descriptors for PC Files � Chapter 14

Table 14.2 Password and Descriptor Interaction

READ= WRITE= ALTER=

access descriptor no effect on descriptor no effect on descriptor protects descriptor frombeing read or updated

view descriptor protects PC file data frombeing read or updated

protects PC file data frombeing updated

protects descriptor frombeing read or updated

In this example, the PROC DATASETS statement assigns the passwords MYPW andMYDEPT 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;

For detailed information on the levels of protection and the types of passwords youcan use, refer to your Base SAS software documentation.

Performance and Efficient View Descriptors for PC Files

General GuidelinesWhen you create and use view descriptors, follow these guidelines to minimize the

use of SAS resources and to reduce the time it takes to access data:� Select only the columns your SAS program needs. Selecting unnecessary columns

adds extra processing time.� Where possible, specify selection criteria to subset the number of observations

processed by SAS.� To present PC files data in sorted order, reference a view descriptor in a PROC SQL

query. Otherwise, you might need to extract the data to sort it, as described below.

Extracting Data Using a ViewIn some cases, it might be more efficient to use a view descriptor to extract PC files

data and place it in a SAS data file instead of using the view descriptor to read the datadirectly.

A PC file is read every time a view descriptor is referred to in a SAS program andthe program is executed. It is better to extract data under these circumstances:

� Extract PC files data if the file is large and you use the data repeatedly in SASprograms.

� Extract PC files data if you use sorted data several times in a SAS program.� Extract PC files data for added security, you can assign a password to the

extracted SAS data file.

ACCESS Procedure SyntaxThe general syntax for the ACCESS procedure is presented here. For specific details,

see Chapter 6, “File Format-Specific Reference for IMPORT and EXPORT Procedures,”on page 25.

Page 203: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � PROC ACCESS Statement 195

PROC ACCESS options;

Create and Update StatementsCREATE libref.member-name.ACCESS|VIEW ;

UPDATE libref.member-name.ACCESS|VIEW ;

Database Description StatementPATH= ’path-and-filename<.PC-filename-extension>’ | <’>filename<’> | fileref;(See your file format-specific chapter for additional database-description statements.)

Editing StatementsASSIGN <=>YES|NO|Y|N;DROP <’>column-identifier-1<’>

<<’>…column-identifier-n <’>>;FORMAT <’>column-identifier-1<’><=>SAS-format-name-1<’>

<…<’>column-identifier-n<’><=>SAS-format-name-n>;LIST <ALL|VIEW|<’>column-identifier <’>>;MIXED <=> YES | NO | Y | N;(The MIXED statement is not available for DIF and DBF files.)QUIT;RENAME <’>column-identifier-1<’><=>SAS-variable-name-1

<…<’>column-identifier-n<’><=>SAS-variable-name-n>;RESET ALL | <’>column-identifier-1 <’><…<’>column-identifier-n<’>>;SELECT ALL|<’>column-identifier-1<’>

<…<’>column-identifier-n <’>>;SUBSET selection-criteria;TYPE <’>column-identifier-1<’><=> C | N

<…column-identifier-n <=> C | N>;(The TYPE statement is not available for DBF files.)UNIQUE <=>YES|NO|Y|N ;

RUN;

PROC ACCESS StatementRequirement: This statement is required.Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 files underWindows operating environments

PROC ACCESS options;

OptionsThe PROC ACCESS statement options that are available with all supported PC file

formats are described below. Other options, specific to particular PC file formats, aredescribed in the file format specific chapter.

Page 204: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

196 ASSIGN Statement � Chapter 14

DBMS=pc-file-formatspecifies which PC database product or spreadsheet system you want to accessfrom SAS. This is the only required option. The valid types are DBF, DIF, WK1,WK3, WK4, and XLS.

ACCDESC=libref.access-descriptor <(READ|WRITE|ALTER=password)>specifies an existing access descriptor.

Use this option when creating or updating a view descriptor based on an accessdescriptor that was created in a separate PROC ACCESS step.

You name the view descriptor in the CREATE statement. You can also use aSAS data set option on the ACCDESC= option to specify a SAS password for theaccess descriptor.

The ACCDESC= option has two aliases: AD= and ACCESS=.

VIEWDESC=libref.view-descriptorspecifies a view descriptor as input for the OUT= option. (See the description ofOUT=.)

OUT= <libref.>member-namespecifies a SAS data file. When VIEWDESC= and OUT= are used together, youcan write data that is accessed from the view descriptor to the SAS data set that isspecified in OUT=. Here is an example:

proc access viewdesc=vlib.invq4out=dlib.invq4;

run;

ASSIGN Statement

Indicates whether SAS variable names and formats are automatically generated.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: access descriptor

Interacts with: FORMAT, RENAME, RESET, UNIQUENot allowed with: UPDATE

Default: NOAlias: AN

ASSIGN <=> YES|NO|Y|N;

DetailsThe ASSIGN statement indicates whether SAS variable names and formats are

automatically generated. Where long names must be shortened to the SAS length limitof eight characters, variable names are automatically generated.

An editing statement such as ASSIGN appears after the CREATE anddatabase-description statements. See “CREATE Statement” on page 197 for moreinformation.

Page 205: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � CREATE Statement 197

You can use the value NO (or N) to modify SAS variable names and formats whenyou create an access descriptor and when you create view descriptors that are based onthis access descriptor. During an access descriptor’s creation, you use the RENAMEstatement to change SAS variable names, and you use the FORMAT statement tochange SAS formats.

Specify a YES (or Y) value for this statement to generate unique SAS variable namesfrom the first eight characters of the PC file column names, according to the rules listedbelow. With YES, you can change the SAS variable names only in the access descriptor.The SAS variable names that are saved in an access descriptor are always used whenview descriptors are created from the access descriptor; you cannot change them in theview descriptors.

Default SAS variable names are generated according to these rules:� If the column name is longer than eight characters, SAS uses only the first eight

characters. If truncating results in duplicate names, numbers are appended to theends of the names to prevent duplicate names. For example, the namesclientsname and clientsnumber become the SAS names clientsn and clients0.

� If the column name in the PC file contains blank characters, SAS ignores theblank characters. For example, the column name Paid On becomes the SAS namePaidOn.

� If the column name in the PC file starts with a digit (0 through 9), SAS adds thecharacter Z before it. For example, the column name 1stYear becomes the SASname Z1stYear.

� If the column name contains characters that are invalid in SAS names (includingnational characters), SAS replaces the invalid characters with underscores (_). Forexample, the column name $Paid becomes the SAS variable name _Paid.

When the SAS/ACCESS interface encounters the next CREATE statement to createan access descriptor, the ASSIGN statement is reset to the default NO value.

CREATE Statement

Creates a SAS/ACCESS descriptor file.

Requirement: This statement is required.Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: access descriptor or view descriptor

CREATE libref.descriptor-name.ACCESS|VIEW;

DetailsUse CREATE to create an access or view descriptor for a PC file you want to access

from SAS. To access a particular PC file of a supported type, you must create first anaccess descriptor, and then one or more view descriptors based on the access descriptor.

The descriptor name has three parts, separated by periods. The libref identifies aSAS library, which is associated with a directory on the local system disk where thedescriptor is created. The libref must already have been created using the LIBNAME

Page 206: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

198 CREATE Statement � Chapter 14

statement. The descriptor-name is the name of the descriptor to be created. The thirdpart is the descriptor type. Specify ACCESS for an access descriptor or VIEW for a viewdescriptor.

You can use the CREATE statement as many times as necessary in one procedureexecution. That is, you can create multiple access descriptors, as well as one or moreview descriptors based on these access descriptors, within the same execution of theACCESS procedure. Or, you can create access descriptors and view descriptors inseparate executions of the procedure.

You can use CREATE and UPDATE in the same PROC ACCESS block with onerestriction: a CREATE statement for a view descriptor should not follow an UPDATEstatement.

Creating Access DescriptorsWhen you create an access descriptor, you must place statements or groups of

statements in a certain order after the PROC ACCESS statement and its options, aslisted here:

1 CREATE must be the first statement after the PROC ACCESS statement with oneexception: if the block includes both CREATE and UPDATE statements, eitherstatement can be the first in the block.

2 Specify any database-description statement, such as PATH=. This informationdescribes the location and characteristics of the PC file. These statements must beplaced before any editing statements. Do not specify these statements when youcreate view descriptors.

Information from database-description statements is stored in an accessdescriptor. Therefore, you do not repeat this information when you create viewdescriptors.

3 Specify any editing statements: ASSIGN, DROP, FORMAT, LIST, RENAME,RESET, and SUBSET. QUIT is also an editing statement, but using it terminatesPROC ACCESS without creating your descriptor.

4 Specify the RUN statement. RUN executes the ACCESS procedure.

The order of the statements within the database-description and editing groupssometimes matters; see the individual statement descriptions for more information.

Note: Altering a PC file that has descriptor files defined on it might cause thedescriptor files to be out-of-date or invalid. For example, if you recreate a file and add anew column to the file, an existing access descriptor defined on that file does not showthat column, but the descriptor can still be valid. However, if you recreate a file anddelete an existing column from the file, the descriptor might be invalid. If the deletedcolumn is included in a view descriptor and this view is used in a SAS program, theprogram fails and an error message is written to the SAS log. �

Creating View DescriptorsYou can create view descriptors and access descriptors in the same ACCESS

procedure or in separate procedures.To create a view descriptor and the access descriptor on which it is based within the

same PROC ACCESS execution, you must place the statements or groups of statementsin a particular order after the PROC ACCESS statement and its options, as listed below:

1 Create the access descriptor as described in “Creating Access Descriptors” on page198, except omit the RUN statement.

2 Specify the CREATE statement for the view descriptor. The CREATE statementmust follow the PROC ACCESS statements that you used to create the accessdescriptor.

Page 207: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � CREATE Statement 199

3 Specify any editing statements: SELECT, SUBSET, and UNIQUE are valid onlywhen creating view descriptors. FORMAT, LIST, RENAME, and RESET are validfor both view and access descriptors. You can specify FORMAT, RENAME, andUNIQUE only when you specify ASSIGN=NO in the access descriptor that thisview descriptor references. QUIT is also an editing statement. However, if you useit, it terminates PROC ACCESS without creating your descriptor.

Statement order within this group usually does not matter. See the individualstatement descriptions for any restrictions.

4 Specify the RUN statement. RUN executes PROC ACCESS.

To create a view descriptor based on an access descriptor that was created in aseparate PROC ACCESS step, specify the access descriptor’s name in the ACCDESC=option in the new PROC ACCESS statement. You must specify the CREATE statementbefore any of the editing statements for the view descriptor.

If you create only one descriptor in a PROC step, the CREATE statement and itsaccompanying statements are checked for errors when you submit PROC ACCESS forprocessing. If you create multiple descriptors in the same PROC step, each CREATEstatement (and its accompanying statements) is checked for errors as it is processed.

If no errors are found when the RUN statement is processed, all descriptors aresaved. If errors are found, error messages are written to the SAS log, and processing isterminated. After you correct the errors, resubmit your statements.

Examples

Example 1: Create an Access Descriptor for a Worksheet FileThis example creates the access descriptor AdLib.Product for the worksheet file namedc:\sasdemo\specprod.wk4:

libname adlib ’c:\sasdata’;

proc access dbms=wk4;create adlib.product.access;path=’c:\sasdemo\specprod.wk4’;getnames=yes;assign=yes;rename productid prodid

fibername fiber;format productid 4.

weight e16.9fibersize e20.13width e16.9;

run;

Example 2: Create an Access Descriptor for an Excel WorksheetThis example creates an access descriptor named AdLib.Employ for the Excelworksheet named c:\dubois\employ.xls. It also creates a view descriptor namedVLib.Emp1204 for this same file:

libname adlib ’c:\sasdata’;libname vlib ’c:\sasviews’;

proc access dbms=xls;/* create access descriptor */create adlib.employ.access;

Page 208: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

200 DROP Statement � Chapter 14

path=’c:\dubois\employ.xls’;getnames=yes;assign=no;list all;

create vlib.emp1204.view;/* create view descriptor */select empid lastname hiredate salary

dept gender birthdate;format empid 6.

salary dollar12.2jobcode 5.hiredate datetime7.birthdate datetime7.;

subset where jobcode=1204;run;

Example 3: Create a View Descriptor from an Access DescriptorThis example creates a view descriptor VLib.BDays from the AdLib.Employ accessdescriptor, which was created in the previous PROC ACCESS step. You could also useFORMAT because the access descriptor was created with ASSIGN=NO.

libname adlib ’c:\sasdata’;libname vlib ’c:\sasviews’;

proc access accdesc=adlib.employ;create vlib.bdays.view;select empid lastname birthdate;format empid 6.

birthdate datetime7.;run;

DROP Statement

Drops a column from a descriptor.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: access descriptor, view descriptorInteracts with: RESET, SELECT, UPDATE

DROP <’>column-identifier-1<’><…<’>column-identifier-n<’>>;

Page 209: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � FORMAT Statement 201

DetailsThe DROP statement drops the specified column from an access descriptor. The

column cannot be selected for a view descriptor that is based on the access descriptor.However, the specified column in the PC file remains unaffected by this statement.

You can specify the DROP statement only when you create or update an accessdescriptor or when you update a view descriptor. DROP is not allowed when you createa view descriptor. When you use the UPDATE statement, you can specify DROP toremove a column from the view descriptor. However, the specified column in the PC fileremains unaffected by the DROP statement.

An editing statement, such as DROP, must follow the CREATE anddatabase-description statements when you create an access descriptor. See “CREATEStatement” on page 197 for more information about the order of statements.

The column-identifier argument can be either the column name or the positionalequivalent from the LIST statement, which is the number that represents columnplacement in the access descriptor or view descriptor. For example, to drop the thirdand fifth columns, submit this statement:

drop 3 5;

If the column name contains lowercase characters, special characters, or nationalcharacters, enclose the name in quotation marks. You can drop as many columns as youwant in one DROP statement.

To display a column that was previously dropped, specify that column name in theRESET statement. However, doing so also resets all column attributes—such as theSAS variable name format—to their default values.

FORMAT Statement

Changes a SAS format for a PC file column.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: access descriptor or view descriptorInteracts with: ASSIGN, DROP, RESET

FORMAT|FMT <’>column-identifier-1<’><=>SAS-format-name-1<…<’>column-identifier-n<’><=>SAS-format-name-n>;

DetailsThe FORMAT statement changes a SAS variable format from its default format. The

default SAS variable format is based on the data type and format of the PC file column.(See your PC file’s chapter for information about the default data types and formatsthat SAS assigns to PC files data.)

An editing statement, such as FORMAT, must follow the CREATE statement and thedatabase-description statements when you create a descriptor. See “CREATEStatement” on page 197 for more information about the order of statements.

The column-identifier argument can be either the column name or the positionalequivalent from the LIST statement, which is the number that represents the column’s

Page 210: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

202 LIST Statement � Chapter 14

place in the access descriptor. For example, to associate the DATE9. format with theBIRTHDATE column and with the second column in the access descriptor, submit thisstatement:

format 2=date9. birthdate=date9.;

The column identifier is specified on the left and the SAS format is specified on theright of the expression. The equal sign (=) is optional. If the column name containslowercase characters, special characters, or national characters, enclose the name inquotation marks. You can enter formats for as many columns as you want in oneFORMAT statement.

You can use the FORMAT statement with a view descriptor only if the ASSIGNstatement that was used when creating the access descriptor was specified with the NOvalue.

Note: When you use the FORMAT statement with access descriptors, the FORMATstatement also reselects columns that were previously dropped with the DROPstatement. �

LIST Statement

Lists columns in the descriptor and gives information about them.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: access descriptor or view descriptorDefault: ALL

LIST <ALL|VIEW|<’>column-identifier<’>>;

DetailsThe LIST statement lists columns in the descriptor along with information about the

columns. You can use the LIST statement when creating an access descriptor or a viewdescriptor. The LIST information is written to your SAS log.

If you use an editing statement, such as LIST, it must follow the CREATE statementand the database-description statements when you create a descriptor. You can specifyLIST as many times as you want while creating a descriptor; specify LIST last in yourPROC ACCESS code to see the entire descriptor. Or, if you are creating multipledescriptors, specify LIST before the next CREATE statement in order to list allinformation about the descriptor that you are creating.

The LIST statement can take one or more of these arguments:

ALLlists all columns in the PC file, the positional equivalents, the SAS variable names,and the SAS variable formats that are available for the access descriptor. Whenyou are creating an access descriptor, *NON-DISPLAY* appears next to the columndescription for any column that has been dropped. When you are creating a viewdescriptor, *SELECTED* appears next to the column description for columns thatyou have selected for the view.

Page 211: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � MIXED Statement 203

VIEWlists all columns that are selected for the view descriptor, along with theirpositional equivalents, their SAS names and formats, and any subsetting clauses.Any columns that were dropped in the access descriptor are not displayed. TheVIEW argument is valid only for a view descriptor.

column-identifierlists the specified column name, its positional equivalent, its SAS variable nameand format, and whether the column has been selected. If the column namecontains lowercase characters, special characters, or national characters, enclosethe name in quotation marks.

The column-identifier argument can be either the column name or the positionalequivalent, which is the number that represents the column’s place in thedescriptor. For example, to list information about the fifth column in thedescriptor, submit this statement:

list 5;

You can use one or more of these previously described options in a LIST statement,in any order.

MIXED Statement

Determines whether to convert numeric data values in a column to their character representationwhen the corresponding SAS variable is expecting a character value.

Valid: for WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats under Windowsoperating environments

MIXED <=> YES | NO | Y | N;

DetailsYou use the MIXED statement with WKn and XLS files if you have both numeric and

character data in a column. Specifying YES allows both numeric and character data tobe displayed as SAS character data. NO, the default, treats any data in a column thatdoes not match the specified type as missing values.

You can change the default value to YES by setting the SS_MIXED environmentvariable. For more information, see “Setting Environment Variables for XLS Files” onpage 235.

The MIXED statement is an editing statement and must follow the CREATEstatement and any database descriptions when you create an access descriptor.

Page 212: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

204 PATH= Statement � Chapter 14

PATH= Statement

Specifies the path and filename of the file to access.

Requirement: This statement is required.Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, Excel 95 file formats underWindows operating environmentsApplies to: access descriptor

PATH= ’path-and-filename<.PC-file-extension>’ |<’>filename<’> | fileref ;

DetailsThe PATH= statement indicates the path and name of the file you want to access. The

length of the filename and its other conventions can vary with the operating system.See the host documentation for your operating environment for more information.

For compatibility, place the PATH= statement immediately after the CREATEstatement and before any other database-description statements when creating accessdescriptors. See “CREATE Statement” on page 197 for more information.

You can specify the PATH= statement with one of these arguments:

’path-and-filename<.PC-file-extension>’specifies the fully qualified path and filename. You must enclose the entire pathand filename in quotation marks, including the appropriate PC file extension, suchas .dbf, .dif, .wk1, .wk3, wk4, .mdb, or .xls. If you omit the file extension,SAS/ACCESS software supplies it for you.

<’>filename<’>specifies the name of a file. The file must be located in your current (default)directory. If no extension is specified, the SAS/ACCESS interface supplies it foryou. If the filename includes characters that are invalid in SAS names, such asthe dollar sign ($) or if the filename begins with a number, you must enclose theentire filename in quotation marks.

filerefspecifies a fileref that references the path and name of the file. (Assigning filerefswith the FILENAME statement is described in Step-by-Step Programming withBase SAS Software.)

QUIT Statement

Terminates the procedure.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: access descriptor or view descriptorAlias: EXIT

Page 213: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � RENAME Statement 205

QUIT;

DetailsThe QUIT statement terminates the ACCESS procedure without any further

descriptor creation.

RENAME Statement

Modifies the SAS variable name.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: access descriptor or view descriptorInteracts with: ASSIGN, RESET

RENAME <’>column-identifier-1<’><=>SAS-variable-name-1<…<’>column-identifier-n<’><=>SAS-variable-name-n>;

DetailsThe RENAME statement enters or modifies the SAS variable name that is associated

with a column in a PC file. Use the RENAME statement when creating an accessdescriptor or a view descriptor.

An editing statement, such as RENAME, must follow the CREATE statement andthe database-description statements when you create a descriptor. See “CREATEStatement” on page 197 for more information about the order of statements.

Two factors affect the use of the RENAME statement: whether you specify theASSIGN statement when you are creating an access descriptor, and the type ofdescriptor that you are creating.

� If you omit the ASSIGN statement or specify it with a NO value, the renamed SASvariable names that you specify in the access descriptor are retained throughoutan ACCESS procedure execution. For example, if you rename the Customercolumn to CustNum when you create an access descriptor, that column continuesto be named CustNum when you select it in a view descriptor unless a RESETstatement or another RENAME statement is specified.

When creating a view descriptor that is based on this access descriptor, you canspecify the RESET statement or another RENAME statement to rename thevariable again, but the new name applies only in that view. When you create otherview descriptors, the SAS variable names are derived from the access descriptorvariable names.

� If you specify the YES value in the ASSIGN statement, you can use the RENAMEstatement to change SAS variable names only while creating an access descriptor.As described earlier in the ASSIGN statement, SAS variable names and formatsthat are saved in an access descriptor are always used when creating viewdescriptors that are based on it.

Page 214: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

206 RESET Statement � Chapter 14

The column-identifier argument can be either the PC file column name or thepositional equivalent from the LIST statement, which is the number that represents thecolumn’s place in the descriptor. For example, to rename the SAS variable names thatare associated with the seventh column and the nine-character FIRSTNAME column ina descriptor, submit this statement:

rename 7 birthdy ’firstname’=fname;

The column name (or positional equivalent) is specified on the left side of theexpression, with the SAS variable name on the right side. The equal sign (=) isoptional. If the column name contains lowercase characters, special characters, ornational characters, enclose the name in quotation marks. You can rename as manycolumns as you want in one RENAME statement.

When you are creating a view descriptor, the RENAME statement automaticallyselects the renamed column for the view. That is, if you rename the SAS variableassociated with a column, you do not have to issue a SELECT statement for thatcolumn.

When you are creating an access descriptor, the RENAME statement also reselectscolumns that were previously dropped with the DROP statement.

RESET Statement

Resets PC file columns to their default settings.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environments

Applies to: access descriptor or view descriptor

Interacts with: ASSIGN, DROP, FORMAT, RENAME, SELECT

Not allowed with: UPDATE

RESET ALL|<’>column-identifier-1<’><…<’>column-identifier-n<’>>;

DetailsThe RESET statement resets either the attributes of all columns or the attributes of

the specified columns to their default values. The RESET statement can be used whenyou create an access descriptor or a view descriptor, but it is not allowed when you areupdating a descriptor. RESET has different effects on access and view descriptors, asdescribed below.

If you use an editing statement, such as RESET, it must follow the CREATEstatement and the database-description statements when you create a descriptor. See“CREATE Statement” on page 197 for more information about the order of statements.

The RESET statement can take one or more of these arguments:

ALLfor access descriptors, resets all PC file columns that are defined to their defaultnames and format settings and reselects any dropped columns.

For view descriptors, ALL resets all columns that are selected so that nocolumns are selected for the view. You can then use the SELECT statement to

Page 215: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � RESET Statement 207

select new columns. See “SELECT Statement” on page 208 for more informationabout that statement.

column-identifiercan be either the PC file column name or the positional equivalent from the LISTstatement, which is the number that represents the column’s place in the accessdescriptor. For example, to reset the SAS variable name and format associatedwith the third column, submit this statement:

reset 3;

If the column name contains lowercase characters, special characters, ornational characters, enclose the name in quotation marks. You can reset as manycolumns as you want in one RESET statement, or use the ALL option to reset allcolumns.

When creating an access descriptor, the column-identifier is reset to its defaultname and format settings. When creating a view descriptor, the specified columnis no longer selected for the view.

Access DescriptorsWhen you create an access descriptor, the default setting for a SAS variable name is

a blank. However, if you have previously entered or modified any of the SAS variablenames, the RESET statement resets the modified names to the default names that aregenerated by the ACCESS procedure. How the default SAS variable names are setdepends on whether you included the ASSIGN statement. If you omitted ASSIGN orset it to NO, the default names are blank. If you set ASSIGN=YES, the default namesare the first eight characters of each PC file column name.

The current SAS variable format is also reset to the default SAS format, which wasdetermined from the column’s data type. Any columns that were previously dropped,but that are specified in the RESET statement, become available; they can be selectedin view descriptors that are based on this access descriptor.

View DescriptorsWhen you create a view descriptor, the RESET statement clears any columns that

were included in the SELECT statement (that is, it deselects the columns).When creating the view descriptor, if you reset a SAS variable and then select it

again within the same procedure execution, the SAS variable names and formats arereset to their default values, which are generated from the column names and datatypes. This applies only if you have omitted the ASSIGN statement or set the value toNO when you created the access descriptor on which the view descriptor is based. Ifyou specified ASSIGN=YES when you created the access descriptor, the RESETstatement has no effect on the view descriptor.

Page 216: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

208 SELECT Statement � Chapter 14

SELECT Statement

Selects PC file columns for the view descriptor.

Requirement: This statement is required.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environments

Applies to: view descriptor

Interacts with: RESET

Not allowed with: UPDATE

SELECT ALL|<’>column-identifier-1<’><…<’>column-identifier-n<’>>;

Details

The SELECT statement specifies which PC file columns in the access descriptor toinclude in the view descriptor. This is a required statement, and you can use it onlywhen you create view descriptors. You cannot use the SELECT statement when youupdate a view descriptor.

If you use an editing statement, such as SELECT, it must follow the CREATEstatement when you create a view descriptor. See “CREATE Statement” on page 197 formore information about statement order.

The SELECT statement can take one or more of these arguments:

ALLincludes in the view descriptor all columns that were defined in the accessdescriptor and that were not dropped.

column-identifiercan be either the column name or the positional equivalent from the LISTstatement, which is the number that represents the column’s place in the accessdescriptor on which the view is based. For example, to select the first threecolumns, submit this statement:

select 1 2 3;

If the column name contains lowercase characters, special characters, ornational characters, enclose the name in quotation marks. You can select as manycolumns as you want in one SELECT statement.

SELECT statements are cumulative within the same view creation. So, forexample, if you submit these SELECT statements, columns 1, 5, and 6 areselected, not just columns 5 and 6:

select 1;select 5 6;

To clear all your current selections when creating a view descriptor, use theRESET ALL statement; you can then use another SELECT statement to selectnew columns.

Page 217: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � TYPE Statement 209

SUBSET Statement

Adds or modifies selection criteria for a view descriptor.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: view descriptor

SUBSET selection-criteria;

DetailsYou use the SUBSET statement to specify selection criteria when you create a view

descriptor. This statement is optional. If you omit it, the view retrieves all data (rows)in the PC file.

An editing statement, such as SUBSET, must follow the CREATE statement whenyou create a view descriptor. See “CREATE Statement” on page 197 for moreinformation about statement order.

TYPE Statement

Changes the expected data types of SAS variables.

Valid: for DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environments

TYPE <’>column-identifier-1< ’><=> C | N<…column-identifier-n <=> C | N>;

DetailsSAS data sets have two data types: character (C) and numeric (N). Spreadsheet files

have the same two data types: character (for labels and formula strings) and numeric(for numbers and formulas). Changing the default data type of a SAS variable in adescriptor file also changes its associated default format in the loaded file.

If you omit the TYPE statement, the database field types are generated from the PCfiles data types. You can change as many database field types as you want in one TYPEstatement.

This statement is not available for use with DBF files.

Page 218: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

210 UNIQUE Statement � Chapter 14

UNIQUE Statement

Generates SAS variable names based on PC file column names.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: view descriptorInteracts with: ASSIGNNot allowed with: UPDATEAlias: UN

UNIQUE <=> YES|NO|Y|N ;

DetailsThe UNIQUE statement specifies whether the SAS/ACCESS interface generates

unique SAS variable names for PC file columns for which SAS variable names have notbeen entered. You cannot use the UNIQUE statement when you are updating a viewdescriptor.

An editing statement, such as UNIQUE, must follow the CREATE statement whenyou create a view descriptor. See “CREATE Statement” on page 197 for moreinformation about the order of statements. The UNIQUE statement is affected bywhether you specified the ASSIGN statement when you created the access descriptor onwhich this view is based, as follows:

� If you specified the ASSIGN=YES statement, you cannot specify UNIQUE whencreating a view descriptor. YES causes SAS to generate unique names, soUNIQUE is not necessary.

� If you omitted the ASSIGN statement or specified ASSIGN=NO, you must resolveany duplicate SAS variable names in the view descriptor. You can use UNIQUE togenerate unique names automatically, or you can use the RENAME statement toresolve duplicate names yourself. See “RENAME Statement” on page 205 forinformation about that statement.

If duplicate SAS variable names exist in the access descriptor on which you arecreating a view descriptor, you can specify UNIQUE to resolve the duplication. Whenyou specify UNIQUE=YES, the SAS/ACCESS interface appends numbers to anyduplicate SAS variable names, thus making each variable name unique. (See “CREATEStatement” on page 197 for an explanation of how to create descriptors.)

If you specify UNIQUE=NO, the SAS/ACCESS interface continues to allow duplicateSAS variable names to exist. You must resolve these duplicate names before saving(and thereby creating) the view descriptor.

Note: It is recommended that you use the UNIQUE statement. If you omit it andSAS encounters duplicate SAS variable names in a view descriptor, your job fails.

The equal (=) sign is optional in the UNIQUE statement. �

Page 219: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � UPDATE Statement 211

UPDATE Statement

Updates a SAS/ACCESS descriptor file.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underWindows operating environmentsApplies to: access descriptor or view descriptorNot allowed with: ASSIGN, RESET, SELECT, UNIQUE

UPDATE libref.descriptor-name.ACCESS|VIEW ;

DetailsUse the UPDATE statement to perform a quick, simple update of a descriptor. For

example, if the PC database file for an existing access descriptor is relocated, you canuse UPDATE with the PATH option to specify the new location.

Descriptors modified by UPDATE are not checked for errors. Where validation iscrucial, use CREATE to overwrite a descriptor rather than UPDATE.

The descriptor is a name in three parts separated by periods (.):

librefidentifies the library container, which is a location either on the local system’s diskor that the local system can directly access. The libref must have been previouslycreated by a LIBNAME statement.

descriptor-nameis the descriptor you are updating. It must already exist in libref. (See “CREATEStatement” on page 197.)

ACCESSindicates that you are updating an access descriptor while VIEW indicates you areupdating a view descriptor.

Multiple UPDATE statements can appear in one ACCESS procedure block. If youuse UPDATE to change an access descriptor, one or more UPDATE statements might berequired for views that depend on the modified access descriptor.

You can use UPDATE and CREATE in the same PROC ACCESS block.

Updating Access DescriptorsThe order of statements in an UPDATE block is as follows:1 UPDATE must be the first statement after the PROC ACCESS statement with one

exception. If the block includes both UPDATE and CREATE statements, eitherstatement can be the first in the block.

2 Data source description statements: All are allowed.3 Editing statements: These editing statements are not allowed: ASSIGN, LIST,

RESET, SELECT, VIEW.

Since the UPDATE block does not validate the updated descriptor, the order ofdescription and editing statements does not matter.

Page 220: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

212 UPDATE Statement � Chapter 14

Updating View Descriptors

1 UPDATE must be the first statement after the PROC ACCESS statement with oneexception. If the block includes both UPDATE and CREATE statements, eitherstatement can be the first in the block.

2 Data source description statements: All are allowed.3 Editing statements. These editing statements are not allowed: ASSIGN, DROP,

RESET, SELECT, and UNIQUE.

Examples

Updating an ExistingThis example updates an existing access descriptor named AdLib.Product:

libname adlib ’c:\sasdata’;

proc access dbms=wk4;update adlib.product.access;path=c:\lotus\specprod.wk4;rename productid prodid

fibername fiber;format productid 4.

weight e16.9fibersize e20.13width e16.9;

run;

This example updates the Employ access descriptor that is located in c:\sasdata,for the spreadsheet named c:\excel\employ.xls and updates the view descriptor forEmploy named Emp1204, located in c:\sasviews:

libname adlib ’c:\sasdata’;libname vlib ’c:\sasviews’;

proc access dbms=xls;update adlib.employ.access;path=’c:\excel\employ.xls’;list all;

update vlib.emp1204.view;format empid 6.

salary dollar12.2jobcode 5.hiredate datetime9.birthdate datetime9.;

subset where jobcode=1204;run;

Page 221: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The ACCESS Procedure for PC Files � UPDATE Statement 213

This example updates a second view descriptor that is based on Employ, namedBDays, that is also located in c:\sasviews. When you update a view, it is notnecessary to specify the access descriptor (using ACCDESC=) in the PROC ACCESSstatement. Note that FORMAT can be used because the Employ access descriptor wascreated with ASSIGN=NO.

libname vlib ’c:\sasviews’;

proc access dbms=xls;update vlib.bdays.view;format empid 6.

birthdate datetime7.;run;

Page 222: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

214

Page 223: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

215

C H A P T E R

15The DBLOAD Procedure for PCFiles

Overview: DBLOAD Procedure for PC Files 215DBLOAD Procedure Naming Conventions 216

DBLOAD Procedure Syntax 216

PROC DBLOAD Statement 216

ACCDESC= Statement 217

DELETE Statement 218ERRLIMIT= Statement 218

LABEL Statement 219

LIMIT= Statement 219

LIST Statement 220

LOAD Statement 220

PATH= Statement 221QUIT Statement 222

RENAME Statement 222

RESET Statement 223

WHERE Statement 224

Overview: DBLOAD Procedure for PC Files

The DBLOAD procedure for PC files is available only under Microsoft Windowsoperating environments. You can use the DBLOAD procedure with DBF, DIF, WK1,WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats. See “Methods for Accessing PCFiles Data” on page 3 for alternate methods for accessing data in PC file formats underthe UNIX, Microsoft Windows, and z/OS operating environments.

This section provides general reference information for the DBLOAD procedure. Itpresents the PROC DBLOAD options and statements that are common to all formats.File format specific information for the SAS/ACCESS interface to your PC file isincluded in separate sections.

Refer to SAS Language Reference: Dictionary and to the SAS documentation for youroperating environment for more information about SAS data sets and SAS libraries andtheir naming conventions or for help with the terminology used in this proceduredescription.

The DBLOAD procedure loads data to and creates PC files. This data can be fromany of these items: a SAS data file, a PROC SQL view, a DATA step view, or a viewdescriptor from any SAS/ACCESS interface product. The DBLOAD procedureassociates each SAS variable with a PC file column and assigns a default name anddata type to each column. You can use the default information or change it asnecessary. When you are finished customizing the columns, the procedure creates thePC file and loads it with the input data.

Page 224: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

216 DBLOAD Procedure Naming Conventions � Chapter 15

DBLOAD Procedure Naming ConventionsWhen you use the DBLOAD procedure to load a SAS data set into a PC file, the SAS

variable names cannot exceed eight characters. This restriction is applied in order tohave compatibility with SAS 6 naming conventions.

DBLOAD Procedure SyntaxWhen you use the DBLOAD procedure, you use different statements depending on

your task and your PC file. Not all statements are available with all PC file formats,and additional statements might be used with your PC file. The general syntax for thisprocedure is presented here. For specific details, see Chapter 6, “File Format-SpecificReference for IMPORT and EXPORT Procedures,” on page 25.

PROC DBLOAD <DBMS=pc-file><DATA=< libref.>SAS-data-set>;

Database-Description StatementPATH=’path-and-filename<.PC-file-extension>’|

<’>filename< ’>|fileref ;

Editing StatementsACCDESC=< libref.>access-descriptor;DELETE variable-identifier-1<…variable-identifier-n;>ERRLIMIT=error-limit;LABEL;LIMIT=load-limit;LIST <ALL|COLUMNS|FIELDS|variable-identifier>;QUIT;RENAME variable-identifier-1=<’>column-name-1<’>

<…variable-identifier-n<’>column-name-n<’>>;RESET ALL|variable-identifier-1 <…variable-identifier-n >;WHERE SAS-where-expression;

Creating and Loading StatementLOAD;

RUN;

PROC DBLOAD StatementRequirement: This statement is required.Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environments

Page 225: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The DBLOAD Procedure for PC Files � ACCDESC= Statement 217

PROC DBLOAD <DBMS=pc-file><DATA=< libref.>SAS-data-set>;

Arguments

DBMS=pc-fileSpecifies the PC file format that you want to access. Specify DBMS=DBF for DBFfiles, DBMS=DIF for DIF files, DBMS=WK1 | WK3 | WK4 for WKn files,DBMS=MDB for MDB files, or DBMS=XLS for XLS files. The DBMS= option isrequired.

DATA=<libref.>SAS-data-setspecifies the input data set. The input data can be retrieved from a SAS data file,a PROC SQL view, a DATA step view, or a SAS/ACCESS view descriptor. If thedata set is permanent, you must use its two-level name, libref.SAS-data-set. If youomit the DATA= option, the default is the last SAS data set that was created.

ACCDESC= Statement

Creates an access descriptor based on the new file.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environmentsAliases: ACCESS= and AD=

ACCDESC=< libref.>access-descriptor;

DetailsThe ACCDESC= statement creates an access descriptor based on the PC file that you

are creating and loading. After the new PC file is created and loaded, the accessdescriptor is automatically created. You must specify an access descriptor that does notalready exist.

An editing statement, such as ACCDESC=, must be specified after thedatabase-description statements when you create and load a file. See “LOADStatement” on page 220 for more information.

Page 226: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

218 DELETE Statement � Chapter 15

DELETE Statement

Prevents variables from being loaded into the new PC file.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environmentsInteracts with: RENAME, RESET

DELETE variable-identifier-1 <…variable-identifier-n>;

DetailsThe DELETE statement drops the specified SAS variables from the PC file being

created. The variable-identifier argument can be either the SAS variable name or thepositional equivalent from the LIST statement. The positional equivalent is the numberthat represents the variable’s place in the data set. For example, if you want to dropthe third variable, submit this statement:

delete 3;

You can drop as many variables as you want in one DELETE statement. If you dropmore than one variable, separate the identifiers with spaces, not commas.

Even if you drop a variable from the list of variables, the positional equivalents ofthe variables do not change. For example, if you drop the second variable, the thirdvariable is still referenced by the number 3, not 2.

An editing statement, such as DELETE, must be specified after thedatabase-description statements when you create and load a file. See “LOADStatement” on page 220 for more information.

ERRLIMIT= Statement

Stops loading data after a specified number of errors.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environmentsDefault: 100

ERRLIMIT=error-limit;

DetailsThe ERRLIMIT= statement stops loading observations after the specified number of

errors has occurred while inserting rows into the file.The error-limit argument must be a nonnegative integer. Specify ERRLIMIT=0 to

allow an unlimited number of errors to occur.

Page 227: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The DBLOAD Procedure for PC Files � LIMIT= Statement 219

An editing statement, such as ERRLIMIT=, must be specified after thedatabase-description statements when you create and load a file. See “LOADStatement” on page 220 for more information.

LABEL Statement

Causes column names to default to SAS labels.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environmentsInteracts with: RENAME, RESET

LABEL;

DetailsThe LABEL statement causes the column names to default to the SAS variable labels

when the new table is created. If a SAS variable has no label, the variable name isused. If the label is too long to be a valid column name, the label is truncated.

For the LABEL statement to take effect, the RESET statement must be used afterthe LABEL statement.

An editing statement, such as LABEL, must be specified after thedatabase-description statements when you create and load PC files. See “LOADStatement” on page 220 for more information.

LIMIT= Statement

Limits the number of observations that are loaded.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environmentsDefault: 5000

LIMIT=load-limit;

DetailsThe LIMIT= statement places a limit on the number of observations that can be

loaded into a new file. The maximum number for the limit statement varies with eachPC file. The load-limit argument must be a nonnegative integer. To load allobservations from your input data set, specify LIMIT=0.

If you omit the LIMIT= statement, a maximum of 5,000 observations are inserted.

Page 228: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

220 LIST Statement � Chapter 15

LIST Statement

Lists information about the variables to load.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environments

Default: ALL

LIST <ALL|COLUMNS|FIELDS|variable-identifier>;

DetailsThe LIST statement lists information about all or some of the SAS variables to be

loaded into the new file. By default, the list is sent to the SAS log.The LIST statement can take one or more of these arguments:

ALLlists information about all variables in the input SAS data set, regardless ofwhether those variables are selected for the load.

COLUMNSlists information only about the input SAS variables that are selected for the load.This argument does not apply to DBF files.

FIELDSlists information only about the input SAS variables that are selected for the load.

variable-identifierlists information only about the specified variable. The variable-identifierargument can be either the SAS variable name or the positional equivalent. Thepositional equivalent is the number that represents the variable’s position in thedata set. For example, if you want to list information for the column associatedwith the third SAS variable, submit this statement:

list 3;

You can specify LIST as many times as you want while creating a file; specify LISTbefore the LOAD statement to see the entire table. LIST must be specified after thedatabase-description statements. See “LOAD Statement” on page 220 for moreinformation.

LOAD Statement

Creates and loads the new PC file.

Requirement: This statement is required.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environments

Page 229: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The DBLOAD Procedure for PC Files � PATH= Statement 221

LOAD;

DetailsThe LOAD statement causes the interface view engine to create a file and to transfer

data to it from the input SAS data set after the DBLOAD procedure is submitted forprocessing. This statement is required to create and load a new file.

When you create and load a file, you must place statements or groups of statementsin a certain order after the PROC DBLOAD statement and its options, as follows:

1 Database-description statements: PATH= and your PC file specific statements.

2 Editing statements: ACCDESC=, DELETE, ERRLIMIT, LABEL, LIMIT=, LIST,RENAME, RESET, and WHERE. The order within this group usually does notmatter. See the individual statements for more information. QUIT is also anediting statement but using it immediately terminates PROC DBLOAD.

3 Creating and loading statement: LOAD must appear last before RUN in order tocreate and load the new table.

4 RUN statement: this statement is used to process the DBLOAD procedure.

PATH= Statement

Indicates the name and path of the PC file to create and load.

Requirement: This statement is required.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environments

PATH=’path-and-filename <.PC-file-extension>’|<’>filename< ’>|fileref ;

DetailsThe PATH= statement indicates the path and name of the PC file you want to create

and load. The length of the filename can vary with the operating environment. See theSAS documentation for your operating environment for any restrictions.

The PATH= statement can take one of these arguments:

’path-and-filename<.PC-file-extension>’specifies the fully qualified path and filename. You must enclose the entire pathand filename in quotation marks, including the appropriate PC file extension, suchas .dbf, .dif, .wkn, .mdb, or .xls. If you omit the file extension, SAS/ACCESSsupplies it for you.

<’>filename <’>specifies the name of a file. The file must be located in your current (default)directory. If no extension is specified, the SAS/ACCESS interface supplies it foryou. If the filename includes characters that are invalid in SAS names, such as

Page 230: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

222 QUIT Statement � Chapter 15

the dollar sign ($) or if the filename begins with a number, you must enclose theentire filename in quotation marks.

filerefspecifies a fileref that references the path and name of the file. (Assigning filerefswith the FILENAME statement is described in Step-by-Step Programming withBase SAS Software.)

A file with the same name must not already exist. If one does exist, it is notoverwritten. An error message is written to the SAS log, and the PC file that isspecified in this statement is not loaded.

QUIT Statement

Exits the DBLOAD procedure.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environmentsAlias: EXIT

QUIT;

DetailsThe QUIT statement exits the procedure without further processing.

RENAME Statement

Renames PC file columns.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environments

Interacts with: DELETE, LABEL, RESET

Alias: COLUMN

RENAME variable-identifier-1=<’>column-name-1<’><…variable-identifier-n =<’>column-name-n<’>>;

DetailsThe RENAME statement changes the names of the PC file’s columns that are

associated with the listed SAS variables. If you omit the RENAME statement, all

Page 231: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The DBLOAD Procedure for PC Files � RESET Statement 223

column names default to the corresponding SAS variable names unless you specify theLABEL statement.

The variable-identifier argument can be either the SAS variable name or positionalequivalent from the LIST statement. The positional equivalent is the number thatrepresents where to place the variable in the data set. For example, submit thisstatement if you want to rename the column associated with the third SAS variable:

rename 3=’employname’;

The column-name argument must be a valid PC file column name. If the columnname includes lowercase characters, special characters, or national characters, youmust enclose the column name in quotation marks.

The RENAME statement enables you to include variables that you have previouslydeleted. For example, you submit these statements:

delete 3;rename 3=’empname’;

The DELETE statement first drops the third variable. The RENAME statement thenincludes the third variable and assigns the name EMPNAME and the default columntype to it.

You can rename as many variables as you want in one RENAME statement. TheRENAME statement overrides the LABEL statement for columns that are renamed.

An editing statement, such as RENAME, must be specified after thedatabase-description statements when you create and load a PC file. See “LOADStatement” on page 220 for more information.

RESET Statement

Resets column names and data types to their default values.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environments

Interacts with: DELETE, LABEL, RENAME

RESET ALL|variable-identifier-1<…variable-identifier-n>;

DetailsThe RESET statement resets the columns that are associated with the listed SAS

variables to the default column name, column data type, and ability to accept nullvalues. If you specify ALL, all columns are reset to their default values, and anydeleted columns are restored with their default values.

The variable-identifier argument can be either the SAS variable name or thepositional equivalent from the LIST statement. The positional equivalent is the numberthat represents the variable’s place in the data set. For example, if you want to resetthe column associated with the third SAS variable, submit this statement:

reset 3;

You can reset as many columns as you want in one RESET statement.

Page 232: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

224 WHERE Statement � Chapter 15

You must use the RESET statement after the LABEL statement for the LABELstatement to take effect.

An editing statement, such as RESET, must be specified after thedatabase-description statements when you create and load a PC file. See “LOADStatement” on page 220 for more information.

WHERE Statement

Loads a subset of data into the new PC file.

Valid: for DBF, DIF, WK1, WK3, WK4, Excel 4, Excel 5, and Excel 95 file formats underMicrosoft Windows operating environments

WHERE SAS-where-expression;

DetailsThe WHERE statement loads a subset of observations into the new PC file. The

SAS-where-expression must be a valid SAS WHERE statement that uses SAS variablenames (not column names) as defined in the input data set. This example loads onlythe observations in which the SAS variable Country has the value Brazil.

where country=’Brazil’;

For more information about the syntax of the SAS WHERE statement, see SASLanguage Reference: Dictionary.

An editing statement, such as WHERE, must be specified after thedatabase-description statements when you create and load a PC File. See “LOADStatement” on page 220 for more information.

Page 233: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

225

C H A P T E R

16File-Specific Reference for theACCESS and DBLOAD Procedures

ACCESS Procedure: XLS Specifics 226Overview: ACCESS Procedure for XLS Files 226

ACCESS Procedure Syntax for XLS Files 226

ACCESS Procedure Data Conversions for XLS Files 228

DBLOAD Procedure: XLS Specifics 232

Overview: DBLOAD Procedure for XLS Files 232DBLOAD Procedure Syntax for XLS Files 232

DBLOAD Procedure Data Conversions for XLS Files 233

Setting Environment Variables for XLS Files 235

ACCESS Procedure: WKn Specifics 236

ACCESS Procedure Syntax for WKn Files 236

ACCESS Procedure Data Conversions for WKn Files 239DBLOAD Procedure: WKn Specifics 240

DBLOAD Procedure Syntax for WKn Files 240

DBLOAD Procedure Data Conversions for WKn Files 241

Setting Environment Variables for WKn Files 242

ACCESS Procedure: DBF Specifics (Windows) 243ACCESS Procedure Syntax for DBF Files 243

ACCESS Procedure Data Conversions for DBF Files 245

DBLOAD Procedure: DBF Specifics (Windows) 245

DBLOAD Procedure Syntax for DBF Files 245

DBLOAD Procedure Data Conversions for DBF Files 247Setting Environment Variables for DBF Files 247

ACCESS Procedure: DIF Specifics 247

ACCESS Procedure Syntax for DIF Files 248

ACCESS Procedure Data Conversions for DIF Files 250

Datetime Conversions in the ACCESS Procedure 250

DBLOAD Procedure: DIF Specifics 250DBLOAD Procedure Syntax for DIF Files 251

Datetime Conversions in the DBLOAD Procedure 252

Setting Environment Variables for DIF Files 253

DIF File Data Types 253

Page 234: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

226 ACCESS Procedure: XLS Specifics � Chapter 16

ACCESS Procedure: XLS Specifics

Overview: ACCESS Procedure for XLS FilesChapter 14, “The ACCESS Procedure for PC Files,” on page 191 contains general

information about this feature. This section provides XLS-specific syntax for theACCESS procedure and describes ACCESS procedure data conversions.

ACCESS Procedure Syntax for XLS FilesTo create an access descriptor, you use the DBMS=XLS option and six

database-description statements: PATH=, GETNAMES, RANGE, SCANTYPE,SKIPROWS, and WORKSHEET. These database-description statements supplyXLS-specific information to SAS, and must immediately follow the CREATE statement.In addition to the database-description statements, you can use editing statementswhen you create an access descriptor. These editing statements must follow thedatabase-description statements.

Database-description statements are required only when you create accessdescriptors. Because the XLS information is stored in an access descriptor, you do notneed to repeat this information when you create view descriptors.

The SAS/ACCESS interface to XLS uses the following procedure statements:

PROC ACCESS DBMS=XLS | EXCEL;CREATE libref.member-name.ACCESS | VIEW;

UPDATE libref.member-name.ACCESS | VIEW;

GETNAMES <=> YES | NO | Y | N;

PATH= ’path-and-filename’<.XLS> ’| < ’>filename<’> | fileref;RANGE <=> <’>range-name<’> | ’range-address’;

SCANTYPE <=> YES | NO | Y | N | <number-of-rows>;

SKIPROWS <=> number-of-rows-to-skip;WORKSHEET <=> worksheet-name;

ASSIGN <=> YES | NO | Y | N ;DROP <’>column-identifier-1<’> <…<’>column-identifier-n<’>>;

FORMAT <’>column-identifier-1<’> <=> SAS-format-name-1<…<’>column-identifier-n<’> <=> SAS-format-name-n> ;

LIST <ALL | VIEW | <’>column-identifier<’>> ;

MIXED <=> YES | NO | Y | N;

RENAME <’>column-identifier-1<’> <=> SAS-variable-name-1<…<’>column-identifier-n<’> <=> SAS-variable-name-n> ;

RESET ALL | <’>column-identifier-1<’> <…<’>column-identifier-n<’>> ;

SELECT ALL | <’>column-identifier-1< ’> <…<’>column-identifier-n<’>> ;SUBSET selection-criteria ;

TYPE column-identifier-1 <=> C | N <… column-identifier-n <=> C | N>;UNIQUE <=> YES | NO | Y | N ;

Page 235: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � ACCESS Procedure Syntax for XLS Files 227

RUN;

Note: By default, PROC ACCESS uses Excel 5 files, which have an identical formatto Excel 95 files. �

Note: Microsoft Excel 4, 5, and 7 limits are: columns — 256, rows — 16,384. �

The QUIT statement is also available in PROC ACCESS. However, it causes theprocedure to terminate. QUIT is used most often in the interactive line andnoninteractive modes to exit the procedure without exiting SAS.

The following list provides detailed information about the XLS-specific statements:

GETNAMES <=> YES | NO | Y | N;determines whether SAS variable names are generated from column names in thefirst row of the range when an access descriptor is created. When you update adescriptor, you are not allowed to specify the GETNAMES statement.

The GETNAMES statement is optional. If you omit it, the default valueGETNAMES=NO is used, and the XLS interface generates the SAS variablenames VAR0, VAR1, VAR2, and so on. If you specify GETNAMES=YES, the SASvariable names are generated from the column names in the first row of the range.GETNAMES=YES also sets the SKIPROWS value to 1.

You can change the default value from NO to YES by setting the SS_NAMESenvironment variable. For more information, see “Setting Environment Variablesfor XLS Files” on page 235.

The GETNAMES statement is a database-description statement. It must followthe CREATE statement and precede any editing statements when you create adescriptor.

RANGE <=> <’>range-name<’> | ’range-address’;subsets a specified section of an XLS file worksheet. The range-name is the namethat is assigned to a range address within the worksheet. Range names can be upto 15 characters long and are not case sensitive.

The range-address is identified by the top-left cell that begins the range and thebottom-right cell that ends the range within the XLS worksheet file. Thebeginning and ending cells are separated by two periods. For example, the rangeaddress C9..F12 indicates a cell range that begins at Cell C9, ends at Cell F12,and includes all cells in between.

The RANGE statement is optional. If you omit RANGE, the entire worksheet isaccessed as the default range.

The RANGE is a database-description statement. It must follow the CREATEstatement and precede any editing statements when you create a descriptor.

SCANTYPE <=> YES | NO | Y | N | <number-of-rows>;finds the most common Excel data type and format for each column in a specifiednumber of rows in an XLS worksheet in order to generate the default SAS format.By default, formats that Excel finds in the first row of the entire worksheet or inthe first row of a range (if specified) in the worksheet generate SAS variableformats.

The SCANTYPE statement is optional, and its default value is NO. If youspecify YES, the ACCESS procedure scans data types and formats of all rows ineach column of the worksheet or range and then uses the most common one togenerate the default SAS format for each column. If you specify a number of rows,PROC ACCESS scans only the specified number of rows and returns the mostcommon format.

If you specify the SKIPROWS statement, the ACCESS procedure skips thespecified rows and starts scanning from the next row. For example, if you specify

Page 236: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

228 ACCESS Procedure Data Conversions for XLS Files � Chapter 16

SKIPROWS=3, PROC ACCESS skips the first three rows and begins scanning thedata type and format on the fourth row.

You can change the default value to YES by setting the SS_SCAN environmentvariable. For more information, see “Setting Environment Variables for XLS Files”on page 235.

Specifying SCANTYPE=0 is equivalent to specifying SCANTYPE=NO.The SCANTYPE statement is a database-description statement. It must follow

the CREATE statement and precede any editing statements when you create adescriptor.

SKIPROWS <=> number-of-rows-to-skip;specifies the number rows, beginning at the top of the range in the XLS file, toignore when you are reading data from the XLS file. The default value forSKIPROWS is 0. The skipped (or ignored) rows often contain information such ascolumn labels or names, or underscores rather than input data.

If GETNAMES=YES, the default value of SKIPROWS automatically changes to1. The first row of data and formats after SKIPROWS in a range is used togenerate the SAS variable types and formats. However, you can use theSCANTYPE statement to scan the formats of a specified number of rows and usethe most common data type and format to generate the default SAS variable typesand formats. For more information, see “Setting Environment Variables for XLSFiles” on page 235.

The SKIPROWS statement is a database-description statement. It must followthe CREATE statement and precede any editing statements when you create adescriptor.

WORKSHEET <=> <’>worksheet-name<’>;identifies one worksheet from a group of worksheets while you are reading from anXLS file. The worksheet-name is a 31-character name and is not case sensitive.For example, specifying WORKSHEET=SHEET2 identifies worksheet 2 from agroup of worksheets

The WORKSHEET statement is optional. For Excel 4 files, there is only oneworksheet identifier, WORKSHEET1. Therefore, the WORKSHEET statement isignored. Under Excel 5, the default value is SHEET1. If you change the defaultworksheet from within Excel, you can either supply the new worksheet name orsupply the worksheet’s value (such as Sheet5 ).

The WORKSHEET statement is a database-description statement. It mustfollow the CREATE statement and precede any editing statements when youcreate an access descriptor.

ACCESS Procedure Data Conversions for XLS Files

You use PROC ACCESS to define descriptors that identify spreadsheet data and theconversions necessary to use that data in SAS programs. The Microsoft Excel label datatype is formatted as a SAS character type, and the Microsoft Excel number data type isformatted as a SAS numeric type.

Fonts, attributes, and colors in the XLS files are not read into the SAS data sets.However, the ACCESS procedure supports most of the XLS number formats andautomatically converts them to the corresponding SAS formats. XLS data strings thatare longer than 200 characters are truncated during conversion into SAS data sets. XLSfiles that create a SAS data file can contain up to 256 variables and 16,384 observations.

The following table shows the default SAS variable formats that the ACCESSprocedure assigns to each type of standard XLS file data.

Page 237: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � ACCESS Procedure Data Conversions for XLS Files 229

Table 16.1 Default SAS Variable Formats for XLS File Data

XLS File Data SAS Variable Format

Data Type XLS Format String Type Format

Char1 @2 Char $w.

Numeric3 General Num BEST

Numeric 0 Num w.d

Numeric 0.00 Num w.d

Numeric #,##0 Num COMMAw.d

Numeric #,##0.00 Num COMMAw.d

Numeric #,##0_);(#,##0) Num NEGPARENw.d

Numeric #,##0_);[Red](#,##0) Num NEGPARENw.d

Numeric #,##0.00_);(#,##0.00) Num NEGPARENw.d

Numeric #,##0.00_);[Red](#,##0.00) Num NEGPARENw.d

Numeric $#,##0_);($#,##0) Num DOLLARw.d

Numeric $#,##0_);[Red]($#,##0) Num DOLLARw.d

Numeric ($#,##0.00_);($#,##0.00) Num DOLLARw.d

Numeric ($#,##0.00_);[Red]($#,##0.00) Num DOLLARw.d

Numeric _($*#,##0_);_($*(#,##0);_($*"-"_);_(@_)

Num DOLLARw.d

Numeric _(*#,##0_);_(*(#,##0);_(*"-"_);_(@_)

Num NEGPARENw.d

Numeric _($*#,##0.00_);_($*(#,##0.00);_($*"-"??_);_(@_)

Num DOLLARw.d

Numeric _(*#,##0.00_);_(*(#,##0.00);_(*"-"??_);_(@_)

Num NEGPARENw.d

Numeric 0% Num PERCENTw.d

Numeric 0.00% Num PERCENTw.d

Numeric 0.00E+00 Num Ew.d

Numeric ##0.0E+0 Num Ew.d

Numeric m/d/yy Num MMDDYYw.

Numeric d-mmm-yy Num MMDDYYw.

Numeric d-mmm Num DATEw.

Numeric mmm-yy Num MONYYw.

Numeric h:mm AM/PM Num TIMEw.

Numeric h:mm:ss AM/PM Num TIMEw.

Numeric h:mm Num TIMEw.

Numeric hh:mm Num TIMEw.

Numeric h:mm:ss Num TIMEw.

Numeric hh:mm:ss Num TIMEw.

Page 238: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

230 ACCESS Procedure Data Conversions for XLS Files � Chapter 16

XLS File Data SAS Variable Format

Data Type XLS Format String Type Format

Numeric m/d/yy h:mm Num DATETIMEw.

Numeric ddmmmyy Num DATEw.

Numeric ddmmmyyyy:hh:mm:ss Num DATETIMEw.

Numeric dd Num DATEw.

Numeric dd/mm/yy Num DDMMYYw.

Numeric dddd Num DATEw.

Numeric mm/dd/yy Num MMDDYYw.

Numeric mm:ss Num MMSSw.

Numeric mm yy Num MONYYw.

Numeric mm yyyy Num MONYYw.

Numeric mm:yy Num MONYYw.

Numeric mm:yyyy Num MONYYw.

Numeric mm-yy Num MONYYw.

Numeric mm-yyyy Num MONYYw.

Numeric mmyy Num MONYYw.

Numeric mmyyyy Num MONYYw.

Numeric mm.yy Num MONYYw.

Numeric mm.yyyy Num MONYYw.

Numeric mm/yy Num MONYYw.

Numeric mm/yyyy Num MONYYw.

Numeric mmmm Num MONYYw.

Numeric m Num MONYYw.

Numeric mmmyy Num MONYYw.

Numeric mmmyyyy Num MONYYw.

Numeric dddd, mmmm dd, yyyy Num MONYYw.

Numeric dddd, dd mmmm yyyy Num MONYYw.

Numeric mmmm dd, yyyy Num MONYYw.

Numeric dd mmmm yyyy Num MONYYw.

Numeric yy Num YYMMDDw.

Numeric yyyy Num YYMMDDw.

Numeric yy mm Num YYMMDDw.

Numeric yyyy mm Num YYMMDDw.

Numeric yy:mm Num YYMMDDw.

Numeric yyyy:mm Num YYMMDDw.

Numeric yy-mm Num YYMMDDw.

Numeric yyyy-mm Num YYMMDDw.

Page 239: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � ACCESS Procedure Data Conversions for XLS Files 231

XLS File Data SAS Variable Format

Data Type XLS Format String Type Format

Numeric yymm Num YYMMDDw.

Numeric yyyymm Num YYMMDDw.

Numeric yy.mm Num YYMMDDw.

Numeric yyyy.mm Num YYMMDDw.

Numeric yy/mm Num YYMMDDw.

Numeric yyyy/mm Num YYMMDDw.

Numeric yy-mm-dd Num YYMMDDw.

Numeric yymmm Num YYMMDDw.

Numeric yyyymmm Num YYMMDDw.

1 Label data.2 The XLS character format for Excel Version 5.3 Number, formula, or missing data.

Table 16.2 Default SAS Variable Formats for Customized XLS Format Strings

XLS File Data SAS Variable Format

Data Type XLS Format String Type Format

Numeric "$" Num DOLLARw.d

Numeric "E" Num Ew.d

Numeric "m, d and y" Num MMDDYYw.

Numeric "m and h" Num TIMEw.d

Numeric "m and s" Num TIMEw.d

Numeric "m and y" Num MONYYw.

Numeric "m" Num DATEw.

Numeric "d" Num DATEw.

Numeric "y" Num DATEw.

Numeric "0.0" Num w.d

Numeric Fraction values (#?/?) Num BESTw.d

Numeric Percent values (0.0%) Num PERCENTw.d

Numeric All others Num BESTw.d

w is based on Excel column width. The Excel format string controls .d.If XLS files data falls outside of the valid SAS data ranges, you receive an error

message in the SAS log when you try to access the data.The SAS/ACCESS interface does not fully support the Microsoft Excel hidden and

text formats. XLS data in hidden format is displayed in SAS data sets. However, youcan drop the hidden column when you are creating the access descriptor. If you want todisplay a formula in text format, add a space to indicate that the formula entry is alabel. Otherwise, the results of the formula display.

You can change the default value from NO to YES by setting the SS_MIXEDenvironment variable. For more information, see “Setting Environment Variables forXLS Files” on page 235.

Page 240: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

232 DBLOAD Procedure: XLS Specifics � Chapter 16

If you set the SS_MIXED environment variable to YES, numeric values in XLS filesare converted to character strings in SAS data sets if the corresponding SAS variabletype is specified as character.

DBLOAD Procedure: XLS Specifics

Overview: DBLOAD Procedure for XLS FilesChapter 15, “The DBLOAD Procedure for PC Files,” on page 215 contains general

information about this feature. This section provides XLS-specific syntax for theDBLOAD procedure and describes DBLOAD procedure data conversions.

DBLOAD Procedure Syntax for XLS FilesTo create and load an XLS table, the SAS/ACCESS interface to XLS uses the

following statements:

PROC DBLOAD DBMS=XLS | EXCEL <DATA=<libref.>SAS-data-set>;PATH=’path-and-filename<.XLS>’ | <’>filename<’> | fileref;VERSION <=> EXCEL-product-number;PUTNAMES <=> YES | NO | Y | N;ACCDESC= <libref.>access-descriptor;DELETE variable-identifier-1 <…variable-identifier-n>;ERRLIMIT= error-limit;FORMAT SAS-variable-name-1 SAS-format-1 <=>

<…SAS-variable-name-n SAS-format-n>;LABEL;LIMIT=load-limit;LIST <ALL | COLUMNS | FIELDS | variable-identifier>;RENAME variable-identifier-1 <=> <’>column-name-1<’>

<…variable-identifier-n = <’>column-name-n<’>>;RESET ALL | variable-identifier-1 <…variable-identifier-n>;WHERE SAS-where-expression ;LOAD ;

RUN ;

The QUIT statement is also available in PROC DBLOAD. However, it causes theprocedure to terminate. QUIT is used most often in the interactive line andnoninteractive modes to exit the procedure without exiting SAS.

The following list provides detailed information about the XLS-specific statements:

FORMAT SAS-variable-name-1 SAS-format-1 <…SAS-variable-name-nSAS-format-n>;

assigns a temporary format to a SAS variable in the input SAS data set. Thisformat temporarily overrides any other format for the variable. The assignmentlasts only for the duration of the procedure. Assign formats to as many variablesas you want in one FORMAT statement.

Page 241: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � DBLOAD Procedure Data Conversions for XLS Files 233

Use FORMAT when you want to change the format, column width, or thenumber of decimal digits for columns being loaded into the PC file. For example, ifyou change the SAS variable format 12.1 to DOLLAR15.2, the column format ofthe loaded data changes from a fixed numeric format with a column width of 12and one decimal digit to a currency format with a column width of 15 and twodecimal digits.

PUTNAMES <=> YES|NO|Y|N;writes column names to the first row of the new XLS file. The column names canbe default SAS variables names or, if you specify the LABEL statement, SASvariable labels. You can modify the column names using the RENAME statement.

The PUTNAMES statement is optional. If you omit PUTNAMES, data is readfrom the data set and written to the XLS file—beginning in the first row of theXLS file—and no column names are written to the file.

You can change the default value to YES by setting the SS_NAMESenvironment variable. For more information, see “Setting Environment Variablesfor XLS Files” on page 235.

VERSION <=> Excel-product-number;specifies the version number of the Excel product you are using, such as Excel 5.The Excel-product-number argument can be one of the following values:

Table 16.3 Excel Versions

Value Description

3 Microsoft Excel Version 3

4 Microsoft Excel Version 4

5 Microsoft Excel Version 5

7 Microsoft Excel 95 (also called Microsoft Excel Version 7)

The DBLOAD procedure chooses the default version of Excel depending onwhich operating environment you use. If you use Windows, DBLOAD uses Excel 5.Excel 5 files have the identical format to Excel 95 files.

PROC DBLOAD does not support Excel 97 or later files. For information aboutaccessing these files, see “Supported Data Sources and Platforms” on page 7.

Specify VERSION before the TYPE statement in order to get the correct datatypes for your new XLS table.

DBLOAD Procedure Data Conversions for XLS FilesThis section explains how SAS data is read into Microsoft Excel data when a table is

loaded. In this conversion, the SAS character data type is converted into the MicrosoftExcel label type and the SAS numeric type is converted into the Microsoft Excelnumber type.

The SAS/ACCESS interface automatically converts SAS formats to the same orassociated Microsoft Excel formats and column widths. However, you can temporarilyassign other formats and column widths to SAS variables by using the FORMATstatement so that the loaded XLS file columns have the formats you want. Thefollowing table shows SAS variable types and formats and the XLS data types, formats,and column widths to which you can assign them.

Note: The FORMAT statement in PROC DBLOAD changes only the format of SASvariables while you are creating and loading the XLS files. When the procedure iscompleted, the formats of SAS variables return to their original settings. �

Page 242: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

234 DBLOAD Procedure Data Conversions for XLS Files � Chapter 16

XLS date and time values are numeric data.

Table 16.4 Converting SAS Variable Formats to XLS File Data

SAS Variable Format XLS File Data

Type Format XLS Format String Data Type

Char " " General LABEL

Char $CHAR General LABEL

Char $ General LABEL

Num BESTw.d General NUMBER

Num COMMAw.d #,##0 NUMBER

Num COMMAXw.d #,##0 NUMBER

Num DATEw. ddmmmyy NUMBER

Num DATETIMEw.d ddmmmyyyy:hh:mm:ss NUMBER

Num DAYw. dd NUMBER

Num DDMMYYw. dd/mm/yy NUMBER

Num DOLLARw.d "$"#,##0_);("$"#,##0) NUMBER

Num DOLLARXw.d "$"#,##0_);("$"#,##0) NUMBER

Num DOWNAMEw.d dddd NUMBER

Num Ew. 0.00E+00 NUMBER

Num HHMMw.d h:mm NUMBER

Num HOURw.d h:mm NUMBER

Num JULDAYw. m/d/yy NUMBER

Num JULIANw. m/d/yy NUMBER

Num MMDDYYw. mm/dd/yy NUMBER

Num MMSSw.d mm:ss NUMBER

Num MMYYxw. mm yy NUMBER

Num MMYYC mm:yy NUMBER

Num MMYYD mm-yy NUMBER

Num MMYYN mmyy NUMBER

Num MMYYP mm.yy NUMBER

Num MMYYS mm/yy NUMBER

Num MONNAMEw. mmmm NUMBER

Num MONTHw. m NUMBER

Num MONYYw. mmmyy NUMBER

Num NEGPARENw.d #,##0_);(#,##0) NUMBER

Num NENGOw. m/d/yy NUMBER

Num PERCENTw.d 0% NUMBER

Num QTRw. m/d/yy NUMBER

Page 243: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � Setting Environment Variables for XLS Files 235

SAS Variable Format XLS File Data

Type Format XLS Format String Data Type

Num QTRRw. m/d/yy NUMBER

Num SSNw. 000-00-0000 NUMBER

Num TIMEw.d h:mm:ss NUMBER

Num TODw. h:mm:ss NUMBER

Num W 0 NUMBER

Num WEEKDATEw. dddd, mmmm dd, yyyy NUMBER

Num WEEKDATXw. dddd, dd mmmm yyyy NUMBER

Num WEEKDAYw. m/d/yy NUMBER

Num WORDDATEw. mmmmdd, yyyy NUMBER

Num WORDDATXw. dd mmmm yyyy NUMBER

Num YEARw. yy or yyyy NUMBER

Num YYMM yy mm NUMBER

Num YYMMC yy:mm NUMBER

Num YYMMD yy-mm NUMBER

Num YYMMN yymm NUMBER

Num YYMMP yy.mm NUMBER

Num YYMMS yy/mm NUMBER

Num YYMMDDw. yy-mm-dd NUMBER

Num YYMONw. yymmm NUMBER

Num Zw.d 0w.d NUMBER

Num FRACTw. # ?/? NUMBER

Excel column widths are set to w and display in the column. If the data is largerthan column width, it displays as pound signs (###). In that case, you can view it byadjusting the column width.

Setting Environment Variables for XLS Files

You can change the default behavior of PROC ACCESS and PROC DBLOAD bysetting environment variables in your SAS configuration file. You can set threeSAS/ACCESS environment variables: SS_MIXED, SS_NAMES, and SS_SCAN. Settingthese variables in your SAS configuration file changes how the interface works bydefault.

The configuration file omits these three environment variables, which means theirdefault values are NO.

SS_MIXED YES | NOYES allows both Microsoft Excel numeric and character data in a column to bedisplayed as SAS character data. The Microsoft Excel numeric data is converted toits character representation when its corresponding SAS variable type is definedas character.

Page 244: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

236 ACCESS Procedure: WKn Specifics � Chapter 16

NO does not convert Microsoft Excel numeric data in a column into SAScharacter data. Microsoft Excel numeric data is read in as SAS missing valueswhen its corresponding SAS variable type is defined as character. NO is thedefault.

Setting the SS_MIXED environment variable changes the default value of theMIXED statement in PROC ACCESS.

SS_NAMES YES | NOYES in PROC ACCESS generates SAS variable names from column names in thefirst row of the worksheet or the specified range of the worksheet. It then readsdata from the second row. YES in PROC DBLOAD writes column names usingSAS variable names or SAS variable labels to the first row of the new XLS file,reads the data from the data set, and writes it to the XLS file beginning with thesecond row.

NO in PROC ACCESS generates the SAS variable names VAR0, VAR1, VAR2,and so on, and reads data from the first row of the worksheet or specified range.NO in PROC DBLOAD reads the data from the data set and writes it to the XLSfile beginning with the first row. NO is the default.

Setting the SS_NAMES environment variable changes the default value of theGETNAMES statement in PROC ACCESS and the PUTNAMES statement inPROC DBLOAD.

SS_SCAN YES | NO | number-of-rowsYES scans the data type and format of rows in a worksheet or specified rangeafter skipping the number of rows specified in the SKIPROWS statement. Afterscanning the rows, SS_SCAN finds the most common Microsoft Excel data typeand format in order to generate the default SAS data type and format. If anumber of rows is specified, SAS/ACCESS scans the data type and format onlyfrom these rows.

NO uses the type and format of the first row in a worksheet or specifiedrange—after skipping the number of rows specified in SKIPROWS—to generatethe default SAS data type and format. NO is the default.

Number-of-rows scans only the type and format of the specified number of rows.Setting the number of rows is more efficient because data is read from only thespecified number of rows rather than the entire file.

Setting the SS_SCAN environment variable changes the default value of theSCANTYPE statement in PROC ACCESS.

ACCESS Procedure: WKn SpecificsChapter 14, “The ACCESS Procedure for PC Files,” on page 191 contains general

information about this feature. This section provides WKn-specific syntax for theACCESS procedure and describes ACCESS procedure data conversions.

ACCESS Procedure Syntax for WKn FilesTo create an access descriptor, use the DBMS=WKn option and these

database-description statements:� GETNAMES=� PATH=� RANGE=� SCANTYPE=

Page 245: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � ACCESS Procedure Syntax for WKn Files 237

� SKIPROWS=� WORKSHEET=

These database-description statements supply WKn-specific information to SAS andmust immediately follow the CREATE or UPDATE statement that specifies the accessdescriptor to be created or updated. In addition to the database-description statements,you can use editing statements when you create an access descriptor. These editingstatements must follow the database-description statements.

Database-description statements are required only when you create accessdescriptors. Because WKn information is stored in an access descriptor, you do not needto repeat this information when you create view descriptors.

The SAS/ACCESS interface to WKn uses the following procedure statements:

PROC ACCESS DBMS=WK1|WK3|WK4;CREATE libref.member-name.ACCESS | VIEW;UPDATE libref.member-name.ACCESS | VIEW;

PATH= ’path-and-filename<.WK1 | .WK3 | .WK4>’| <’>filename<’>| fileref;GETNAMES <=> YES | NO | Y | N;RANGE <=><’>range-name<’>| ’range-address’;SCANTYPE <=> YES | NO | Y | N | <number-of-rows>;SKIPROWS <=> number-of-rows-to-skip;WORKSHEET <=> worksheet-letter| <’>worksheet-name<’>;ASSIGN <=> YES | NO | Y | N;DROP <’>column-identifier-1<’> <…<’>column-identifier-n<’>>;FORMAT <’>column-identifier-1<’> <=> SAS-format-name-1

<…<’>column-identifier-n<’><=> SAS-format-name-n>;LIST <ALL | VIEW | <’>column-identifier<’>>;MIXED <=> YES | NO | Y | N;RENAME <’>column-identifier-1<’> <=> SAS-variable-name-1

<…<’>column-identifier-n<’> <=> SAS-variable-name-n>;RESET ALL | <’>column-identifier-1<’> <…<’>column-identifier-n<’>>;SELECT ALL | <’>column-identifier-1<’> <…<’>column-identifier-n<’>>;SUBSET selection-criteria;TYPE column-identifier-1<=> C | N <…column-identifier-n <=> C | N>;UNIQUE <=> YES | NO | Y | N ;

RUN ;

The QUIT statement is also available in PROC ACCESS. However, it causes theprocedure to terminate. QUIT is used most often in the interactive line andnoninteractive modes to exit the procedure without exiting SAS.

The following list provides detailed information about the WKn-specific statements:

GETNAMES <=> YES | NO | Y | N;determines whether SAS variable names are generated from column names in thefirst row of the Lotus range when an access descriptor is created. When youupdate a descriptor, you are not allowed to specify the GETNAMES statement.

The GETNAMES statement is optional. If you omit it, the default valueGETNAMES=NO is used, and the SAS/ACCESS interface generates the SASvariable names VAR0, VAR1, VAR2, and so on. If you specify GETNAMES=YES,the SAS variable names are generated from the column names in the first row ofthe Lotus range. GETNAMES=YES also sets the default value of SKIPROWS to 1.

Page 246: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

238 ACCESS Procedure Syntax for WKn Files � Chapter 16

You can change the default value from NO to YES by setting the SS_NAMESenvironment variable. For more information, see “Setting Environment Variablesfor WKn Files” on page 242.

The GETNAMES statement is a database-description statement. It must followthe CREATE statement and precede any editing statements when you create adescriptor.

RANGE <=> <’>range-name<’> | ’range-address’;subsets a specified section of a WKn file worksheet. The range-name is the namethat is assigned to a range address within the worksheet. Range names can be upto 15 characters long and are not case sensitive. If you specify a range name, thename must have been previously defined in the WKn file. The range-address isidentified by the top-left cell that begins the range and the bottom-right cell thatends the range within the WKn worksheet file. The beginning and ending cells areseparated by two periods. For example, the range address C9..F12 indicates a cellrange that begins at Cell C9, ends at Cell F12, and includes all cells in between.

The RANGE statement is optional. If you omit RANGE, the entire worksheet isaccessed as the default range.

The RANGE is a database-description statement. It must follow the CREATEstatement and precede any editing statements when you create a descriptor.

SCANTYPE <=> YES | NO | Y | N | <number-of-rows>;finds the most common Lotus 1-2-3 format for each column in a specified numberof rows in a WKn worksheet to generate the SAS format. By default, SAS variableformats are generated from the Lotus 1-2-3 formats that are found in the first rowof the worksheet or in the range of the worksheet (if you specified a range).

The SCANTYPE statement is optional, and its default value is NO. If you specifyYES, the ACCESS procedure scans the Lotus 1-2-3 formats of all the rows in eachcolumn of the range and uses the most common format to generate the defaultSAS format for each column. If you specify a number of rows, PROC ACCESSscans only the specified number of rows and returns the most common format.

If you specify the SKIPROWS statement, the ACCESS procedure skips thespecified rows and starts scanning the Lotus 1-2-3 format from the next row. Forexample, if you specify SKIPROWS=3, PROC ACCESS skips the first three rowsand begins scanning the formats on the fourth row.

You can change the default value to YES by setting the SS_SCAN environmentvariable. For more information, see “Setting Environment Variables for WKnFiles” on page 242.

Specifying SCANTYPE=0 is equivalent to specifying SCANTYPE=NO.The SCANTYPE statement is a database-description statement. It must follow

the CREATE statement and precede any editing statements when you create adescriptor.

SKIPROWS <=> number-of-rows-to-skip;specifies the number of rows, beginning at the top of the range in the WKn file, toignore when you are reading data from the WKn file. The default value forSKIPROWS is 0. The skipped (or ignored) rows often contain information such ascolumn labels or names, or underscores rather than input data.

If GETNAMES=YES, the default value of SKIPROWS automatically changes to1. The first row of data and formats after SKIPROWS in a range is used togenerate the SAS variable types and formats. However, you can use theSCANTYPE statement to scan the formats of specified rows and use the mostcommon type and format to generate the default SAS variable types and formats.

The SKIPROWS statement is a database-description statement. It must followthe CREATE statement and precede any editing statements when you create adescriptor.

Page 247: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � ACCESS Procedure Data Conversions for WKn Files 239

WORKSHEET <=> worksheet-letter | <’>worksheet-name<’>;identifies a particular worksheet when you are reading from a WKn file thatcontains more than one worksheet. You can specify a worksheet name or aworksheet letter using the WORKSHEET statement. Worksheet names can be upto 15 characters long and are not case sensitive. A worksheet letter is a one- ortwo-letter alpha character. For WK1 files, there is only one worksheet letter:worksheet A. For WK3 and WK4 files, there can be up to 256 different worksheetletters: worksheet A through worksheet Z and worksheet AA through worksheetIV. The default value is A. For example, specifying WORKSHEET=B identifiesworksheet B from a group of worksheets.

The WORKSHEET statement is optional. The WORKSHEET statement is adatabase-description statement. It must follow the CREATE statement andprecede any editing statements when you create an access descriptor.

ACCESS Procedure Data Conversions for WKn Files

Use PROC ACCESS to define descriptors that identify spreadsheet data and theconversions necessary to use that data in SAS programs. The Lotus label data type isformatted as a SAS character type, and the 1-2-3 number data type is formatted as aSAS numeric type.

Fonts, attributes, and colors in the WKn files are not read into the SAS data sets.However, the ACCESS procedure supports most of the WKn number formats andautomatically converts them to the corresponding SAS formats. Any WKn data stringslonger than 200 characters are truncated while being converted into SAS data sets, andany SAS data file created from WKn files can contain only up to 256 variables and8,192 observations.

The following table shows the default SAS System variable formats that the ACCESSprocedure assigns to each type of WKn file numeric data include date and time values.

Table 16.5 Default SAS System Variable Formats for WKn File Data

WKn File Data SAS Variable Format

Data Type Data FormatColumnWidth Decimal Number Type Format

Char** * w Char $w.

Numeric*** Default w Num BESTw.

Numeric AUTOMATIC w d Num BESTw.

Numeric FIXED w d Num w.d

Numeric SCIENTIFIC w d Num Ew.d

Numeric CURRENCY w d Num DOLLARw.d

Numeric PERCENT w d Num PERCENTw.d

Numeric COMMA w d Num COMMAw.d

Numeric GENERAL w Num BESTw.

Numeric DD-MON-YY w. Num DATE7.

Numeric DD-MON w Num DATE7.

Numeric MON-YY w Num MONYY5.

Page 248: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

240 DBLOAD Procedure: WKn Specifics � Chapter 16

WKn File Data SAS Variable Format

Data Type Data FormatColumnWidth Decimal Number Type Format

Numeric MM-DD-YY w Num MMDDYY8.

Numeric MM-DD w Num MMDDYY8.

Numeric HH-MM-SS w Num TIME8.

Numeric HH-MM-SS w Num TIME5.

Numeric HH-MM-SS AM/PM w Num TIME12.

Numeric HH-MM AM/PM w Num TIME9.

* Any valid Lotus 1–2–3 data format.** Label or formula string data.*** Number or formula data.

If WKn file fall outside of the valid SAS data ranges, you receive an error message inthe SAS log when you try to access the data.

The SAS/ACCESS interface does not fully support the Lotus1–2–3 hidden and textformats. WKn data in hidden format are displayed in SAS data sets; however, you candrop the hidden column when you are creating the access descriptor. If you want todisplay the formula in the text format, add a label prefix character to indicate that theformula entry is a label. Otherwise, the results of the formula are displayed.

DBLOAD Procedure: WKn SpecificsChapter 15, “The DBLOAD Procedure for PC Files,” on page 215 contains general

information about this feature. This section provides WKn-specific syntax for theDBLOAD procedure and describes DBLOAD procedure data conversions.

DBLOAD Procedure Syntax for WKn FilesTo create and load a WKn table, the SAS/ACCESS interface to WKn uses the

following statements:

PROC DBLOAD <DBMS=WK1|WK3|WK4><DATA= < libref.>SAS-data-set>;

PATH=’path-and-filename<.WK1|.WK3|.WK4>’ | <’>filename< ’> | fileref;PUTNAMES <=> YES | NO | Y | N;ACCDESC= <libref.>access-descriptor;DELETE variable-identifier-1 <…variable-identifier-n>;ERRLIMIT= error-limit;FORMAT SAS-variable-name-1 SAS-format-1 <=>

<…SAS-variable-name-n SAS-format-n>;LABEL;LIMIT= load-limit ;LIST <ALL | COLUMNS | FIELDS | variable-identifier>;RENAME variable-identifier-1 <=> <’>column-name-1<’>

<…variable-identifier-n = <’>column-name-n<’>>;

Page 249: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � DBLOAD Procedure Data Conversions for WKn Files 241

RESET ALL | variable-identifier-1 <…variable-identifier-n>;<…column-identifier-n <=> C | N>;

WHERE SAS-where-expression;LOAD;

RUN;

The QUIT statement is also available in PROC DBLOAD. However, it causes theprocedure to terminate. QUIT is used most often in the interactive line andnoninteractive modes to exit the procedure without exiting SAS.

This list provides detailed information about the WKn-specific statements:

PUTNAMES <=> YES | NO | Y | N;writes column names to the first row of the new WKn file. The column names canbe default SAS variable names or, if you specify the LABEL statement, SASvariable labels. You can modify the column names using the RENAME statement.

The PUTNAMES statement is optional. If you omit PUTNAMES, data is readfrom the data set and written to the WKn file beginning in the first row of theWKn file, and no column names are written to the file.

You can change the default value to YES by setting the SS_NAMESenvironment variable. For more information, see “Setting Environment Variablesfor XLS Files” on page 235.

FORMAT SAS-variable-name-1 SAS-format-1 <SAS-variable-name-n SAS-format-n>;assigns a temporary format to a SAS variable in the input SAS data set. Thisformat temporarily overrides any other format for the variable. The assignmentlasts only for the duration of the procedure. Assign formats to as many variablesas you want in one FORMAT statement.

Use FORMAT when you want to change the format, column width, or thenumber of decimal digits for columns being loaded into the PC file. For example, ifyou change the SAS variable format 12.1 to DOLLAR15.2, the column format ofthe loaded data changes from a fixed numeric format with a column width of 12and one decimal digit to a currency format with a column width of 15 and twodecimal digits.

DBLOAD Procedure Data Conversions for WKn FilesThis section explains how SAS data is read into Lotus 1-2-3 data when a table is

loaded. In this conversion, the SAS character data type is converted into the Lotus 1-2-3label type, and the SAS numeric type is converted into the Lotus 1-2-3 number type.

The SAS/ACCESS interface automatically converts SAS formats to the same orassociated Lotus 1-2-3 formats and column widths. However, you can temporarilyassign other formats and column widths to SAS variables by using the FORMATstatement. The following table shows SAS variable types and formats and the WKndata types, formats, and column widths that you can assign them to.

Note: The FORMAT statement in PROC DBLOAD changes only the format of SASvariables while you are creating and loading the WKn files. When the procedure iscompleted, the formats of SAS variables return to their original settings. �

Page 250: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

242 Setting Environment Variables for WKn Files � Chapter 16

Table 16.6 Converting SAS Variable Formats to WKn File Data

SAS Variable Format WKn File Data

Type Data Format Data Type Column FormatColumnWidth Number

Char $w. LABEL DEFAULT w

Char $CHARw. LABEL DEFAULT w

Num w.d NUMBER FIXED w d

Num Fw.d NUMBER FIXED w d

Num Ew.d NUMBER SCIENTIFIC w d

Num DOLLARw.d NUMBER CURRENCY w d

Num PERCENTw.d NUMBER PERCENT w d

Num COMMAw.d NUMBER COMMA w d

Num BESTw. NUMBER DEFAULT w

Num BESTw. NUMBER GENERAL w

Num DATE5. NUMBER DD-MON 7

Num DATE7. NUMBER DD-MON-YY 10

Num MONYY5. NUMBER MON-YY 7

Num MMDDYY5. NUMBER MM-DD 6

Num MMDDYY8. NUMBER MM-DD-YY 9

Num TIME5. NUMBER HH-MM-SS 6

Num TIME8. NUMBER HH-MM-SS 9

Num TIME9. NUMBER HH-MM AM/PM 9

Num TIME12. NUMBER HH-MM-SS AM/PM

12

Setting Environment Variables for WKn FilesYou can change the default behavior of the SAS/ACCESS interface by setting

environment variables in your SAS configuration file. You can set four SAS/ACCESSenvironment variables: SS_MISS NULLS, SS_MIXED, SS_NAMES, and SS_SCAN.Setting these variables in your SAS configuration file changes how the interface worksby default.

The configuration file omits these three environment variables by default, whichmeans their default values are NO.

SS_MISS NULLSBy default, the DBLOAD procedure loads Lotus @NA cell values for missingvalues. Use this option to specify a null cell value instead. If set, missing values ina SAS data set are displayed as blanks in the Lotus 1-2-3 table.

SS_MIXED YES | NOYES allows both Lotus 1-2-3 numeric and character data in a column to bedisplayed as SAS character data. The Lotus 1-2-3 numeric data is converted to its

Page 251: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � ACCESS Procedure Syntax for DBF Files 243

character representation when its corresponding SAS variable type is defined ascharacter.

NO does not convert Lotus 1-2-3 numeric data in a column into SAS characterdata. Lotus 1-2-3 numeric data is read in as SAS missing values when itscorresponding SAS variable type is defined as character. NO is the default.

Setting the SS_MIXED environment variable changes the default value of theMIXED statement in PROC ACCESS.

SS_NAMES YES | NOYES in PROC ACCESS generates SAS variable names from column names in thefirst row of the worksheet or the specified range of the worksheet and reads datafrom the second row. YES in PROC DBLOAD writes column names using SASvariable names or SAS variable labels to the first row of the new WKn file, timereads data from the data set and writes it to the WKn file beginning with thesecond row.

NO in PROC ACCESS generates the SAS variable names VAR0, VAR1, VAR2,and so on, and reads data from the first row of the worksheet or specified range.NO in PROC DBLOAD reads the data from the data set and writes it to the WKnfile beginning with the first row. NO is the default.

Setting the SS_NAMES environment variable changes the default value of theGETNAMES statement in PROC ACCESS and the PUTNAMES statement inPROC DBLOAD.

SS_SCAN YES | NO | number-of-rowsYES scans the data type and format of rows in a worksheet or specified rangeafter skipping the number of rows specified in the SKIPROWS statement.SS_SCAN finds the most common Lotus 1-2-3 data type and format in order togenerate the default SAS data type and format. If a number of rows is specified,SAS/ACCESS scans only the data type and format from these rows.

NO uses the type and format of the first row in a worksheet or specified range,after skipping the number of rows specified in SKIPROWS, to generate the defaultSAS data type and format. NO is the default.

Number-of-rows scans only the type and format of the specified number of rows.Setting the number of rows is more efficient because data is read from only thespecified number of rows rather than the entire file.

Setting the SS_SCAN environment variable changes the default value of theSCANTYPE statement in PROC ACCESS.

ACCESS Procedure: DBF Specifics (Windows)

Chapter 14, “The ACCESS Procedure for PC Files,” on page 191 contains generalinformation about this feature. This section provides DBF-specific syntax for theACCESS procedure and describes ACCESS procedure data conversions.

ACCESS Procedure Syntax for DBF FilesTo create an access descriptor, use the DBMS=DBF option and the

database-description statement PATH=. This PATH= statement supplies DBF-specificinformation to SAS and must immediately follow the CREATE statement. In additionto the database-description statement, you can use optional editing statements whenyou create an access descriptor. These editing statements must follow thedatabase-description statement.

Page 252: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

244 ACCESS Procedure Syntax for DBF Files � Chapter 16

The database-description statement is required only when you create accessdescriptors. Because the DBF information is stored in an access descriptor, you do notneed to repeat this information when you create view descriptors.

Note: The SAS/ACCESS interface cannot read DBF files that are encrypted.Therefore, you cannot define an access descriptor based on these files. �

The SAS/ACCESS interface to DBF supports the following procedure statements:

PROC ACCESS options;

CREATE libref.name.ACCESS|VIEW;

UPDATE libref.name.ACCESS|VIEW;

PATH= ’path-and-filename<.DBF>’|<’>filename<’>| fileref;

ASSIGN | AN <=> YES | NO;

DROP <’>column-identifier-1<’> <…<’>column-identifier-n<’>>;

FORMAT <’>column-identifier-1<’><=>SAS-format-name-1<…<’>column-identifier-n<’> <=>SAS-format-name-n>;

LIST <ALL | VIEW | <’>column-identifier<’>>;

RENAME <’>column-identifier-1<’><=>SAS-variable-name-1<…<’>column-identifier-n<’><=>SAS-variable-name-n>;

RESET ALL | <’>column-identifier-1<’> <…<’>column-identifier-n<’>>;

SELECT ALL | <’>column-identifier-1< ’> <…<’>column-identifier-n<’>>;

SUBSET selection criteria;

UNIQUE <=> YES | NO;

RUN;

The QUIT statement is also available in PROC ACCESS. However, it causes theprocedure to terminate. QUIT is used most often in the interactive line andnon-interactive modes to exit the procedure without exiting SAS.

This example creates an access descriptor and a view descriptor based on DBF filedata.

options linesize=80;libname dbfliba ’SAS-data-library’;libname dbflibv ’SAS-data-library’;

proc access dbms=dbf;/* create access descriptor */

create adlib.custs.access;path=’c:\dbfiles\dbcusts.dbf’;assign=yes;rename customer = custnum;format firstorder date9.;list all;

/* create usacust view */create vlib.usacust.view;select customer state zipcode name

firstorder;run;

Page 253: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � DBLOAD Procedure Syntax for DBF Files 245

ACCESS Procedure Data Conversions for DBF FilesThe table below shows the default SAS variable formats that the ACCESS procedure

assigns to each DBF file data type. If DBF file data falls outside of the valid SAS dataranges, you get an error message in the SAS log when you try to read the data.

Table 16.7 Default SAS Variable Formats for DBF File Data Types

DBF File Data Type SAS Variable Format

Character(n) $n. (n <= 200)

$200. (n > 200)

Numeric(N,n) (N,n)

Float(N,n)* (N,n)

Date MMDDYY8.

Logical $1.

* This data type applies to dBASE V and later. Check with other software products’ documentationto determine whether this data type applies.

DBLOAD Procedure: DBF Specifics (Windows)

Chapter 15, “The DBLOAD Procedure for PC Files,” on page 215 contains generalinformation about this feature. This section provides DBF-specific syntax for theDBLOAD procedure and describes DBLOAD procedure data conversions .

DBLOAD Procedure Syntax for DBF FilesTo create and load a DBF table, SAS/ACCESS Interface to PC Files uses the

following statements:

PROC DBLOAD <DBMS=DBF> <DATA=<libref.>SAS-data-set>;

PATH=’path-and-filename<.DBF>’ | <’>filename<’>|fileref;

VERSION= dBASE-product-number;

ACCDESC=<libref.>access-descriptor;

DELETE variable-identifier-1 <…variable-identifier-n>;

ERRLIMIT= error-limit;

LABEL;

LIMIT= load-limit;

LIST <ALL | FIELDS | variable-identifier>;

LOAD;

RENAME variable-identifier-1= <’>database-field-name-1<’><…variable-identifier-n = <’>database-field-name-n<’>>;

RESET ALL | variable-identifier-1 <…variable-identifier-n>;

TYPE variable-identifier-1=’database-field-type-1’<…variable-identifier-n = ’database-field-type-n’>;

Page 254: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

246 DBLOAD Procedure Syntax for DBF Files � Chapter 16

WHERE SAS-where-expression;

RUN;

The QUIT statement is also available in PROC DBLOAD. However, it causes theprocedure to terminate. QUIT is used most often in the interactive line andnon-interactive modes to exit the procedure without exiting SAS.

The following list provides detailed information about the DBF-specific statements:

VERSION= dBASE-product-numberspecifies the number of the dBASE product you are using, such as dBASE IV. ThedBASE-product-number argument can be one of the following values: II, III, IIIP,IV, V, 2, 3, 3P, 4, and 5. The statement’s default value is V.

Specify VERSION= before the TYPE statement in order to get the correct datatypes for your new DBF table.

TYPE variable-identifier-1 = ’database-field-name-1’<… variable-identifier-n = ’database-field-name-n’>

specifies a DBF file data type, which is based on the SAS variable format. Thedatabase field name must be enclosed in quotation marks.

This example defines the data types for several database fields. You can specify thelength of the data type.

proc dbload dbms=dbf data=employee;path=’c:\sasdemo\employee.dbf’;rename firstname = fname;type empid = ’numeric(6)’

hiredate = ’date’salary = ’numeric(10,2)’jobcode = ’numeric(5)’;

run;

This next example creates a new DBF table, Exchange.Dbf, from the data fileDLib.RateOfex. An access descriptor DbFliba.Exchange is also created based on thenew table. You must be granted the appropriate privileges to create new DBF tables.

libname dbfliba ’SAS-data-library’;libname dbflibv ’SAS-data-library’;

proc dbload dbms=dbf data=dlib.rateofex;path=’c:\dbfiles\sasdemo\exchange.dbf’;accdesc=adlib.exchange;rename fgnindol=fgnindolar 4=dolrsinfgn;type country=’char(25)’;load;

run;

Page 255: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � ACCESS Procedure: DIF Specifics 247

DBLOAD Procedure Data Conversions for DBF FilesThe following table shows the default DBF file data types that the DBLOAD

procedure assigns to each SAS variable format.

Table 16.8 Default DBF File Data Types for SAS Variable Formats

SAS Variable Formats DBF File Data Types

$w. CHAR(n)

w. NUMERIC

w.d. NUMERIC

datetimew.d DATE

datew. DATE

ew. FLOAT

binaryw. NUMERIC

Setting Environment Variables for DBF FilesMissing numeric values are filled in with nines by default. The DBFMISCH

environment variable is used to change the default by specifying the character that theinterface to DBF files uses to fill missing numeric fields. For example, if you try towrite a SAS file with a missing numeric variable to a DBF file, the corresponding fieldin the DBF file would be filled with the DBFMISCH character. Conversely, any numericor float field in a DBF file that is filled with the DBFMISCH character is treated asmissing when read by SAS.

You set the DBMISCH environment variable in the SAS configuration file using thefollowing syntax:

-set DBFMISCH value

Valid values are

<any single character>Type in any single character. For example, to fill missing numeric valueswith the zero character (0), enter -set DBFMISCH 0.

NULLSTo replace missing numeric values with binary zeros, enter -set DBFMISCH NULLS.

BLANKSTo replace missing numeric values with blanks, enter -set DBFMISCH BLANKS.

ACCESS Procedure: DIF Specifics

Chapter 14, “The ACCESS Procedure for PC Files,” on page 191 contains generalinformation about this feature. This section provides DIF-specific syntax for theACCESS procedure and describes ACCESS procedure data conversions.

Page 256: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

248 ACCESS Procedure Syntax for DIF Files � Chapter 16

ACCESS Procedure Syntax for DIF FilesTo create an access descriptor, use the DBMS=DIF option and the

database-description statements PATH=, DIFLABEL, and SKIPROWS. Thesestatements supply DIF-specific information to SAS, and must immediately follow theCREATE statement. In addition to the database-description statements, you can useoptional editing statements when you create an access descriptor. These editingstatements must follow the database-description statements.

Database-description statements are required only when you create accessdescriptors. Because the DIF information is stored in an access descriptor, you do notneed to repeat this information when you create view descriptors.

The SAS/ACCESS interface to DIF uses the following procedure statements:

PROC ACCESS options;CREATE <libref.>member-name.ACCESS | VIEW;

UPDATE <libref.>member-name.ACCESS | VIEW;

PATH= ’path-and-filename<.DIF>’ | <’>filename< ’>| fileref;DIFLABEL;SKIPROWS <=> number-of-rows-to-skip;ASSIGN | AN <=> YES | NO;DROP <’>column-identifier-1<’><…<’>column-identifier-n< ’>>;FORMAT <’>column-identifier-1<’><=>SAS-format-name-1

<…<’>column-identifier-n<’><=> SAS-format-name-n>;LIST <ALL | VIEW | <’>column-identifier<’>>;RENAME <’>column-identifier-1<’> <=> SAS-variable-name-1

<…<’>column-identifier-n<’> <=> SAS-variable-name-n>;RESET ALL | <’>column-identifier-1<’><…<’>column-identifier-n<’>>;SELECT ALL | <’>column-identifier-1< ’> <…<’>column-identifier-n<’>>;SUBSET selection criteria ;TYPE <’>column-identifier-1<’><=> C | N

<…column-identifier-n <=> C | N>;UNIQUE <=> YES | NO;

RUN;

The QUIT statement is also available in PROC ACCESS. However, it causes theprocedure to terminate. QUIT is used most often in the interactive line andnoninteractive modes to exit the procedure without exiting SAS.

The following list provides detailed information about the DIF-specific statements:

DIFLABELindicates whether variable names are generated from the first row of the columns.If you omit this statement, variable names that are generated are based on thecolumns’ placement in the first row. That is, SAS labels each column as COL0,COL1, COL2, and so on. These labels become the names of SAS variables in theaccess descriptor.

If you specify DIFLABEL, the ACCESS procedure reads column labels from thefirst row of the DIF file and uses them as the SAS variable names in the accessdescriptor. You provide the DIF file column labels; they are not the letters (for

Page 257: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � ACCESS Procedure Syntax for DIF Files 249

example, A, B, and so on) that identify the columns in a worksheet. If you specifyDIFLABEL, the SKIPROWS statement automatically changes to 1.

Always specify DIFLABEL after the PATH= statement and before any editingstatements. When you update a descriptor, you are not allowed to specify theDIFLABEL statement.

This example creates an access descriptor and a view descriptor based on DIFfile data.

options linesize=80;libname difdliba ’SAS-data-library’;libname diflibv ’SAS-data-library’;

proc access dbms=dif;/* create access descriptor */

create difliba.custs.access;path=’c:\difiles\dbcusts.dif’;diflabel;skiprows=2;assign=yes;rename customer = custnum;format firstorder date9.;list all;

/* create usacust view */create diflibv.usacust.view;select customer state zipcode name

firstorder;run;

SKIPROWS <=> number-of-rows-to-skip;specifies the number of rows, beginning at the top of the DIF file, to ignore whenyou read data from the file. The default value for SKIPROWS is 0. The skipped(or ignored) rows often contain information such as column labels or names, orunderscores rather than input data.

If you specify the DIFLABEL statement, the default value of SKIPROWSautomatically changes to 1. The SKIPROWS statement should always follow thePATH= statement and precede any editing statements when you are creating adescriptor. The first row of data after SKIPROWS is used to generate the SASvariable types and formats. If there is no data in the first row of a column afterSKIPROWS, the data in the rest of the column is assumed to be character data,even if the data in the next row is numeric.

By default, any data value in a column that does not match the type is treatedas a missing value. However, if you set the DIFNUMS environment variable toYES in your SAS configuration file, any numeric data values in a character columnare converted to the character representation of the number and are not treated asmissing values. Add the following line to your SAS configuration file to set theDIFNUMS environment variable to YES:

-SET DIFNUMS YES

The default for the DIFNUMS environment variable is NO. Refer to the SASdocumentation for your operating environment for more information aboutenvironment variables.

You can change the column type from the type that SAS/ACCESS determineswhen you create an access descriptor.

Page 258: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

250 ACCESS Procedure Data Conversions for DIF Files � Chapter 16

ACCESS Procedure Data Conversions for DIF FilesThe following table shows the default SAS variable formats that the ACCESS

procedure assigns to each type of DIF file data. DIF file numeric data includes date andtime values.

Table 16.9 Default SAS Variable Formats for DIF File Data

DIF File Data SAS Variable Format

C (Character) $20.

N (Numeric) 15.2

If DIF file data falls outside of the valid SAS data ranges, you get an error messagein the SAS log when you try to read the data.

Datetime Conversions in the ACCESS ProcedureWhen you create an access descriptor, SAS cannot distinguish a Lotus datetime value

from other numeric data. SAS stores the Lotus datetime value as a number anddisplays it like other Lotus numeric data by using the SAS variable format 15.2 (thedefault format for this interface).

To convert a Lotus datetime value to a SAS datetime value, you must specify a SASdatetime format in the access descriptor. A Lotus datetime value is a number thatrepresents the number of days between January 1, 1900, and a specified date; changingthe default SAS format (15.2) to a datetime format in the descriptor causes the Lotusvalue to be converted to an equivalent SAS datetime value based on January 1, 1960.In other words, the Lotus numeric value for January 1, 1960 (which is 21,916) isconverted to the equivalent SAS representation of January 1, 1960 (which is 0) only if aSAS datetime format is stored in the descriptor for that column. Otherwise, the Lotusvalue of 21,916 is treated as a SAS numeric value of 21,916.

The following table shows how SAS uses a Lotus datetime value to convert to a SASdatetime format.

Table 16.10 Value-to-Format Conversions

For a SAS format SAS uses

date integer portion of the Lotus number

time decimal portion of the Lotus number

date-and-time integer and decimal portion of the Lotus number

DBLOAD Procedure: DIF SpecificsChapter 15, “The DBLOAD Procedure for PC Files,” on page 215 contains general

information about this feature. This section provides DIF-specific syntax for theDBLOAD procedure and describes DBLOAD procedure datetime conversions.

Page 259: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � DBLOAD Procedure Syntax for DIF Files 251

DBLOAD Procedure Syntax for DIF FilesTo create and load a DIF table, SAS/ACCESS Interface to PC Files uses the following

statements.

PROC DBLOAD DBMS=DIF <DATA=<libref.>SAS-data-set>;PATH=’path-and-filename<.DIF>’ | <’>filename< ’>| fileref;DIFLABEL;ACCDESC=<libref.>access-descriptor;DELETE variable-identifier-1 <…variable-identifier-n>;ERRLIMIT=error-limit;FORMAT SAS-variable-name-1 SAS-format-1 <…SAS-variable-name-n

SAS-format-n>;LABEL;LIMIT=load-limit;LIST <ALL | COLUMNS | FIELDS | variable-identifier>;LOAD;RENAME variable-identifier-1= <’>column-name-1<’>

<…variable-identifier-n=<’>column-name-n<’>>;RESET ALL | variable-identifier-1 <…variable-identifier-n>;WHERE SAS-where-expression;

RUN;

The QUIT statement is also available in PROC DBLOAD. However, it causes theprocedure to terminate. QUIT is used most often in the interactive line andnoninteractive modes to exit the procedure without exiting SAS.

The following list provides detailed information about the DIF-specific statements:

DIFLABELwrites column labels to the first row of the new DIF file and follows the columnlabels with a blank row. The column labels can be default SAS variable names or,if you specify the LABEL statement, SAS labels. You can modify the column labelsusing the RENAME statement.

If this statement is omitted, data is read from the data set and written to theDIF file beginning in the first row of the DIF file, and no column labels are writtento the file.

FORMAT SAS-variable-name-1 SAS-format-1< …SAS-variable-name-nsas-format-n>;

assigns a temporary format to a SAS variable in the input SAS data set. Thisformat temporarily overrides any other format for the variable. The assignmentlasts only for the duration of the procedure. Assign formats to as many variablesas you want in one FORMAT statement.

Use FORMAT when you want to change the format, column width, or thenumber of decimal digits for columns being loaded into the PC file. For example, ifyou change the SAS variable format 12.1 to DOLLAR15.2, the column format ofthe loaded data changes from a fixed numeric format with a column width of 12and one decimal digit to a currency format with a column width of 15 and twodecimal digits.

This example creates a new DIF table, Exchange.dif, from the data file Dlib.RateOfex.An access descriptor AdLib.Exchange is also created based on the new DIF table. Youmust be granted the appropriate privileges in order to create new DIF files.

Page 260: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

252 Datetime Conversions in the DBLOAD Procedure � Chapter 16

libname difdliba ’SAS-data-library’;libname diflibv ’SAS-data-library’;

proc dbload dbms=dif data=dlib.rateofex;accdesc=adlib.exchange;path=’c:\difiles\sasdemo\exchange.dif’;diflabel;rename fgnindol=fgnindolar 4=dolrsinfgn;load;

run;

Datetime Conversions in the DBLOAD ProcedureIf a SAS variable is specified with a date, time, or datetime format in the FORMAT

statement, the interface view engine converts that datetime value into the equivalentLotus datetime value when the new DIF file is created. However, the DIF file has noway of relating this formatting information to Lotus products. Therefore, when you loadthe DIF file into a Lotus 1-2-3 worksheet, the datetime values are represented asnumbers. You should assign (from within Lotus) a Lotus datetime format to anydatetime column that you load from a DIF file.

If a SAS variable represents a date, time, or datetime value, but it has not beenassigned a SAS datetime format — the SAS datetime value is represented as anumber — the number is not converted into an equivalent Lotus datetime value in theDIF file. Rather, the number is written to the new DIF file as is. Because SAS datesare based on January 1, 1960, and Lotus dates are based on January 1, 1900, if youassign a Lotus datetime format to an unconverted Lotus column, the datetime values inthat column are inaccurate.

Use the DBLOAD FORMAT statement to maintain a SAS variable format in theinput data set yet change it only while the DBLOAD procedure is in progress. You canuse this statement to assign a temporary format to a SAS variable for the duration ofthe procedure without affecting how SAS stores the variable.

For example, if the SAS format for the BirthDat variable in the MyData.SasEmpsdata set is left at the default 15.2 format, you can specify the FORMAT statement tochange the variable’s format to DATE7. while you are creating and loading the DIF file.When you load the DIF file into a Lotus 1-2-3 worksheet, you can specify an equivalentLotus date format. When the DBLOAD procedure has completed, the SAS format forthe BirthDat variable reverts to the 15.2 format.

You can specify the FORMAT statement in the PROC DBLOAD statement when youinvoke the procedure using any of the methods of processing.

Note: There are certain display restrictions on the SAS datetime values that areloaded into Lotus 1-2-3 worksheets through DIF files. If you load a SAS variable with aDATETIMEw.d format into a DIF file, Lotus stores the number with both integer anddecimal portions. However, when you load the DIF file into a Lotus 1-2-3 worksheetand specify a format for the column, you can specify only a date format (that uses theinteger portion) or time format (that uses the decimal portion) for that column, not bothat the same time. �

Page 261: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

File-Specific Reference � DIF File Data Types 253

Setting Environment Variables for DIF Files

DIF File Data TypesBy default, any data value in a column that does not match the type is treated as a

missing value. However, if you set the DIFNUMS environment variable to YES in yourSAS configuration file, any numeric data values in a character column are converted tothe character representation of the number and are not treated as missing values. Addthe following line to your SAS configuration file to set the DIFNUMS environmentvariable to YES:

-SET DIFNUMS YES

The default for the DIFNUMS environment variable is NO. Refer to the SASCompanion for your operating system for more information about environmentvariables.

You can change the column type from the type that SAS/ACCESS determines whenyou create an access descriptor.

Page 262: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

254

Page 263: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

255

P A R T6

Appendixes

Appendix 1. . . . . . . . .The DBF and DIF Procedures 257

Appendix 2. . . . . . . . .Recommended Reading 263

Page 264: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

256

Page 265: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

257

A P P E N D I X

1The DBF and DIF Procedures

Introduction to the DBF and DIF Procedures 257Overview: DBF and DIF Procedures 257

Introduction to the DBF and DIF Procedures

Overview: DBF and DIF ProceduresThe DBF and DIF procedures give UNIX, Microsoft Windows, and z/OS users an

alternative way to access DBF and DIF files. Instead of creating access descriptors andview descriptors, you can convert these PC file types to SAS data sets, or vice versa.

Under UNIX and Microsoft Windows operating environments, you can use the DBFand DIF procedures to convert a DBF or DIF file to a SAS data set or to convert a SASdata set to a DBF or DIF file. Under z/OS, only the DBF procedure is available.

See “Methods for Accessing PC Files Data” on page 3 for the other methods foraccessing data in PC file formats under Open VMS, UNIX, and Microsoft Windowoperating environments.

The DBF Procedure

Converts a dBASE file to SAS data set or a SAS data set to a dBASE file.

SyntaxPROC DBF options;

PROC DBF Options

DB2|DB3|DB4|DB5=fileref | filenamespecifies the fileref or filename of a DBF file. The DBn option must correspond to theversion of dBASE with which the DBF file is compatible. You specify the version withthe DBn option, where n is the version number and can have a value of 2, 3, 4, or 5.

Page 266: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

258 The DBF Procedure � Appendix 1

If you specify a fileref, the FILENAME statement that you used to define it mustspecify the filename plus a .dbf extension; for example, filename myref ’/my_dir/myfile.dbf’.

If you specify a filename instead of a fileref, you can specify only the name itself(omitting the .dbf extension), and the file must be in the current directory. Forexample, this PROC DBF statement creates the EMP.DBF file (with the name inuppercase) from the MyLib.Employee data set:

proc dbf db5=emp data=mylib.employee;

You cannot specify emp.dbf or a full pathname (proc dbf db5=’/my/unix_directory/emp.dbf’).

The DBn= option is required.

DATA=<libref.>membernames the input SAS data set. Use this option if you are creating a DBF file from aSAS data set. If you use the DATA= option, do not use the OUT= option. If you omitthe DATA= option, SAS software creates an output SAS data set from the DBF file.

OUT=<libref.>membernames the SAS data set that is created to hold the converted data. Use this optiononly if you are creating a SAS data set from a DBF file and you did not specify theDATA= option.

If OUT= is omitted, SAS creates a temporary data set in the Work library. (UnderUNIX and z/OS, the temporary data set is named Data1 [...Datan]. Under MicrosoftWindows, it is called _DATA_.) If OUT= is omitted or if you do not specify a two-levelname in the OUT= option, the data set remains available during your current SASsession, but it is not permanently saved.

Details

The DBF procedure converts dBASE files to SAS data sets that are compatible with thecurrent release of SAS, or it converts SAS data sets to DBF files.

PROC DBF produces one output file but no printed output. The output file containsthe same information as the input file but in a different format.

The DBF procedure works with DBF files that all current versions and releases ofdBASE (II, III, III PLUS, IV, and 5.0) create and with most DBF files that othersoftware products create.

Future versions of dBASE files might not be compatible with the current version ofthe DBF procedure. To use the DBF procedure, you must have a SAS/ACCESSInterface to PC Files license.

Converting DBF Fields to SAS VariablesNumeric variables are stored in character form by DBF files. These numeric variablesbecome SAS numeric variables when converted from a DBF file to a SAS data set. If aDBF numeric value is missing, the corresponding dBASE numeric field is filled with thecharacter 9, by default.

Character variables become SAS character variables. Logical fields become SAScharacter variables with a length of 1. Date fields become SAS date variables. Whenyou are converting a DBF file to a SAS data set, fields with data stored in auxiliaryDBF files (Memo and General fields) are ignored.

When a dBASE II file is translated into a SAS data set, any colons in dBASEvariable names are changed to underscores in SAS variable names. Conversely, when aSAS data set is translated into a dBASE file, any underscores in SAS variable namesare changed to colons in dBASE field names.

Page 267: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The DBF and DIF Procedures � The DBF Procedure 259

Converting SAS Variables to DBF FieldsNumeric variables are stored in character form by DBF files. SAS numeric variablesbecome numeric variables with a length of 16 when converting from a SAS data set to aDBF file. A SAS numeric variable with a decimal value must be stored in a decimalformat in order to be converted to a DBF numeric field with a decimal value. In otherwords, unless you associate the SAS numeric variable with an appropriate format in aSAS FORMAT statement, the corresponding DBF field does not have any value to theright of the decimal point. You can associate a format with the variable in a SAS dataset when you create the data set or by using the DATASETS procedure.

If the number of digits—including a possible decimal point—exceeds 16, a warningmessage is issued and the DBF numeric field is filled with the character 9. All SAScharacter variables become DBF fields of the same length. When you are convertingdata from a SAS data set to a DBF file that is compatible with dBASE III or later, SASdate variables become DBF date fields. When you are converting data from a SAS dataset to a dBASE II file, SAS date variables become dBASE II character fields in the formYYYYMMDD.

Transferring Other Software Files to DBF FilesYou might find it helpful to save another software vendor’s file to a DBF file and thenconvert that file into a SAS data set. UNIX users find this especially helpful. Forexample, you could save an Excel XLS file to a DBF file (by selecting File � Save Asfrom within an Excel spreadsheet and selecting the Emp.dbf file) and then use PROCDBF to convert that file into a SAS data set. Or you could do the reverse: use PROCDBF to convert a SAS data set into a DBF file and then load that file into an Excelspreadsheet.

Examples for UNIX

Example 1: Converting a dBASE II File to a SAS Data Set In this example, a dBASE IIfile named Employee.dbf is converted to a SAS data set. Because no FILENAMEstatement is specified, the last level of the filename is assumed to be .dbf and the file isassumed to be in your current directory and in uppercase.

libname save ’/my/unx_save_dir’;proc dbf db2=employee out=save.employee;run;

Example 2: Converting a SAS Data Set to a dBASE 5 File In this example, a SAS dataset is converted to a dBASE 5 file. A FILENAME statement specifies a fileref thatnames the dBASE 5 file. You must specify the FILENAME statement before the PROCDBF statement.

libname mylib ’/my/unix_directory’;filename employee ’/sasdemo/employee.dbf’;proc dbf db5=employee data=mylib.employee;run;

Here is the same example for the Microsoft Windows environment:

libname mylib ’c:\my\directory’;filename employee ’c:\sasdemo\employee.dbf’;proc dbf db5=employee data=mylib.employee;run;

Page 268: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

260 The DIF Procedure � Appendix 1

Here is the same example for the z/OS environment:

libname mylib ’sasdemo.employee.data’;filename dbfout ’sasdemo.newemp.dbf’ recfm=n;proc dbf db5=dbfout data=mylib.employee;run;

The DIF Procedure

Converts a DIF file to SAS data set or a SAS data set to a DIF file.

Restrictions: The DIF procedure is available only under UNIX and Microsoft Windowsoperating environments.

SyntaxPROC DIF options;

PROC DIF Options

DIF=fileref | filenamespecifies the fileref or filename of a DIF file.

If you specify a fileref, the FILENAME statement that you used to define it mustspecify the filename plus a .dif extension; for example, filename myref ’/my_dir/myfile.dif’.

If you specify a filename instead of a fileref, you can specify only the name itself(omitting the .dif extension) and the file must be in the current directory. Forexample, this PROC DIF statement creates the Emp.dif file from theMyLib.Employee data set:

proc dif dif=emp data=mylib.employee;

You cannot specify emp.dif or a full pathname (proc dif dif=’/my/unix_directory/emp.dif’).

DATA=<libref.>membernames the input SAS data set. Use this option if you are creating a DIF file from aSAS data set. If you use this option, do not use the OUT= option. If you omit theDATA= option, SAS creates an output SAS data set from the DIF file.

OUT=<libref.>membernames the SAS data set to hold the converted data. You use this option only if youomit the DATA= option and you are creating a SAS data set from a DIF file.

If OUT= is omitted, SAS creates a temporary data set in the Work library. (UnderUNIX, the temporary data set is named Data1 [...Datan]. Under Microsoft Windows,it is called _DATA_. If OUT= is omitted or if you do not specify a two-level name inthe OUT= option, the data set remains available during your current SAS sessionbut is not permanently saved.

LABELScauses PROC DIF to write the names of the SAS variables as the first row of the DIFfile and a row of blanks as the second row of the DIF file. The actual data portion of

Page 269: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

The DBF and DIF Procedures � The DIF Procedure 261

the DIF file begins in the third row. The LABELS option is allowed only when youare converting a SAS data set to a DIF file.

PREFIX=namespecifies a prefix to be used in constructing SAS variable names when you areconverting a DIF file to a SAS data set. For example, if PREFIX=VAR, the newvariable names are VAR1, VAR2, ... VARn. If you omit the PREFIX= option, PROCDIF assigns the names Col1, Col2, ... Coln.

SKIP=nspecifies the number of rows, beginning at the top of the DIF file, to be ignored whenconverting a DIF file to a SAS data set. For example, the first row of your DIF filecontains column headings and the second row of your DIF file is a blank row. Theactual data in your DIF file begins in row 3. You should specify SKIP=2 so thatPROC DIF ignores the nondata portion of your DIF file. You could also delete thefirst two rows of your DIF file before using PROC DIF.

DetailsThe DIF procedure converts data interchange format (DIF) files to SAS data sets thatare compatible with the current release of SAS software, or it converts SAS data sets toDIF files.

PROC DIF produces one output file but no printed output. The output file containsthe same information as the input file but in a different format.

Software Arts, Inc. developed the data interchange format to be used as a commonlanguage for data. Originally, DIF was made popular by products such as Lotus 1-2-3and VisiCalc. Although DIF is not as popular today as it once was, it is still supportedby many software products.

Note: Any DIF file that you plan to convert to a SAS data set should be in a tabularformat. All items in a given column should represent the same type of data. If any rowsin the DIF file contain inconsistent data—for example, a row of underscores, dashes, orblanks—delete these rows before converting the DIF file to a SAS data set. It isrecommended that you make a backup copy of your DIF table before you make thesemodifications. �

When you are converting data from a DIF file to a SAS data set, each row of the DIFfile becomes an observation in the SAS data set. Conversely, when you are converting aSAS data set to a DIF file, each SAS observation becomes a row in the DIF file. To usethe DIF procedure, you must have a SAS/ACCESS Interface to PC Files license.

Converting DIF Variables to SAS VariablesCharacter variables in a DIF file (sometimes referred to as string values) become SAScharacter variables of length 20. If a DIF character variable’s value is longer than 20characters, it is truncated to a length of 20 in the SAS output data set. The quotationmarks that normally enclose character variable values in a DIF file are removed whenthe value is converted to a SAS character value.

Numeric variables, which can be represented in either integer or scientific notation ina DIF file, become SAS numeric variables when a DIF file is converted to a SAS data set.

Transferring SAS Data Sets to and from Other Software Products Using DIFDIF files are not generally used as the native file format for a software product’s datastorage. Therefore, transferring data between SAS and another software product is atwo-step process when using DIF files.

Page 270: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

262 The DIF Procedure � Appendix 1

To send SAS data sets to another software product using DIF files, you must first runPROC DIF to convert your SAS data set to a DIF file. Use whatever facility is providedby the target software product to read the DIF file. For example, you use theLotus 1-2-3 Translate Utility to translate a DIF file to a 1-2-3 worksheet file. (Thisfacility might be provided by an import tool or from an Open window in that softwareproduct.) After the application reads the DIF file data, the data can be manipulatedand saved in the application’s native format.

To transfer data in the opposite direction — from a software product to a SAS dataset — the process is reversed. First, export the data to a DIF file and then run PROCDIF to read the DIF file into a SAS data set.

Missing ValuesThe developers of the data interchange format (DIF) files suggest that you treat allnumeric values that have a value indicator other than V as missing values. PROC DIFfollows this convention. When a DIF file is converted to a SAS data set, any numericvalue with a value indicator other than V becomes a SAS missing value.

When a SAS data set that has missing values for some numeric variables isconverted to a DIF file, the following assignments are made in the DIF file for thevariables with missing values:

� the type indicator field value is set to 0

� the number field value contains a string of 16 blanks� the value indicator is set to NA.

Examples

Example 1: Converting a DIF File to a SAS Data Set In this example, a DIF file namedEmployee.dif is converted to a SAS data set. Because no FILENAME statement isspecified, the last level of the filename is assumed to be .dif, and the file is assumed tobe in your current directory and in uppercase.

libname save ’/my/my_unx_dir’;proc dif dif=employee out=save.employee;run;

Example 2: Converting a SAS Data Set to a DIF File In this example, a SAS data set isconverted to a DIF file. A FILENAME statement is used to specify a fileref that namesthe DIF file. You must specify the FILENAME statement before the PROC DIFstatement.

filename employee ’c:\sasdemo\employee.dif’;proc dif dif=employee data=save.employee;run;

Here is the same example in a UNIX environment:

filename employee ’/sasdemo/employee.dif’;proc dif dif=employee data=save.employee;run;

See Also“Programmer’s Guide to the DIF,” Software Arts Technical Notes (SATN-18).

Page 271: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

263

A P P E N D I X

2Recommended Reading

Recommended Reading 263

Recommended Reading

Here is the recommended reading list for this title:� SAS/ACCESS for Relational Databases: Reference� SAS Language Reference: Concepts

� SAS Language Reference: Dictionary� SAS Macro Language: Reference� Base SAS Procedures Guide

� SAS Companion that is specific to your operating environment

For a complete list of SAS publications, go to support.sas.com/bookstore. If youhave questions about which titles you need, please contact a SAS Publishing SalesRepresentative at:

SAS Publishing SalesSAS Campus DriveCary, NC 27513Telephone: 1-800-727-3228Fax: 1-919-531-9439E-mail: [email protected] address: support.sas.com/bookstore

Customers outside the United States and Canada, please contact your local SAS officefor assistance.

Page 272: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

264

Page 273: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

265

Glossary

This glossary defines SAS software terms that are used in this document as well asterms that relate specifically to SAS/ACCESS software.

access descriptora SAS/ACCESS file that describes data that a data management system manages.After creating an access descriptor, you can use it as the basis for creating one ormore view descriptors. See also view and view descriptor.

browsing datathe process of viewing the contents of a file. Depending on how the file is accessed,you can view SAS data either one observation (row) at a time or as a group in atabular format. You cannot update data that you are browsing.

bulk loadto load large amounts of data into a database object, using methods that are specificto a particular DBMS. Bulk loading enables you to rapidly and efficiently addmultiple rows of data to a table as a single unit.

client(1) a computer or application that requests services, data, or other resources from aserver. (2) in the X Window System, an application program that interacts with the Xserver and can perform tasks such as terminal emulation or window management.For example, SAS is a client because it requests windows to be created, results to bedisplayed, and so on.

columnin relational databases, a vertical component of a table. Each column has a uniquename, contains data of a specific type, and has certain attributes. A column isanalogous to a variable in SAS terminology.

column functionan operation that is performed for each value in the column that is named as anargument of the function. For example, AVG(SALARY) is a column function.

committhe process that ends a transaction and makes permanent any changes to thedatabase that the user made during the transaction. When the commit processoccurs, locks on the database are released so that other applications can access thechanged data. The SQL COMMIT statement initiates the commit process.

Page 274: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

266 Glossary

DATA step viewa type of SAS data set that consists of a stored DATA step program. Like other SASdata views, a DATA step view contains a definition of data that is stored elsewhere;the view does not contain the physical data. The view’s input data can come from oneor more sources, including external files and other SAS data sets. Because a DATAstep view only reads (opens for input) other files, you cannot update the view’sunderlying data.

data typean attribute of every column in a table or database. The data type tells the operatingsystem how much physical storage to set aside for the column and specifies what typeof data the column will contain. It is similar to the type attribute of SAS variables.

data valuein SAS software, a unit of character or numeric information in a SAS data set. Adata value represents one variable in an observation.

databasean organized collection of related data. A database usually contains named files,named objects, or other named entities such as tables, views, and indexes.

database fielda vertical component of a dBASE .DBF file that contains data of a specific type withcertain attributes. A database field is analogous to a variable in SAS terminology.

database filea two-dimensional system of representing data in records and fields.

database management system (DBMS)a software application that enables you to create and manipulate data in the form ofdatabases. See also relational database management system.

editing datathe process of viewing the contents of a file with the intent and the ability to changeits data. Depending on how the file is accessed, you can view the details either oneobservation at a time or in a tabular format.

enginea component of SAS software that reads from or writes to a file. Each engine enablesSAS to access files that are in a particular format. There are several types of engines.

filea collection of related records that are treated as a unit. SAS files are processed andcontrolled through SAS software and are stored in SAS libraries.

formatan instruction that SAS uses to display or write each value of a variable (or column).Some formats are supplied by SAS software. You can create other formats by usingthe FORMAT procedure in Base SAS software. In SAS/ACCESS software, the defaultformats vary according to the interface product.

indexin SAS software, a component of a SAS data set that enables SAS to accessobservations in the SAS data set quickly and efficiently. The purpose of SAS indexesis to optimize WHERE-clause processing and to facilitate BY-group processing.

informata pattern or set of instructions that SAS uses to determine how data values in aninput file should be interpreted. SAS provides a set of standard informats and alsoenables you to define your own informats.

Page 275: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Glossary 267

interface view enginea SAS engine that is used by SAS/ACCESS software to retrieve data from files thathave been formatted by another vendor’s software. Each SAS/ACCESS interface hasits own interface view engine, which reads the interface product data and returns thedata in a form that SAS can understand (that is, in a SAS data set). SASautomatically uses an interface view engine; the engine name is stored inSAS/ACCESS descriptor files so that you do not need to specify the engine name in aLIBNAME statement.

librefa name that is temporarily associated with a SAS library. The complete name of aSAS file consists of two words, separated by a period. The libref, which is the firstword, indicates the library. The second word is the name of the specific SAS file. Forexample, in VLIB.NEWBDAY, the libref VLIB tells SAS which library contains thefile NEWBDAY. You assign a libref with a LIBNAME statement or with an operatingsystem command.

membera name that represents a particular data item within a dimension. For example,September 1996 might be a member of the Time dimension. A member can be eitherunique or non-unique. For example, 1997 and 1998 represent unique members in theYear level of a Time dimension. January represents non-unique members in theMonth level, because there can be more than one January in the Time dimension ifthe Time dimension contains data for more than one year.

member namea name that is assigned to a SAS file in a SAS library.

member typea SAS name that identifies the type of information that is stored in a SAS file.Member types include ACCESS, DATA, CATALOG, ITEMSTOR, MDDB, PROGRAM,and VIEW.

missing valuein SAS, a term that describes the contents of a variable that contains no data for aparticular row or observation. By default, SAS prints or displays a missing numericvalue as a single period, and it prints or displays a missing character value as ablank space.

observationa row in a SAS data set. All of the data values in an observation are associated witha single entity such as a customer or a state. Each observation contains one datavalue for each variable. In a database product table, an observation is analogous to arow. Unlike rows in a database product table or file, observations in a SAS data filehave an inherent order.

PROC SQL viewa SAS data set (of type VIEW) that is created by the SQL procedure. A PROC SQLview contains no data. Instead, it stores information that enables it to read datavalues from other files, which can include SAS data files, SAS/ACCESS views, DATAstep views, or other PROC SQL views. A PROC SQL view’s output can be either asubset or a superset of one or more files.

querya set of instructions that requests particular information from one or more datasources.

recorda logical unit of information that consists of fields of related data. A collection ofrecords is stored in a file. A record is analogous to a SAS observation.

Page 276: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

268 Glossary

referential integritya set of rules that a DBMS uses to ensure that whenever a data value in one table ischanged, the appropriate change is also made to any related values in other tables orin the same table. Referential integrity is also used to ensure that related data is notdeleted or changed accidentally.

relational database management systema database management system that organizes and accesses data according torelationships between data items. The main characteristic of a relational databasemanagement system is the two-dimensional table. Examples of relational databasemanagement systems are DB2, INGRES, ORACLE, and SQL/DS.

rollbackin most databases, the process that restores a database to its state when changeswere last committed, voiding any changes. The SQL ROLLBACK statement initiatesthe rollback process.

rowin relational database management systems, the horizontal component of a table. Arow is analogous to a SAS observation.

SAS data filea type of SAS data set that contains data values as well as descriptor informationthat is associated with the data. The descriptor information includes informationsuch as the data types and lengths of the variables, as well as the name of the enginethat was used to create the data. A PROC SQL table is a SAS data file. SAS datafiles are of member type DATA.

SAS data seta file whose contents are in one of the native SAS file formats. There are two types ofSAS data sets: SAS data files and SAS data views. SAS data files contain datavalues in addition to descriptor information that is associated with the data. SASdata views contain only the descriptor information plus other information that isrequired for retrieving data values from other SAS data sets or from files whosecontents are in other software vendors’ file formats.

SAS data viewa type of SAS data set that retrieves data values from other files. A SAS data viewcontains only descriptor information such as the data types and lengths of thevariables (columns), plus other information that is required for retrieving data valuesfrom other SAS data sets or from files that are stored in other software vendors’ fileformats. SAS data views are of member type VIEW.

SAS librarya collection of one or more SAS files that are recognized by SAS and which arereferenced and stored as a unit. Each file is a member of the library.

SAS/ACCESS viewsSee view descriptor and SAS data view.

Structured Query Language (SQL)a standardized, high-level query language that is used in relational databasemanagement systems to create and manipulate database management systemobjects. SAS implements SQL through the SQL procedure.

Page 277: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Glossary 269

serverin a network, a computer that is reserved for servicing other computers in thenetwork. Servers can provide several types of services, such as file services andcommunication services. Servers can also enable users to access shared resourcessuch as disks, data, and modems.

Structured Query Language (SQL)the standardized, high-level query language that is used in relational databasemanagement systems to create and manipulate database management systemobjects. SAS implements SQL through the SQL procedure.

tablea two-dimensional representation of data, in which the data values are arranged inrows and columns.

triggera type of user-defined stored procedure that is executed whenever a user issues adata-modification command such as INSERT, DELETE, or UPDATE for a specifiedtable or column. Triggers can be used to implement referential integrity or tomaintain business constraints.

variablea column in a SAS data set or in a SAS data view. The data values for each variabledescribe a single characteristic for all observations. In the ACCESS procedure,variables are created from the PC files’ columns or fields.

viewa definition of a virtual data set. The definition is named and stored for later use. Aview contains no data but describes or defines data that are stored elsewhere. Seealso PROC SQL view, SAS data view, and view descriptor.

view descriptora SAS/ACCESS file that defines part or all of the DBMS data that is described by anaccess descriptor.

windowing procedurea SAS procedure that you can use by entering information in one or more windows ordialog boxes. For example, the FSVIEW procedure is a windowing procedure. Someprocedures, such as ACCESS and DBLOAD, can be used either as windowingprocedures or in batch mode.

wildcarda file created by SAS/ACCESS software that defines part or all of the databasemanagement system (DBMS) data or PC file data that is described by an accessdescriptor. The access descriptor describes the data in a single DBMS table, DBMSview, or PC file.

Page 278: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

270

Page 279: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

271

Index

Aabsolute range address

importing data with 46ACCDB file format 47ACCDESC= option

PROC ACCESS statement 196ACCDESC= statement

DBLOAD procedure 217access descriptors 193

creating 198passwords for 193performance and 194resetting column settings 207updating 211WKn files with 236

ACCESS enginecommitting updates 93

ACCESS= LIBNAME option 86, 153access methods 3ACCESS procedure 191, 194

component for Excel 33importing and exporting Excel files 42statements 192syntax 194

ACCESS procedure, DBF (Windows) 243data conversions 245QUIT statement 244syntax 243

ACCESS procedure, DIF 247data conversions 250datetime conversions 250DIFLABEL statement 248QUIT statement 248SKIPROWS statement 249syntax 248

ACCESS procedure, WKn 236data conversions 239GETNAMES statement 237QUIT statement 237RANGE statement 238SCANTYPE statement 238SKIPROWS statement 238syntax 236WORKSHEET statement 239

ACCESS procedure, XLS 226data conversions 228syntax 226

Ace queries 122

ASSIGN statementACCESS procedure 196

AUTOCOMMIT= argumentCONNECT statement 114, 180

AUTOCOMMIT= data set option 93AUTOCOMMIT= LIBNAME option 86, 153

Bbuffers

reading rows into 109, 174

Ccells 31character data 32, 56

very long character data type 101, 167column names

saved as label names 104variable labels as 100, 166

columnsdate format of 110, 175disallowed characters in 99, 164NULL values 102, 167renaming 99, 164

comma-separated values filesSee CSV files

commandsJet commands 124timing out 94, 160

COMMAND_TIMEOUT= argumentCONNECT statement 114, 180

COMMAND_TIMEOUT= data set option 94, 160COMMAND_TIMEOUT= LIBNAME option 86, 154commit statements

row processing 95, 161configuration

PC Files Server 143, 144CONNECT statement

arguments 114, 180database connection arguments 113Pass-Through Facility, UNIX 178Pass-Through Facility, Windows 113

CONNECTION= argumentCONNECT statement 114, 181

CONNECTION= LIBNAME option 86, 154connection options

Access files 132Excel workbook files 128

Page 280: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

272 Index

LIBNAME statement, UNIX 149CONNECTION TO component

Pass-Through Facility, UNIX 185Pass-Through Facility, Windows 120

CONNECTION_GROUP= argumentCONNECT statement 115, 181

CONNECTION_GROUP= LIBNAME option 87, 154CONNECT_STRING= LIBNAME option 149CONNECT_STRING= option

CONNECT statement 179CREATE statement

ACCESS procedure 197CREATE TABLE statement

data source-specific syntax 97, 163CSV files 27

exporting data sets to 29importing into SAS 29importing subsets into SAS 30

cursor type 94, 161CURSOR_TYPE= argument

CONNECT statement 115, 181CURSOR_TYPE= data set option 94, 161CURSOR_TYPE= LIBNAME option 87, 154

Ddata access methods 3DATA= argument

PROC DBLOAD statement 217PROC EXPORT statement 20

data conversionsACCESS procedure, DBF 245ACCESS procedure, DIF 250ACCESS procedure, WKn 239ACCESS procedure, XLS 228DBLOAD procedure, DBF 247DBLOAD procedure, WKn 241DBLOAD procedure, XLS 233

DATA= optionDBF procedure 258DIF procedure 260

data set optionsPC files on Linux and UNIX 159PC files on Windows 93

data setsconverting dBASE files to 257converting dBASE II files to 259converting to dBASE 5 files 259converting to DIF files 260DBF files and 245, 247DIF files and 250exporting to CSV files 29exporting to Excel 5 files 43exporting to Excel files 41exporting to Excel workbook files 42, 46importing from Excel 5 files 43importing ranges to 41transferring with DIF files 261WKn files and 239, 241

data source tablesdata type for 105, 170

data sources, supported 7data types

Ace provider 120conversion for Access files 133conversion for Excel workbook files 130

DBF 59DIF 253DTA 69Excel 32for data source tables 105, 170Jet provider 120JMP 64Microsoft Access database 47overriding 104, 169SAV 67WKn 56

database connection argumentsCONNECT statement 113

database fields 59DATAFILE= argument

PROC IMPORT statement 14DATAROW= statement

IMPORT and EXPORT procedures 28DATATABLE= argument

PROC IMPORT statement 15date and time values 56date format

of data source columns 110, 175date/time values

SAS versus Access 136SAS versus Excel 132

date values 33datetime conversions

ACCESS procedure, DIF 250DBLOAD procedure, DIF 252

datetime values 33DB files, Paradox 66dBASE 5 files

converting data sets to 259dBase DBF files 58

ACCESS procedure with 243converting to SAS variables 258data conversions 245, 247DBF data types 59DBLOAD procedure with 245examples of importing and exporting 62missing values 247setting environment variables 60setting system options 60supported IMPORT/EXPORT procedure statements 61transferring other software files to 259

dBase DBFMEMO files 63dBASE files

converting to data sets 257dBASE II files

converting to data sets 259DBCOMMIT= data set option 95, 161DBCOMMIT= LIBNAME option 87, 155DBCONDITION= data set option 96, 162DBCREATE_TABLE_OPTS= data set option 97, 163DBENCODING= argument

CONNECT statement 115DBENCODING= data set option 98DBENCODING= LIBNAME option 88DBF data types 59DBF fields

converting SAS variables to 259DBF files

See dBase DBF filesDBF procedure 257DBFORCE= data set option 98, 164

Page 281: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Index 273

DBGEN_NAME= argumentCONNECT statement 115, 181

DBGEN_NAME= data set option 99, 164DBGEN_NAME= LIBNAME option 88, 155DBGEN_NAME= option

CONNECT statement 115DBKEY= data set option 100, 165

format of WHERE clause 103, 168DBKEY= processing

missing values and 108, 109, 173DBLABEL= data set option 100, 166DBLOAD procedure 215, 216

component for Excel 33importing and exporting Excel files 42naming conventions 216syntax 216

DBLOAD procedure, DBF (Windows) 245data conversions 247environment variables 247QUIT statement 246syntax 245VERSION statement 246

DBLOAD procedure, DIF 250datetime conversions 252DIFLABEL statement 251environment variables 253FORMAT statement 251QUIT statement 251syntax 251

DBLOAD procedure, WKn 240data conversions 241FORMAT statement 241PUTNAMES statement 241QUIT statement 241syntax 240

DBLOAD procedure, XLS 232data conversions 233syntax 232

DBMAX_TEXT= argumentCONNECT statement 115

DBMAX_TEXT= data set option 101, 167DBMAX_TEXT= LIBNAME option 88, 155DBMAX_TEXT= option

CONNECT statement 182DBMEMO files 63DBMS= argument

PROC DBLOAD statement 217DBMS engines

trace information from 77DBMS= option

PROC ACCESS statement 196PROC EXPORT statement 21PROC IMPORT statement 15

DBMS specificationsEXPORT procedure 21IMPORT procedure 15

DBn optionsDBF procedure 257

DBNULL= data set option 102, 167DBNULLKEYS= data set option 103, 168DBNULLKEYS= LIBNAME option 88, 155DBPASSWORD= LIBNAME option 150DBPASSWORD= option

CONNECT statement 179DBSASLABEL= data set option 104DBSASLABEL= LIBNAME option 89, 156

DBSASTYPE= data set option 104, 169DBSYSFILE= LIBNAME option 150DBSYSFILE= option

CONNECT statement 179DBTYPE= data set option 105, 170DEFER= argument

CONNECT statement 116DEFER= LIBNAME option 89, 156DEFER= option

CONNECT statement 182DELETE statement

DBLOAD procedure 218delimited files 26

examples of importing and exporting 29IMPORT and EXPORT procedure statements for 27text files 26

delimiter-separated values (DSV) files 26DELIMITER= statement

IMPORT and EXPORT procedures 28delimiters 26descriptor files 193

examples 199passwords for 193performance and 194

desktop applicationsrunning PC Files Server as 141

DIF file data types 253DIF files

converting to data sets 260missing values and 262transferring data sets with 261

DIF (Lotus) filesACCESS procedure with 247data conversions 250DBLOAD procedure with 250

DIF= optionDIF procedure 260

DIF procedure 260DIF variables

converting to SAS variables 261DIFLABEL statement

ACCESS procedure 248DBLOAD procedure 251

DIRECT_SQL= LIBNAME option 89, 156DISCONNECT statement

Pass-Through Facility, UNIX 183Pass-Through Facility, Windows 117

DLM files 26DNS= LIBNAME option 149DROP statement

ACCESS procedure 201DSN= option

CONNECT statement 179DSV files 26DTA data types 69DTA files 69

EEFI (External File Interface) 11encoding

character set for Access databases 98character set for Excel workbook files 98

encryptionPC Files Server 143

Page 282: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

274 Index

environment variablesdBase DBF files 60Lotus WKn files 242XLS files 235

ERRLIMIT= data set option 106, 170ERRLIMIT= statement

DBLOAD procedure 218error limit, before rollback 106, 170Excel 2007 31, 41Excel files 31Excel workbooks 31EXECUTE statement

Pass-Through Facility, UNIX 184Pass-Through Facility, Windows 118

EXPORT procedure 19Access table specification compatibility 23DBMS specifications 21examples of exporting delimited files 29Excel spreadsheet specification compatibility 23features of 7statements for delimited files 27supported data sources and platforms 7syntax 20

export utilities 33Export Wizard 11

features of 7supported data sources and platforms 7

exportingAccess files 49, 53data sets to Excel 5 files 43data sets to Excel files 41data sets to Excel workbook files 42, 46DB files 67DBF files 61, 62delimited files 29DTA files 71Excel files with ACCESS and DBLOAD procedures 42Excel files with LIBNAME statement 33Excel files with XLS file formats 43JMP files 65, 66SAV files 69WKn files 56, 57XLS files 46

External File Interface (EFI) 11extracting data 193

view descriptors for 194

Ffile formats

ACCDB 47Access database files 47CSV 27DBF 58DBFMEMO 63DLM 26DSV 26DTA 69JMP 63MDB 47, 49Paradox DB 66SAV 67TAB 27WKn 54XLS 31, 33XLSB 31, 41

XLSM 31XLSX 31

FILELOCK= LIBNAME option 90FORMAT statement

ACCESS procedure 201DBLOAD procedure 241, 251

functions 81, 147

GGETNAMES statement

ACCESS procedure 237IMPORT and EXPORT procedures 28

GUESSINGROWS= statementIMPORT and EXPORT procedures 28

IIMPORT procedure 13

DBMS specifications 15examples of importing delimited files 29Excel spreadsheet specification compatibility 17Excel spreadsheet specifications 17features of 7statements for delimited files 27supported data sources and platforms 7syntax 14

import utilities 33Import Wizard 11

features of 7supported data sources and platforms 7

importingAccess files 49, 53data sets from Excel 5 files 43data using a range name 46data using absolute range address 46DB files 67DBF files 61, 62delimited files 29DTA files 71Excel files with ACCESS and DBLOAD procedures 42Excel files with LIBNAME statement 33Excel files with XLS file formats 43JMP files 65, 66ranges to data sets 41SAV files 69WKn files 56, 57XLS files 46

INIT= argumentCONNECT statement 113

INIT= LIBNAME option 83insert processing

missing values and 108, 109, 173INSERTBUFF= data set option 107, 172INSERTBUFF= LIBNAME option 90, 157INSERT_SQL= data set option 107, 171INSERT_SQL= LIBNAME option 90installing PC Files Server 141

JJet commands 124Jet queries 122JMP data types 64JMP files 63

examples of importing and exporting 65, 66

Page 283: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Index 275

importing and exporting data in 65missing values 63

joinsperformance improvement 100, 165

LLABEL option

PROC EXPORT statement 23LABEL statement

DBLOAD procedure 219LABELS option

DIF procedure 260LIBNAME connection options

Access files 132Excel workbook files 128

LIBNAME engines 75macro variables 76software requirements 76trace system options 77

LIBNAME optionsPC files on Linux and UNIX 153

LIBNAME statement, PC files 33, 81, 82assigning librefs 82, 85connection options 83connection options on UNIX 149for Access files 132for Excel workbook files 127functions with PC files data 81importing and exporting Excel files 33on 64-bit Microsoft Windows 147on Linux 147on UNIX 147options for Windows 86sorting data 81syntax 82syntax, on Linux 148syntax, on UNIX 148

librariesdisassociating librefs from 151writing attributes to log 85, 151

librefsassigning 82, 85assigning to Access databases 151assigning to Excel workbooks 152assigning to Oracle databases 153assigning to SQL Server databases 153disassociating 85, 151

LIMIT= statementDBLOAD procedure 219

Linuxdata set options 159LIBNAME options 153LIBNAME statement 148

LIST statementACCESS procedure 202DBLOAD procedure 220

LOAD statementDBLOAD procedure 221

logwriting library attributes to 85, 151

Lotus DIF filesACCESS procedure with 247data conversions 250DBLOAD procedure with 250

Lotus WKn data types 56

Lotus WKn files 54ACCESS procedure with 236data conversions 239, 241DBLOAD procedure 240environment variables 242examples of importing and exporting 57import and export components and statements 56

Mmacro variables 76MDB file format 47

IMPORT and EXPORT procedure statements 49Microsoft Access

assigning librefs to databases 151encoding character set for database 98LIBNAME statement, PC files on UNIX 150table specification compatibility 23

Microsoft Access database data types 47Microsoft Access database files 47

accessing data in 30examples of importing and exporting 53IMPORT and EXPORT procedure statements for 49with IMPORT and EXPORT procedures 49

Microsoft Access filesdata types conversion for 133file-specific reference 132LIBNAME connection options for 132LIBNAME statements for 132

Microsoft Ace provider data types 120Microsoft Excel

assigning librefs to workbooks 152data types 32DBMS spreadsheet specifications 17import and export components 33LIBNAME statement, PC files on UNIX 150spreadsheet specification compatibility 17, 23workbooks 31

Microsoft Excel 2007 31, 41Microsoft Excel files 31

exporting data sets to 41exporting data sets to Excel 5 files 43importing data sets from Excel 5 files 43importing/exporting using XLS file formats 43importing/exporting with ACCESS and DBLOAD proce-

dures 42importing/exporting with LIBNAME statement 33importing ranges to data sets 41

Microsoft Excel workbook files 31accessing data in 30data types conversion for 130encoding character set for 98exporting data sets to 42, 46file-specific reference 127LIBNAME connection options for 128LIBNAME statements for 127

Microsoft Jet provider data types 120Microsoft Windows

Pass-Through Facility on 111missing values

DBF files 247DBKEY= processing and 108, 109, 173DIF file conversions 262insert processing and 108, 109, 173JMP files 63update processing and 108, 109, 173

Page 284: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

276 Index

MIXED statementACCESS procedure 203

MSENGINE= argumentCONNECT statement 116

MSENGINE= LIBNAME option 90, 150MSENGINE= option

CONNECT statement 180

Nnaming conventions

DBLOAD procedure 216NULL values

in columns 102, 167NULLCHAR= data set option 108, 173NULLCHARVAL= data set option 109, 173numeric data 32, 56

OOracle

assigning librefs to databases 153ordering PC files data 96, 162OUT= argument

PROC IMPORT statement 15OUT= option

DBF procedure 258DIF procedure 260PROC ACCESS statement 196

OUTFILE= argumentPROC EXPORT statement 20

OUTTABLE= argumentPROC EXPORT statement 21

overriding data types 104, 169

PParadox DB files 66

examples of importing and exporting 67Pass-Through Facility, UNIX 177

return codes 178special queries 187syntax 177

Pass-Through Facility, Windows 111CONNECT statement 113CONNECTION TO component 120DISCONNECT statement 117EXECUTE statement 118return codes 112syntax 112

PASSWORD= LIBNAME option 150PASSWORD= option

CONNECT statement 180passwords

access descriptors 193descriptor files 193view descriptors 193

PATH= argumentCONNECT statement 113

PATH= LIBNAME option 84, 149PATH= option

CONNECT statement 179PATH= statement

ACCESS procedure 204DBLOAD procedure 221

PC filesACCESS procedure 191assigning librefs 82, 85data access methods 3data set options 93DBLOAD procedure 215descriptor files 193functions with PC files data 81, 147LIBNAME statement for 81Pass-Through Facility on UNIX 177sorting data 81, 96, 147, 162special queries 187subsetting data 96, 162

PC Files Server 139configuring 143, 144constraints 144data encryption 143installation 141maximum connections 143modes 140port number 143running as desktop application 141running as Windows Service 144service name 143shared information 145

PCFFSCL.SAS file 229performance

descriptors and 194joins 100, 165

platforms, supported 7PORT= LIBNAME option 149port number

PC Files Server 143PORT= option

CONNECT statement 179PREFIX= option

DIF procedure 261printing

SASTRACE information 80PROC ACCESS statement 195PROC DBLOAD statement 217PROC EXPORT statement 20PROC IMPORT statement 14PROMPT= argument

CONNECT statement 113PROMPT= LIBNAME option 84PUTNAMES statement

DLOAD procedure 241IMPORT and EXPORT procedures 28

Qqueries

Jet and Ace 122special PC files queries 187

QUIT statementACCESS procedure 205, 237, 244, 248DBLOAD procedure 222, 241, 246, 251

Rrange names

importing data with 46RANGE statement

ACCESS procedure 238

Page 285: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Index 277

ranges 31importing to data sets 41

READBUFF= argumentCONNECT statement 116

READBUFF= data set option 109, 174READBUFF= LIBNAME option 91, 157READBUFF= option

CONNECT statement 182RENAME statement

ACCESS procedure 205DBLOAD procedure 222

REPLACE optionPROC EXPORT statement 23PROC IMPORT statement 17

RESET statementACCESS procedure 206DBLOAD procedure 223

return codesPass-Through Facility, UNIX 178Pass-Through Facility, Windows 112

rollback, error limit for 106, 170row processing

commit statement for 95, 161rows

insertion method 107, 171number for single insert 107, 172number to read into buffer 109, 174

Ssample data 4SASDATEFMT= data set option 110, 175SASTRACE= system option 77

printing trace information 80SASTRACELOC= system option 80SAV data types 67SAV files 67SCAN_TEXTSIZE= LIBNAME option 91, 158SCAN_TIMETYPE= LIBNAME option 91, 158SCANTYPE statement

ACCESS procedure 238SELECT statement

ACCESS procedure 208SERVER= LIBNAME option 149Server Mode 140SERVER= option

CONNECT statement 179Service Mode 140service name

PC Files Server 143shared information

PC Files Server 145SKIP= option

DIF procedure 261SKIPROWS statement

ACCESS procedure 238, 249software requirements, for LIBNAME engine 76sorting PC files data 81, 96, 147, 162space-separated data values

importing into SAS 29SPOOL= LIBNAME option 92, 158SPSS SAV data types 67SPSS SAV files 67

examples of importing and exporting 69SQL Server

assigning librefs to databases 153

SQLXMSG macro variable 112, 178SQLXRC macro variable 112, 178SS_MIXED environment variable 242SS_NAMES environment variable 243SS_SCAN environment variable 243Stata DTA data types 69Stata DTA files 69

examples of importing and exporting 71STRINGDATES= argument

CONNECT statement 116STRINGDATES= LIBNAME option 92, 159STRINGDATES= option

CONNECT statement 182SUBSET statement

ACCESS procedure 209subsetting

importing CSV file subsets 30PC files data 96, 162

supported data sources 7supported platforms 7system options

dBase DBF files 60for tracing 77

TTAB files 27time values 33timeout for commands 94, 160trace information

from DBMS engine 77trace system options 77truncation, forcing 98, 164TYPE= LIBNAME option 150TYPE statement

ACCESS procedure 209

UUDL= argument

CONNECT statement 114UDL= LIBNAME option 84UNICODE= LIBNAME option 92UNIQUE statement

ACCESS procedure 210UNIX

accessing PC data from 150data set options 159LIBNAME options 153LIBNAME statement 148Pass-Through Facility 177

update processingmissing values and 108, 109, 173

UPDATE statementACCESS procedure 211

updating datamissing values and 247

USE_DATATYPE= LIBNAME option 92, 159USE_DATETYPE= argument

CONNECT statement 116USER= LIBNAME option 150USER= option

CONNECT statement 180utilities

import and export 33

Page 286: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

278 Index

Vvariables

converting DBF fields to SAS variables 258converting DIF variables to SAS variables 261converting SAS variables to DBF fields 259DBF files and 245, 247DIF files and 250WKn files and 239, 241

VERSION= LIBNAME option 149, 180VERSION statement

DBLOAD procedure 246very long character data type 101, 167view descriptors 193

creating 198extracting data with 194passwords for 193performance and 194resetting column settings 207updating 212

VIEWDESC= optionPROC ACCESS statement 196

WWHERE clause

format of, with DBKEY= data set option 103, 168WHERE statement

DBLOAD procedure 224

Windows Service

running PC Files Server as 144

WKn data types 56

WKn files

See also Lotus WKn files

ACCESS procedure 236

data conversions 239, 241

DBLOAD procedure 240

environment variables 242

WORKSHEET statement

ACCESS procedure 239

worksheets 31

XXLS file formats 33

importing/exporting 46

importing/exporting Excel files with 43

XLS files 31

ACCESS procedure 226

data conversions 228, 233

DBLOAD procedure 232

environment variables 235

XLSB files 31, 41

XLSM files 31

XLSX files 31

Page 287: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

Your Turn

We welcome your feedback.� If you have comments about this book, please send them to [email protected].

Include the full title and page numbers (if applicable).� If you have comments about the software, please send them to [email protected].

Page 288: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft
Page 289: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft
Page 290: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft
Page 291: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft

SAS® Publishing Delivers!Whether you are new to the work force or an experienced professional, you need to distinguish yourself in this rapidly changing and competitive job market. SAS® Publishing provides you with a wide range of resources to help you set yourself apart. Visit us online at support.sas.com/bookstore.

SAS® Press Need to learn the basics? Struggling with a programming problem? You’ll find the expert answers that you need in example-rich books from SAS Press. Written by experienced SAS professionals from around the world, SAS Press books deliver real-world insights on a broad range of topics for all skill levels.

s u p p o r t . s a s . c o m / s a s p r e s sSAS® Documentation To successfully implement applications using SAS software, companies in every industry and on every continent all turn to the one source for accurate, timely, and reliable information: SAS documentation. We currently produce the following types of reference documentation to improve your work experience:

• Onlinehelpthatisbuiltintothesoftware.• Tutorialsthatareintegratedintotheproduct.• ReferencedocumentationdeliveredinHTMLandPDF– free on the Web. • Hard-copybooks.

s u p p o r t . s a s . c o m / p u b l i s h i n gSAS® Publishing News Subscribe to SAS Publishing News to receive up-to-date information about all new SAS titles, author podcasts, and new Web site features via e-mail. Complete instructions on how to subscribe, as well as access to past issues, are available at our Web site.

s u p p o r t . s a s . c o m / s p n

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Otherbrandandproductnamesaretrademarksoftheirrespectivecompanies.©2009SASInstituteInc.Allrightsreserved.518177_1US.0109

Page 292: Interface to PC Files Reference - Dartmouth Collegemorgan.dartmouth.edu/Docs/sas92/SASDoc/book_files/9781599947105txt.pdfInterface to PC Files Reference SAS ... Accessing Data in Microsoft