BookmarkSubscribeRSS Feed
StickyRoll
Fluorite | Level 6

I have an ODBC connection that connects to Oracle Database.

 

In SAS, i connect to this ODBC connection with the following statement.

libname staging oracle authdomain="OracleAuth" path='dubaiserver.sas.com';

 

What I want to do is to not hardcode the username, password, and library path in the code.

However, I am having a hardtime to retrieve the library path here. I can find this path in SAS Management Console by opening the library "staging".

 

I see some guides that path can easily be resolved. However, the Database path is different from server host.

 

Is there a way to make the "path" dynamic?

 

My desired libname statement is:

libname staging oracle authdomain="OracleAuth" path=DBPath;

 

3 REPLIES 3
Patrick
Opal | Level 21

If you have a different database then you would also need a different authdomain. 

If you need this library regularly then best define it in SAS metadata - under a different libref though. 

 

What you always can do is point one libref to another. Something like: libname mystg (staging).

The library pre-defined in SAS metadata doesn't need to be pre-assigned. You can always use it via the SAS Meta engine and liburi (and then just assign the libref of your desire).

SASKiwi
PROC Star

If you were using an ODBC connection then you would be using the ODBC engine on your LIBNAME statement. Since you use the ORACLE engine, that means you interface with the Oracle client software installed on your SAS server. The client software contains a file called TNSNAMES.ORA which is where all of the Oracle paths are defined.

 

Any new database paths first need to be defined in TNSNAMES.ORA. Then you can try them out in a SAS LIBNAME statement. It is best to trial new database connections in a LIBNAME before defining them in SAS metadata.

AllanBowe
Barite | Level 11

If you are looking to extract the library definition from metadata, then this macro will help (and it is configured for Oracle libname engines):  https://core.sasjs.io/mm__assigndirectlib_8sas_source.html

 

We use it in Data Controller for SAS to enable direct connections using the relevant system account.

 

Here's the extract:

%else %if &engine=ORACLE %then %do;
  %put NOTE: Obtaining &engine library details;
  data _null_;
    length assocuri1 assocuri2 assocuri3 authdomain path schema $256;
    call missing (of _all_);
 
    /* get auth domain */
    rc=metadata_getnasn("&liburi",'LibraryConnection',1,assocuri1);
    rc=metadata_getnasn(assocuri1,'Domain',1,assocuri2);
    rc=metadata_getattr(assocuri2,"Name",authdomain);
    call symputx('authdomain',authdomain,'l');
 
    /* path */
    rc=metadata_getprop(assocuri1,
      'Connection.Oracle.Property.PATH.Name.xmlKey.txt',path);
    call symputx('path',path,'l');
 
    /* schema */
    rc=metadata_getnasn("&liburi",'UsingPackages',1,assocuri3);
    rc=metadata_getattr(assocuri3,'SchemaName',schema);
    call symputx('schema',schema,'l');
  run;
  %put NOTE: Executing the following:/; %put NOTE-;
  %put NOTE- libname &libref ORACLE path=&path schema=&schema;
  %put NOTE-     authdomain=&authdomain;
  %put NOTE-;
  libname &libref ORACLE path=&path schema=&schema authdomain=&authdomain;
%end;
/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 919 views
  • 0 likes
  • 4 in conversation