user9218778
user9218778

Reputation: 11

SAS Access/Interface with SQL server

I am having a problem with connecting to data in SQL database.

I am not sure if I don't have the certain driver or if the code I am using is incorrect. Could someone please help guide me in the right direction?

  1. Below is the product license that I have after running Proc Setinit

Operating System: WX64_WKS.

Product expiration dates:

---Base SAS Software
14FEB2018
---SAS/STAT
14FEB2018
---SAS/GRAPH
14FEB2018
---SAS/Secure 168-bit
14FEB2018
---SAS/Secure Windows
14FEB2018
---SAS Enterprise Guide
14FEB2018
---SAS/ACCESS Interface to PC Files
14FEB2018
---SAS/ACCESS Interface to Microsoft SQL Server
31DEC2017
---SAS Workspace Server for Local Access
14FEB2018
---SAS/ACCESS to Amazon Redshift
31DEC2017
---High Performance Suite
14FEB2018
  1. Below is product installed after I ran Proc Product_Status

16 proc Product_Status ; run;

For Base SAS Software ...
Custom version information: 9.4_M5
Image version information: 9.04.01M5P090617
For SAS/STAT ...
Custom version information: 14.3
For SAS/GRAPH ...
Custom version information: 9.4_M5
For SAS/ACCESS to Amazon Redshift ...
Custom version information: 9.42
For High Performance Suite ...
Custom version information: 2.2_M6
For SAS/ACCESS Interface to PC Files ...
Custom version information: 9.4_M5
NOTE: PROCEDURE PRODUCT_STATUS used (Total process time):
real time 0.24 seconds

It seems like sas access to SQL server is not installed right?

I am also trying these codes to connect and all got the error. Which direction of code should I be using? ODBC or sqlsvr?

I tried sqlsvr and got this error message

Code:

LIBNAME database1 sqlsvr user=datareader password=myspassword DATAsrc=clientA;

Error:

LIBNAME database1 sqlsvr user=datareader password=XXXXXXX DATAsrc=clientA;

ERROR: CLI error trying to establish connection: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ERROR: Error in the LIBNAME statement.

When I tried ODBC route, I got this message

Code:

LIBNAME database1 ODBC DSN=clientA User=datareader Password=myspassword ;

Error:

LIBNAME database1 ODBC DSN=clientA User=datareader Password=XXXXXXX;

ERROR: The ODBC engine cannot be found. ERROR: Error in the LIBNAME statement.

Could someone please point me in the right direction? Should DSN be the name of the database of each client as "ClientA" etc or should it be the name of the server?

Thank you so much!

Upvotes: 1

Views: 3390

Answers (1)

Richard
Richard

Reputation: 27508

The SQLSRV library engine DATASRC= option should specify an entry shown in the "ODBC Data Source Administrator (64-bit)" application. You can add an entry, set (configure) the connection parameters and test the connection. Suppose you name your new DSN Sales History, the libname might be

libname OldSales sqlsrv datasrc="Sales History" user=... pass=...;

For the case of wanting to specify the server name, schema, port, connection persistence, etcetera directly in your SAS code you would use the NOPROMPT= option. The option value will be a semi-colon separated list of name=value pairs:

libname OldSales sqlsrv user=... pass=... noprompt="Server=<url or hostname><\instance-name-if-other-than-default>,<port-number-if-other-than-default>;Initial Catalog=<database-to-use-if-other-than-default>;..other connection parameters..";

Microsoft documentation "Using Connection String Keywords with SQL Server Native Client" is a great reference. Another good resource for examples is connectionstrings website. A NOPROMPT= value that seems correct, yet is not to working, may have or require unusual spacing or quoting.

For a small group of coders in a static data hosting environment the NOPROMPT= method will probably be OK and require no extra support (other than access) in a large organization. If the data hosting migrates or changes your SAS code will have to be changed.

In a larger context, especially in a SAS Server environment, you are best off having your IT support to create the DSNs that your SAS sessions will need. The DSNs will be the single gateway that all programs and users will use and coders and analysts will not have to get bogged down in the connection details.

Upvotes: 1

Related Questions