Access SQL 7364
Access SQL 7364
1 Supplement for
®
Glossary 17
Index 23
iv
1
CHAPTER
1
SAS/ACCESS for Microsoft SQL
Server
Arguments
libref
is any SAS name that serves as an alias to associate SAS with a database,
schema, server, or group of tables and views.
sqlsvr
is the SAS/ACCESS engine name for the interface to Microsoft SQL Server.
connection-options
provide connection information and control how SAS manages the timing and
concurrence of the connection to the DBMS. There are multiple ways that you can
connect to Microsoft SQL Server when using the LIBNAME statement. Use only
one of the following methods for each connection since they are mutually exclusive:
3 specify USER=, PASSWORD=, and DATASRC=
3 specify COMPLETE=
3 specify NOPROMPT=
3 specify PROMPT=
3 specify REQUIRED=.
The connection options are defined as follows:
USER=<’>user-name<’>
enables you to connect to Microsoft SQL Server with a user ID that is
different from the default ID.
USER= is optional. UID= is an alias for this option.
PASSWORD=<’>password<’>
specifies the Microsoft SQL Server password that is associated with your user
ID.
PASSWORD= is optional. PWD= is an alias for this option.
DATASRC=<’>SQL-Server-data-source<’>
specifies the Microsoft SQL Server data source to which you want to connect.
For PC platforms, data sources must be configured by using the Microsoft
SQL Server icon in the Windows Control Panel. For UNIX platforms, data
sources must be configured by modifying the .ODBC.ini file.
DSN= is an alias for this option that indicates that the connection is
attempted using the ODBC SQLConnect API, which requires a data source
name. Optionally, a user ID and password can be used in conjunction with
DSN=. This API is guaranteed to be present in all drivers.
COMPLETE=<’>SQL-Server-connection-options<’>
specifies connection options for your data source or database. Separate
multiple options with a semicolon. When a successful connection is made, the
complete connection string is returned in the SYSDBMSG macro variable.
If you do not specify enough correct connection options, you are prompted
with a dialog box that displays the values from the COMPLETE= connection
string. You can edit any field before you connect to the data source.
See your driver documentation for more details.
NOPROMPT=<’>SQL-Server-connection-options<’>
specifies connection options for your data source or database. Separate
multiple options with a semicolon.
If you do not specify enough correct connection options, an error is
returned. No dialog box is displayed to help you with the connection string.
SAS/ACCESS for Microsoft SQL Server 4 Arguments 3
PROMPT=<’> SQL-Server-connection-options<’>
specifies connection options for your data source or database. Separate
multiple options with a semicolon. When a successful connection is made, the
complete connection string is returned in the SYSDBMSG macro variable.
PROMPT= does not immediately attempt to connect to the DBMS. Instead,
it displays a dialog box that contains the values that you entered in the
PROMPT= connection string. You can edit values or enter additional values
in any field before you connect to the data source.
REQUIRED=<’>SQL-Server-connection-options<’>
specifies connection options for your data source or database. Separate
multiple options with a semicolon. When a successful connection is made, the
complete connection string is returned in the SYSDBMSG macro variable.
If you do not specify enough correct connection options, a dialog box
prompts you for the connection options. REQUIRED= allows you to modify
only required fields in the dialog box.
The following Microsoft SQL Server connection options are not supported on UNIX:
REQUIRED=
BULKCOPY=
PROMPT=
COMPLETE=
LIBNAME-options
define how DBMS objects are processed by SAS. Some LIBNAME options can
enhance performance; others determine locking or naming behavior. The following
table describes the LIBNAME options that are supported for Microsoft SQL
Server, and presents default values where applicable. See the section about the
SAS/ACCESS LIBNAME statement in SAS/ACCESS for Relational Databases:
Reference for detailed information about these options.
ACCESS= none
AUTOCOMMIT= varies with transaction type
BL_LOG= none
CONNECTION_GROUP= none
CURSOR_TYPE= DYNAMIC
DBCONINIT= none
DBCONTERM= none
DBCREATE_TABLE_OPTS= none
DBGEN_NAME= DBMS
DBINDEX= YES
DBLIBINIT= none
DBLIBTERM= none
4 Arguments 4 Chapter 1
DBNULLKEYS= YES
DBPROMPT= NO
DBSLICEPARM= THREADED_APPS,2 or 3
DEFER= NO
DELETE_MULT_ROWS= NO
DIRECT_EXE= none
DIRECT_SQL= YES
IGNORE_ NO
READ_ONLY_COLUMNS=
INSERT_SQL= YES
INSERTBUFF= 1
KEYSET_SIZE= 0
MULTI_DATASRC_OPT= NONE
QUALIFIER= none
QUERY_TIMEOUT= 0
QUOTE_CHAR = none
READBUFF= 0
RC (see “Locking in the Microsoft SQL Server
READ_ISOLATION_LEVEL=
Interface” on page 10)
READ_LOCK_TYPE= ROW
REREAD_EXPOSURE= NO
SCHEMA= none
SPOOL= YES
STRINGDATES= NO
TRACE= NO
TRACEFILE= none
UPDATE_LOCK_TYPE= ROW
UPDATE_MULT_ ROWS= NO
UPDATE_SQL= driver specific
SAS/ACCESS for Microsoft SQL Server 4 Data Set Options for Microsoft SQL Server 5
UTILCONN_TRANSIENT= NO
In the following example, the libref MYDBLIB connects to a Microsoft SQL Server
database using the NOPROMPT= option.
libname mydblib sqlsvr
noprompt="uid=testuser;
pwd=testpass;
dsn=sqlservr;"
stringdates=yes;
Table 1.2 SAS/ACCESS Data Set Options for Microsoft SQL Server
DBCONDITION= none
DBGEN_NAME= DBMS
DBKEY= none
DBLABEL= NO
DBMASTER= none
DBMAX_TEXT= 1024
DBNULL= YES
DBSLICE= none
DBSLICEPARM= THREADED_APPS,2 or 3
ERRLIMIT= 1
IGNORE_ READ_ONLY_COLUMNS= NO
INSERT_SQL= LIBNAME option setting
NULLCHAR= SAS
NULLCHARVAL= a blank character
SASDATEFMT= none
SCHEMA= LIBNAME option setting
3 The following LIBNAME options are available with the CONNECT statement:
AUTOCOMMIT=
CURSOR_TYPE=
KEYSET_SIZE=
QUERY_TIMEOUT=
READBUFF=
READ_ISOLATION_LEVEL=
TRACE=
TRACEFILE=
USE_ODBC_CL=
3 The DBMS-SQL-query argument can be a DBMS-specific SQL EXECUTE
statement that executes a DBMS stored procedure. However, if the stored
procedure contains more than one query, only the first query is processed.
The following example uses the connection method that represents a more advanced
level of Microsoft SQL Server ODBC conformance. It uses the input dialog box that is
provided by the driver. The DSN= and UID= arguments are within the connection
string and are not parsed by the Pass-Through Facility. Instead, they are passed to the
ODBC driver manager.
proc sql;
connect to SQLSVR as user1
(required = "dsn=User’s Data; uid=testuser");
The following example enables you to select any data source that is configured on
your machine. The example uses the connection method that represents a more
advanced level of Microsoft SQL Server ODBC conformance, Level 1. When a successful
connection is made, the connection string is returned in the SQLXMSG and
SYSDBMSG macro variables and can be stored if this method is used to configure a
connection for later use.
proc sql;
connect to SQLSVR (required);
The following example prompts you to specify the information that is required to
make a connection to the DBMS. You are prompted to supply the data source name,
user ID, and password in the dialog boxes that are displayed.
proc sql;
connect to SQLSVR (prompt);
serve as a virtual table for the PROC SQL FROM clause. In this example, MYDB is the
connection alias.
proc sql;
connect to SQLSVR as mydb
(datasrc="SQL Server" user=testuser password=testpass);
select * from connection to mydb
(select CUSTOMER, NAME, COUNTRY
from CUSTOMERS
where COUNTRY <> ’USA’);
quit;
The following example returns a list of the columns in the CUSTOMERS table.
proc sql;
connect to SQLSVR as mydb
(datasrc = "SQL Server" user=testuser password=testpass);
select * from connection to mydb
(ODBC::SQLColumns (, , "CUSTOMERS"));
quit;
Examples
The following example creates a new Microsoft SQL Server table,
TESTUSER.EXCHANGE, from the DLIB.RATEOFEX data file. You must be granted
the appropriate privileges in order to create new Microsoft SQL Server tables or views.
proc dbload dbms=SQLSVR data=dlib.rateofex;
dsn=sample;
user=’testuser’;
password=’testpass’;
table=exchange;
rename fgnindol=fgnindollars
4=dollarsinfgn;
nulls updated=n fgnindollars=n
dollarsinfgn=n country=n;
load;
run;
The following example only sends a Microsoft SQL Server SQL GRANT statement to
the SAMPLE database and does not create a new table. Therefore, the TABLE= and
LOAD statements are omitted.
proc dbload dbms=SQLSVR;
user=’testuser’;
password=’testpass’;
dsn=sample;
sql grant select on testuser.exchange
to dbitest;
run;
MAX
SIGN
SIN
SQRT
TAN
UPCASE
SUM
COUNT
RR (repeatable read) Does not allow dirty reads or nonrepeatable reads; does
allow phantom reads.
RC (read committed) Does not allow dirty reads or nonrepeatable reads; does
allow phantom reads.
RU (read uncommitted) Allows dirty reads, nonrepeatable reads and phantom reads.
Table 1.4 Microsoft SQL Server Data Types and Default SAS Formats
SQL_CHAR $n
SQL_VARCHAR $n
SQL_LONGVARCHAR $n
12 Microsoft SQL Server Null Values 4 Chapter 1
SQL_BINARY $n.*
SQL_VARBINARY $n.*
SQL_LONGVARBINARY $n.*
SQL_INTEGER 11.
SQL_SMALLINT 6.
SQL_TINYINT 4.
SQL_BIT 1.
SQL_REAL none
SQL_FLOAT none
SQL_DOUBLE none
SQL_BIGINT 20.
SQL_DATE DATE9.
SQL_TIME TIME8.
Microsoft SQL Server cannot support fractions
of seconds for time values
* Because the Microsoft SQL Server driver does the conversion, this field is displayed as though
the $HEXn. format were applied.
The following table shows the default data types that the interface to Microsoft SQL
Server uses when creating tables.
The interface to Microsoft SQL Server allows nondefault data types to be specified
with the DBTYPE= data set option.
Note: To control how SAS missing character values are handled by Microsoft SQL
Server, use the NULLCHAR= and NULLCHARVAL= data set options. 4
14
15
APPENDIX
1
Recommended Reading
Recommended Reading 15
Recommended Reading
Customers outside the United States should contact their local SAS office.
16
17
Glossary
This glossary defines SAS software terms that are used in this document as well as
terms that relate specifically to SAS/ACCESS software.
access descriptor
a SAS/ACCESS file that describes data that is managed by a data management
system. After creating an access descriptor, you can use it as the basis for creating
one or more view descriptors. See also view and view descriptor.
browsing data
the 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 a
tabular format. You cannot update data that you are browsing.
bulk load
to load large amounts of data into a database object, using methods that are specific
to a particular DBMS. Bulk loading enables you to rapidly and efficiently add
multiple rows of data to a table as a single unit.
client
(1) a computer or application that requests services, data, or other resources from a
server. (2) in the X Window System, an application program that interacts with the X
server 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 be
displayed, and so on.
column
in relational databases, a vertical component of a table. Each column has a unique
name, contains data of a specific type, and has certain attributes. A column is
analogous to a variable in SAS terminology.
column function
an operation that is performed for each value in the column that is named as an
argument of the function. For example, AVG(SALARY) is a column function.
commit
the process that ends a transaction and makes permanent any changes to the
database that the user made during the transaction. When the commit process
occurs, locks on the database are released so that other applications can access the
changed data. The SQL COMMIT statement initiates the commit processs.
18 Glossary
libref
a name that is temporarily associated with a SAS data library. The complete name of
a SAS file consists of two words, separated by a period. The libref, which is the first
word, indicates the library. The second word is the name of the specific SAS file. For
example, in VLIB.NEWBDAY, the libref VLIB tells SAS which library contains the
file NEWBDAY. You assign a libref with a LIBNAME statement or with an operating
system command.
member
a SAS file in a SAS data library.
member name
a name that is given to a SAS file in a SAS data library.
member type
a SAS name that identifies the type of information that is stored in a SAS file.
Member types include ACCESS, DATA, CATALOG, PROGRAM, and VIEW.
missing value
in SAS, a term that describes the contents of a variable that contains no data for a
particular row or observation. By default, SAS prints or displays a missing numeric
value as a single period, and it prints or displays a missing character value as a
blank space.
observation
a row in a SAS data set. All of the data values in an observation are associated with
a single entity such as a customer or a state. Each observation contains one data
value for each variable. In a database product table, an observation is analogous to a
row. Unlike rows in a database product table or file, observations in a SAS data file
have an inherent order.
Pass-Through Facility
a group of SQL procedure statements that send and receive data directly between a
relational database management system and SAS. The Pass-Through Facility
includes the CONNECT, DISCONNECT, and EXECUTE statements, and the
CONNECTION TO component. SAS/ACCESS software is required in order to use
the Pass-Through Facility.
query
a set of instructions that requests particular information from one or more data
sources.
20 Glossary
referential integrity
a set of rules that a DBMS uses to ensure that whenever a data value in one table is
changed, the appropriate change is also made to any related values in other tables or
in the same table. Referential integrity is also used to ensure that related data is not
deleted or changed accidentally.
relational database management system
a database management system that organizes and accesses data according to
relationships between data items. Oracle and DB2 are examples of relational
database management systems.
rollback
in most databases, the process that restores the database to its state when changes
were last committed, voiding any recent changes. The SQL ROLLBACK statement
initiates the rollback processes. See also commit.
row
in relational database management systems, the horizontal component of a table. A
row is analogous to a SAS observation.
SAS data file
a type of SAS data set that contains data values as well as descriptor information
that is associated with the data. The descriptor information includes information
such as the data types and lengths of the variables, as well as the name of the engine
that was used to create the data. A PROC SQL table is a SAS data file. SAS data
files are of member type DATA.
SAS data library
a collection of one or more SAS files that are recognized by SAS and that are
referenced and stored as a unit. Each file is a member of the library.
SAS data set
a file whose contents are in one of the native SAS file formats. There are two types of
SAS data sets: SAS data files and SAS data views. SAS data files contain data
values in addition to descriptor information that is associated with the data. SAS
data views contain only the descriptor information plus other information that is
required for retrieving data values from other SAS data sets or from files whose
contents are in other software vendors’ file formats.
SAS data view
a file whose contents are in one of the native SAS file formats. There are two types of
SAS data sets: SAS data files and SAS data views. SAS data files contain data
values in addition to descriptor information that is associated with the data. SAS
data views contain only the descriptor information plus other information that is
required for retrieving data values from other SAS data sets or from files whose
contents are in other software vendors’ file formats.
SAS/ACCESS views
See view descriptor and SAS data view.
server
in a network, a computer that is reserved for servicing other computers in the
network. Servers can provide several different types of services, such as file services
and communication services. Servers can also enable users to access shared
resources such as disks, data, and modems.
Structured Query Language (SQL)
the standardized, high-level query language that is used in relational database
management systems to create and manipulate database management system
objects. SAS implements SQL through the SQL procedure.
Glossary 21
table
a two-dimensional representation of data, in which the data values are arranged in
rows and columns.
trigger
a type of user-defined stored procedure that is executed whenever a user issues a
data-modification command such as INSERT, DELETE, or UPDATE for a specified
table or column. Triggers can be used to implement referential integrity or to
maintain business constraints.
variable
a column in a SAS data set. A variable is a set of data values that describe a given
characteristic across all observations.
view
a definition of a virtual data set. The definition is named and stored for later use. A
view contains no data; it merely describes or defines data that is stored elsewhere.
SAS data views can be created by the ACCESS and SQL procedures.
view descriptor
a file created by SAS/ACCESS software that defines part or all of the database
management system (DBMS) data or PC file data that is described by an access
descriptor. The access descriptor describes the data in a single DBMS table, DBMS
view, or PC file.
wildcard
a file created by SAS/ACCESS software that defines part or all of the database
management system (DBMS) data or PC file data that is described by an access
descriptor. The access descriptor describes the data in a single DBMS table, DBMS
view, or PC file.
22
Index 23
Index
A E nonrepeatable reads 11
NOPROMPT= option, LIBNAME statement
access descriptors 17 editing data, defined 18
Microsoft SQL Server 2
engine, defined 18
NULL values
Microsoft SQL Server 12
B
F
browsing data, defined 17
bulk loading 17 files, defined 18 O
observations 19
C I
client, defined 17 indexes 18 P
commit, defined 17 informats, defined 18
COMPLETE= option, LIBNAME statement interface view engine, defined 19 Pass-Through Facility 19
Microsoft SQL Server 2 Microsoft SQL Server specifics 6
CONNECT statement, SQL procedure PASSWORD= option, LIBNAME statement
options, Microsoft SQL Server 7
CONNECTION TO component, SQL SELECT
L Microsoft SQL Server 2
statement PASSWORD= option, PROC DBLOAD statement
LIBNAME statement
Microsoft SQL Server 7 Microsoft SQL Server 8
Microsoft SQL Server specifics 1
librefs phantom reads 11
defined 19 PROMPT= option, LIBNAME statement
D locking data, handling Microsoft SQL Server 3
Microsoft SQL Server interface 10
data files
defined 20
data libraries, defined 20 Q
data set options M
queries, SQL
Microsoft SQL Server specifics 3
Microsoft SQL Server, interface to 1 defined 19
data sets
CONNECT statement options (SQL proce-
defined 20
dure) 7
DATA step
data set options 3
views, defined 18
data types 11 R
data types 18
DBLOAD procedure 7 RDMS (relational database management sys-
Microsoft SQL Server 11
LIBNAME statement 1 tem) 20
data views, defined 20
databases, defined 18 locking in 10
READ_ISOLATION_LEVEL= option
DATASRC= option, LIBNAME statement naming conventions 11
Pass-Through Facility 6 Microsoft SQL Server interface 10
Microsoft SQL Server 2
passing SAS functions to 9 READ_LOCK_TYPE= option
DBLOAD procedure
Microsoft SQL Server specifics 7 missing values Microsoft SQL Server interface 10
DBMS data 17 defined 19 referential integrity, defined 20
DBMS (database management systems), de- REQUIRED= option, LIBNAME statement
fined 18 Microsoft SQL Server 3
dirty reads 10 N rollbacks, defined 20
DSN= option
LIBNAME statement 2 naming conventions rows, table
PROC DBLOAD statement 8 Microsoft SQL Server 11 defined 20
24 Index