Accessing a Microsoft SQL Server Database from SAS on Microsoft Windows



Similar documents
Technical Paper. Defining an ODBC Library in SAS 9.2 Management Console Using Microsoft Windows NT Authentication

Define ODBC Database Library using Management Console

Defining an OLEDB Library in SAS Management Console Using Windows Authentication

Migrating helpdesk to a new server

Video Administration Backup and Restore Procedures

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

Voyager Reporting System (VRS) Installation Guide. Revised 5/09/06

Outlook Profile Setup Guide Exchange 2010 Quick Start and Detailed Instructions

Linking Access to SQL Server

CIMHT_006 How to Configure the Database Logger Proficy HMI/SCADA CIMPLICITY

Querying Databases Using the DB Query and JDBC Query Nodes

Database Assistant. Once Database Assistant is installed you must login to gain access to the database. Copyright 2009

Connecting to SQL server

MICROSTRATEGY 9.3 Supplement Files Setup Transaction Services for Dashboard and App Developers

SQL Server Setup for Assistant/Pro applications Compliance Information Systems

Installing Cobra 4.7

Creating a System DSN for Crystal Reports to Access a Sentinel Server Database. Configuration Guide Version 1.0

Implementing Microsoft SQL Server 2008 Exercise Guide. Database by Design

Setting up a database for multi-user access

How To Use Exhange On Outlook On A Pc Or Macintosh Outlook 2007 On Your Pc Or Ipad (For Windows Xp) On Your Ipad Or Ipa (For Your Windows Xp). (For A Macintosh) On A

2. Unzip the file using a program that supports long filenames, such as WinZip. Do not use DOS.

Crystal Reports Installation Guide

RE:Open for SQL Anywhere. Installation Guide. RE:Open for SQL Anywhere Installation Guide 1

Windows XP Exchange Client Installation Instructions

Release Notes For Versant/ODBC On Windows. Release

How to set up Outlook Anywhere on your home system

How to Connect to CDL SQL Server Database via Internet

TAMUS Terminal Server Setup BPP SQL/Alva

The purpose of this document is to describe how to connect Crystal Reports with BMC Remedy AR System using ODBC.

System Area Management Software Tool Tip: Integrating into NetIQ AppManager

SPECIALIST PRACTICE MANAGER

Installing SQL Express. For CribMaster 9.2 and Later

Creating a User Profile for Outlook 2013

How to Move an SAP BusinessObjects BI Platform System Database and Audit Database

SAS 9.3 Drivers for ODBC

Setting Up ALERE with Client/Server Data

Access to Relational Databases Using SAS. Frederick Pratter, Destiny Corp.

Converting InfoPlus.21 Data to a Microsoft SQL Server 2000 Database

ODBC Chapter,First Edition

Active Directory Integration for Greentree

Microsoft Office 365 Exchange Online Cloud

Configuring Color Access on the WorkCentre 7120 Using Microsoft Active Directory Customer Tip

National Fire Incident Reporting System (NFIRS 5.0) Configuration Tool User's Guide

How To Create An Easybelle History Database On A Microsoft Powerbook (Windows)

SELF SERVICE RESET PASSWORD MANAGEMENT DATABASE REPLICATION GUIDE

Connecting to Manage Your MS SQL Database

Download and Installation of MS SQL Server

STATISTICA VERSION 9 STATISTICA ENTERPRISE INSTALLATION INSTRUCTIONS FOR USE WITH TERMINAL SERVER

Exchange Outlook Profile/POP/IMAP/SMTP Setup Guide

1. Open the preferences screen by opening the Mail menu and selecting Preferences...

Customer Tips. Configuring Color Access on the WorkCentre 7328/7335/7345 using Windows Active Directory. for the user. Overview

Installation Guide v3.0

Versions Addressed: Microsoft Office Outlook 2010/2013. Document Updated: Copyright 2014 Smarsh, Inc. All right reserved

SpectraPro. SLQ Server databases

# or ## - how to reference SQL server temporary tables? Xiaoqiang Wang, CHERP, Pittsburgh, PA

How to Configure Outlook Client for Exchange

ODBC Group Policy Settings

Client configuration and migration Guide Setting up Thunderbird 3.1

WorldShip Export Shipment Data

Connect to MySQL or Microsoft SQL Server using R

Creating IBM Cognos Controller Databases using Microsoft SQL Server

Sage Intelligence Financial Reporting for Sage ERP X3 Version 6.5 Installation Guide

ReportBy ODBC Connection setup

SQL Tuning and Maintenance for the Altiris Deployment Server express database.

VPN Overview. The path for wireless VPN users

Installation Instruction STATISTICA Enterprise Small Business

Getting Your Data into SAS

for Networks Installation Guide for the application on the server August 2014 (GUIDE 2) Lucid Exact Version 1.7-N and later

Microsoft Business Intelligence 2012 Single Server Install Guide

How to Copy A SQL Database SQL Server Express (Making a History Company)

Setting Up Your Team-SQL Database for ORACLE 8.05

Outlook 2010 Setup Guide (POP3)

for Networks Installation Guide for the application on the server July 2014 (GUIDE 2) Lucid Rapid Version 6.05-N and later

Matisse Installation Guide for MS Windows. 10th Edition

XMailer Reference Guide

Creating a New Database and a Table Owner in SQL Server 2005 for exchange@pam

Migrating a Database from Legi for Windows 2.X to MS Access

STATISTICA VERSION 12 STATISTICA ENTERPRISE SMALL BUSINESS INSTALLATION INSTRUCTIONS

The manual contains complete instructions on 'converting' your data to version 4.21.

Jolly Server Getting Started Guide

OpenScape Business V2

Insight Video Net. LLC. CMS 2.0. Quick Installation Guide

Archive Server for MDaemon disaster recovery & database migration

Snow Inventory. Installing and Evaluating

PaperClip. em4 Cloud Client. Manual Setup Guide

Step 2: Open the ODBC Data Source Administrator Panel

BUSINESS CLASS POP3 END USER GUIDE TIME WARNER CABLE BUSINESS SERVICES VERSION 1.0, RELEASE 1.2

ilaw Installation Procedure

Team Foundation Server 2012 Installation Guide

PROJECTIONS SUITE. Database Setup Utility (and Prerequisites) Installation and General Instructions. v0.9 draft prepared by David Weinstein

WhatsUp Gold v16.3 Installation and Configuration Guide

Using Windows Task Scheduler instead of the Backup Express Scheduler

TECHNICAL NOTE. The following information is provided as a service to our users, customers, and distributors.

ODBC Driver Version 4 Manual

Fax User Guide 07/31/2014 USER GUIDE

How to Pop to Outlook

Ektron CMS100 Web Hosting Edition Installation Manual, Version 1.0

ACCESSING IBM iseries (AS/400) DB2 IN SSIS

Transcription:

Accessing a Microsoft SQL Server Database from SAS on Microsoft Windows On Microsoft Windows, you have two options to access a Microsoft SQL Server database from SAS. You can use either SAS/Access Interface to ODBC, or SAS/Access to OLEDB. Submitting the following code from within SAS displays all the licensed products for your site in the SAS log window: Proc setinit noalias; Run; If you have one or both of the Access products licensed for your site, the next step is to determine if the products have been installed on your machine. From Windows Explorer, you can browse to!sasroot\access\sasexe and look for the following files: 1) sasioodb.dll the presence of this file means that SAS\Access Interface to ODBC is installed on your machine. 2) sasioole.dll - the presence of this file means that SAS\Access Interface to OLEDB is installed on your machine. Depending on how SQL Server is set up, you can connect using either SQL Server Authentication or NT Authentication. Using SAS/Access to ODBC or SAS/Access to OLEDB with each authentication method will be discussed below. SAS/Access to ODBC: SQL Server Authentication: To set up an ODBC Data Source, select the Start Menu, click on Settings Control Panel and choose Administrative Tools. From there, choose Data Sources (ODBC). This will open the Data Source Administrator.

Choose the User or System DSN tab and select Add to add a new data source. Select the SQL Server driver and click Finish. The next window allows you to enter a name for the data source, an optional description, and the server you want to connect to.

Choose SQL Server authentication as shown below and enter the SQL server login ID and password. Click on Next.

The next 2 screens will allow for further server configurations, such as changing the default database, creating temporary stored procedures, changing the language of SQL server system messages, etc. Once you click the Finish button, you will see a summary window of the configurations you chose, and you can try a test connection to see if the configurations are valid.

If everything is set up properly, the test connection will be successful. Click OK to exit out of the SQL Server setup and Administrator.

Once the driver has been configured and the test connection is successful, then you can use a LIBNAME statement to create a library within SAS: LIBNAME SQL ODBC DSN= sql server user=sasjlb pw=pwd; Where 'sql server' is the name of the Data Source configured in the ODBC Administrator. Using NT Authentication: To setup an ODBC data source, select the Start Menu, click on Settings Control Panel and choose Administrative Tools. From there, choose Data Sources (ODBC). This will open the Data Source Administrator. Choose the User or System DSN tab and select Add to add a new data source. Select the SQL Server driver and click Finish.

The next window allows you to enter a name for the data source, an optional description, and the server you want to connect to. Click on Next. Choose NT authentication as shown below and click on Next.

The next 2 screens will allow for further server configurations, such as changing the default database, creating temporary stored procedures, changing the language of SQL server system messages, etc.

Once you click the Finish button, you will see a summary window of the configurations you chose, and you can try a test connection to see if the configurations are valid.

If everything is set up properly, the test connection will be successful. Click OK to exit out of the SQL Server setup and Administrator. Once the driver has been configured and the test connection is successful, then you can use a LIBNAME statement to create a library within SAS: LIBNAME SQL ODBC DSN= sqlsrv_nt ; Where 'sqlsrv_nt' is the name of the Data Source configured in the ODBC Administrator. Prompted connection: If you aren't sure what values to add for the userid, password and data source, you can try connecting with a prompted connection. A prompted connection just means you are prompted to enter the above information instead of supplying it on the LIBNAME statement. Submit the following 2 lines of code: libname sql odbc prompt; %put %superq(sysdbmsg); /* V9 syntax */ %put &sysdbmsg; /* V8 syntax */ The Select Datasource window will open. If you created a user or system DSN, you will need to select the Machine Data Source tab. Choose the appropriate DSN, and click on

Okay. Enter your SQL Server login id and password. Once you have connected, several parameters will be written to the log window. An example is below: LIBNAME SQL ODBC prompt; NOTE: Libref SQL was successfully assigned as follows: Engine: ODBC Physical Name: sqlsrv 7 %put %superq(sysdbmsg); ODBC: DSN=sqlsrv;UID=jebjur;PWD=jebjur1;WSID=d17117 You can cut and paste everything after 'ODBC:' and place it on the LIBNAME statement with a NOPROMPT= option as such: /* SQL Server Authentication */ LIBNAME SQL ODBC noprompt= "dsn=sqlsrv; uid=sasjlb; pwd=pwd; wsid=d17117"; /* NT Authentication */ LIBNAME SQL ODBC noprompt= dsn=sqlsrv_nt;wsid=d17117; Trusted_Connection=Yes "; Schemas: SQL Server database tables are organized in schemas, which are equivalent to database users or owners. In order to see particular tables in a defined library, you may need to add the SCHEMA= option to the LIBNAME statement. If no schema is specified, SAS will look in the current userid s schema by default. For example: LIBNAME SQL ODBC DSN=sqlsrv user=sasjlb pw=pwd schema=dbo; If you aren t sure what schema your tables are contained in, you can use one of the following methods to find it: 1) Use SAS Query Window: from the Tools -> Query menu. when the Query Window has loaded, go to Tools Switch Access Mode - ODBC. Then select your datasource and respond to any prompts that pop up. When you are connected, you will see a list of available tables from your odbc datasource. The tables are two-level names such as dbo.table1. The first level (dbo) is the schema. 2) Use PROC SQL passthrough method:

This method will create a temporary data set with the list of available tables in the database. The TABLE_SCHEM variable will contain the schema. /* SQL Server Authentication */ proc sql; connect to odbc (dsn=sqlsrv user=user pwd=xxxxx); create table test as select * from connection to odbc(odbc::sqltables); quit ; /* NT Authentication */ proc sql; connect to odbc (dsn= sqlsrv_nt ); create table test as select * from connection to odbc(odbc::sqltables); quit ; Importing Data: Once the LIBNAME statement has been successfully assigned, you can use either DATA step or PROC SQL logic to import the data in a SQL Server table, just as you would with a permanent SAS data set. For ex: LIBNAME SQL ODBC DSN= sql server user=sasjlb pw=pwd; DATA NEW; SET SQL.TABLE1; RUN; PROC SQL; CREATE TABLE NEW AS SELECT * FROM SQL.TABLE1; QUIT; You can also use PROC SQL passthrough with SAS/Access to ODBC. The query would look similar to: /* SQL Server Authentication */ proc sql; connect to odbc (dsn=sqlsrv user=user pwd=xxxxx); create table test as select * from connection to odbc(select * from table2); quit ; /* NT Authentication */

proc sql; connect to odbc(dsn= sqlsrv_nt ); create table new as select * from connection to odbc(select * from table2); quit; SAS/Access to OLEDB: SQL Server Authentication: With SAS/Access to OLEDB, you do not have to configure the data provider. The LIBNAME statement would look similar to: LIBNAME sqlsrv oledb init_string="provider=sqloledb.1;password=pwd; Persist Security Info=True;User ID=user;Data Source=sqlserv"; Using NT Authentication: With NT authentication, The LIBNAME statement would look similar to: LIBNAME sqlsrv oledb init_string="provider=sqloledb.1; Integrated Security=SSPI;Persist Security Info=True; Initial Catalog=northwind;Data Source=steak"; Prompted Connection: If you aren't sure what values to add for the userid, password and data source (=server name), then you can try connecting with a prompted connection. A prompted connection just means you are prompted to enter the above information instead of supplying it on the LIBNAME statement. Submit the following 2 lines of code: libname sqlsrv oledb; %put %superq(sysdbmsg); /* V9 syntax */ %put &sysdbmsg; /* V8 syntax */ * in the pop up window, select "Microsoft OLE DB Provider for SQL Server," * select "Next: * enter the Data Source name (server) * select the "Use a specific user name and password" radio button, and enter the appropriate username and password. * Enter the name of a database on the server you wish to connect to (optional). * select "Test Connection" and made sure it established a connection * select "OK" to exit the pop up. If a connection was established, you

should see a note in the SAS log that says the LIBNAME statement was successfully assigned. If you then want to do an unprompted connection, then do the following: * The connection parameters were then written to the log due to the following line: %put %superq(sysdbmsg); * which wrote the following to the Log: OLEDB: Provider=SQLOLEDB.1;Password=pwd;Persist Security Info=True; User ID=user;Data Source=sqlserv In order to create a LIBNAME statement such as the one above, you can cut and paste the connection parameters that were written to the log (everything after the OLEDB: string) and add them to the LIBNAME statement with an INIT_STRING= option. The final LIBNAME statement looks like: /* SQL Server Authentication */ LIBNAME sqlsrv oledb init_string="provider=sqloledb.1;password=pwd; Persist Security Info=True;User ID=user;Data Source=sqlserv"; /* NT Authentication */ LIBNAME sqlsrv oledb init_string="provider=sqloledb.1;integrated Security=SSPI; Persist Security Info=True;Initial Catalog=northwind;Data Source=steak ; If the connection is successful, you can go to the SAS Explorer window, click on the library and see the tables on the server. Schemas: If the LIBNAME statement connected successfully but there are no tables in the library, a schema may be needed on the LIBNAME statement as well. If you need to find a schema for a table with SAS/Access to OLEDB, you can use the PROC SQL passthrough code below. This method will create a temporary data set with the list of available tables in the database. The TABLE_SCHEMA variable will contain the schema. proc sql; connect to oledb; create table tabs as select * from connection to oledb(oledb::tables); quit;

Once you find the appropriate schema value, you would add it to the the LIBNAME statement with the SCHEMA= option. The LIBNAME statement would look similar to the following: /* SQL Server Authentication */ LIBNAME sqlsrv oledb init_string="provider=sqloledb.1;password=pwd; Persist Security Info=True;User ID=user;Data Source=sqlserv" schema=dbo; /* NT Authentication */ LIBNAME sqlsrv oledb init_string="provider=sqloledb.1;integrated Security=SSPI; Persist Security Info=True;Initial Catalog=northwind;Data Source=steak schema=dbo; Importing Data: Once the LIBNAME statement has been successfully assigned, you can use either DATA step or PROC SQL logic to import the data in a SQL Server table, just as you would with a permanent SAS data set. For ex: LIBNAME sqlsrv oledb init_string="provider=sqloledb.1;password=pwd; Persist Security Info=True;User ID=user;Data Source=sqlserv" DATA NEW; SET SQLSRV.TABLE1; RUN; PROC SQL; CREATE TABLE NEW AS SELECT * FROM SQLSRV.TABLE1; QUIT; You can also use PROC SQL passthrough with SAS/Access to OLEDB. The query would look similar to: /* SQL Server Authentication */ proc sql; connect to oledb (init_string=" Provider=SQLOLEDB.1;Password=pwd; Persist Security Info=True;User ID=user;Data Source=sqlserv" schema=dbo); select * from connection to oledb (select * from class); quit; /* NT Authentication */

proc sql; connect to oledb (init_string="provider=sqloledb.1;integrated Security=SSPI; Persist Security Info=True;Initial Catalog=northwind;Data Source=steak schema=dbo); select * from connection to oledb (select * from class); quit; Resources: SAS/Access 9.1 Interface to Relational Databases: Reference can be found at the following URL: http://support.sas.com/onlinedoc/913/docmainpage.jsp