Accessing Oracle Data Through Sas
-
Upload
kariadan-sarosh -
Category
Documents
-
view
239 -
download
1
Transcript of Accessing Oracle Data Through Sas
![Page 1: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/1.jpg)
Accessing ORACLE data through SAS
Susanne Young
Bank One
![Page 2: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/2.jpg)
Overview
You need to use SAS to access data stored in Oracle tables or views
![Page 3: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/3.jpg)
Options
LIBNAME statement pass-thru SQL query
![Page 4: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/4.jpg)
LIBNAME statement
LIBNAME MYORALIB ORACLE USER=MYUID PW=MYPASSWORD PATH='@OraInfo' SCHEMA=MYSCHEMA;
![Page 5: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/5.jpg)
LIBNAME statement
14 LIBNAME MYORALIB ORACLE USER=MYUID PW=XXXXXXX PATH='@OraInfo' SCHEMA=MYUID
NOTE: Libref MYORALIB was successfully assigned as follows:
Engine: ORACLE Physical Name: @OraInfo
![Page 6: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/6.jpg)
LIBNAME statement
![Page 7: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/7.jpg)
LIBNAME statement
PROC PRINT DATA=MYORALIB.NBR_DAYS_TO_DATE_LKUP;
RUN;
![Page 8: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/8.jpg)
LIBNAME statement
Helpful Info Automatic macro variables
&sysdbmsg displays the DBMS error messages58 %put &sysdbmsg;ORACLE: ORA-01017: invalid username/password; logon denied
&sysdbrc displays the DBMS error codes59 %put &sysdbrc;-1017
![Page 9: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/9.jpg)
Sql pass thru query
PROC SQL;
CONNECT TO ORACLE(USER=MYUID ORAPW=MYPASSWORD PATH='@OraInfo');
SELECT * FROM CONNECTION TO ORACLE
(SELECT * FROM MYSCHEMA.NBR_DAYS_TO_DATE_LKUP);
DISCONNECT FROM ORACLE;
QUIT;
![Page 10: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/10.jpg)
Sql pass thru query
![Page 11: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/11.jpg)
Sql pass thru query
Execute statement execute (grant select on
MYSCHEMA.MY_TABLE to OTHERUID) by oracle;execute (execute credit(234,5000)) by oracle; execute (create unique index my_pk on
MYUID.MY_TABLE (MYFIELD) ) by oracle;Execute (drop table MYUID.MY_TABLE) by oracle;
![Page 12: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/12.jpg)
Sql pass thru query
Automatic macro variables&sqlxmsg displays the DBMS error messages
64 %put &SQLXMSG;ORA-12560: TNS:protocol adapter error
&sqlxrc displays the DBMS error codes65 %put &SQLXRC;-12560
![Page 13: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/13.jpg)
What you need to know
Path= option
![Page 14: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/14.jpg)
What you need to know
![Page 15: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/15.jpg)
What you need to know
Schema = option In Microsoft Access, when connecting to Oracle tables, the
Schema name is identified as the text to the left of the period.
The best way to find out is to go to the source, your Oracle DBA
![Page 16: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/16.jpg)
Error Messages
The service you’re referencing is not configured in your sqlnet.ora file.ERROR: ORACLE connection error: ORA-12154: TNS:could
not resolve service name.
ERROR: Error in the LIBNAME statement.
You do not have SAS/Access for ORACLE or it’s not configured properlyERROR: The SAS/ACCESS Interface to ORACLE cannot be
loaded. The SASORA code appendage could not be loaded.
ERROR: Error in the LIBNAME statement.
![Page 17: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/17.jpg)
Error Messages
You’ve entered your User ID or password incorrectly or it’s expired.ERROR: ORACLE connection error: ORA-01017: invalid
username/password; logon denied.
ERROR: Error in the LIBNAME statement.
![Page 18: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/18.jpg)
Options
The following option statement causes information about the query that is being passed to Oracle to be printed in the SAS log, so you can see the logic being passed.
Options SASTRACE= ‘,,,d’ SASTRACELOC=SASLOG;
![Page 19: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/19.jpg)
Alternatives
So what if I don’t have SAS/Access for Oracle?
![Page 20: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/20.jpg)
Using ODBC drivers
Syntax for Libname statement LIBNAME MYORALIB ODBC DSN=MyOracle UID=MYUID PW=MYPASSWORD SCHEMA=MYSCHEMA;
Syntax for pass-thru SQL query PROC SQL; CONNECT TO ODBC(DSN=MyOracle UID=MYUID PW=MYPASSWORD);
SELECT * FROM CONNECTION TO ODBC (SELECT * FROM FIN1MGR.NBR_DAYS_TO_DATE_LKUP);
DISCONNECT FROM ODBC; QUIT;
![Page 21: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/21.jpg)
Conclusion
SAS offers a variety of ways to access data that is stored in Oracle.
Work with your Oracle DBA to assistance with connection questions.
Utilize the numerous Users Group papers on the subject of methods and efficiencies accessing Oracle data.
![Page 22: Accessing Oracle Data Through Sas](https://reader034.fdocuments.us/reader034/viewer/2022050705/5501e8a34a795974588b529a/html5/thumbnails/22.jpg)
References
SUGI 27 Data Warehousing and Enterprise Solutions Can’t Relate? A Primer on using SAS with your relational database
Garth Helf, IBM Corporation
SUGI 26 Advanced Tutorials Database Access Using the SAS System
Frederic Pratter, Computer Science Department, University of Montana Missoula
SUGI 28 Advanced Tutorials SAS/ACCESS to External Databases: Wisdom for the Warehouse User
Judy Loren, Health Dialog Data Service, Inc
SUGI 27 Advanced Tutorials Reading From Alternate Sources: What To Do When The Input Is Not a Flat File
Michael Davis, Bassett Consulting Services