Search notes:

SAS and Oracle

Creating a table with CONNECT TO and EXECUTE

%let ora_user     = rene;
%let ora_password = secret_garden;
%let ora_server   = ora.renenyffenegger.ch;
/* Or, alternatively: */
%let ora_server   =
"(DESCRIPTION=(
    ADDRESS     = (PROTOCOL = TCP                      )
                  (HOST     = ora.renenyffenegger.ch   )
                  (PORT     = 2808                     )
  )
  ( CONNECT_DATA =(SERVICE_NAME=ora.renenyffenegger.ch )
  )
)";


proc sql;
  connect to oracle (
    user     = &ora_user
    password = &ora_password
    path     = &ora_server
  );

  execute (
      create table tq84_test (
         col_1 number,
         col_2 varchar2(11)
      )
  ) by oracle;
quit;
Github repository about-SAS, path: /programming/proc/sql/oracle/connect/execute.create-table.sas

Creating a table with a LIBNAME

If there is already a libname, it can be used in the connect statement:
%let ora_user     = rene;
%let ora_password = secret_garden;
%let ora_server   = ora.renenyffenegger.ch;

/* Or, alternatively: */
%let ora_server   =
"(DESCRIPTION=(
    ADDRESS     = (PROTOCOL = TCP                      )
                  (HOST     = ora.renenyffenegger.ch   )
                  (PORT     = 2808                     )
  )
  ( CONNECT_DATA =(SERVICE_NAME=ora.renenyffenegger.ch )
  )
)";

libname tq84_ora
   oracle 
   user                     = &ora_user
   password                 = &ora_password
   path                     = &ora_server
   sql_functions            = all
   db_length_semantics_byte = no;                                                                           

proc sql;
   connect using tq84_ora;

   execute by tq84_ora (
       create table tq84_test_connect_using (
          id        number primary key,
          col_1     varchar2(10)
       )
   );

   disconnect from tq84_ora;
quit;
Github repository about-SAS, path: /programming/proc/sql/oracle/connect/using.execute.create-table.sas

Select via a LIBNAME

%let ora_user     = rene;
%let ora_password = secret_garden;
%let ora_server   = ora.renenyffenegger.ch;

libname tq84_ora
   oracle 
   user                     = &ora_user
   password                 = &ora_password
   path                     = &ora_server
   sql_functions            = all
   db_length_semantics_byte = no;
 
proc sql;
   connect using tq84_ora;

   select * from connection to tq84_ora (
       select * from tq84_test_connect_using
   );

   disconnect from tq84_ora;
quit;
Github repository about-SAS, path: /programming/proc/sql/oracle/connect/using.select-from-connection.sas

See also

Insert a date variable into an Oracle table
Call an Oracle PL/SQL function from SAS
Determine a session's sid and serial
SAS and Oracle: helpers
libname for Oracle
Specifying an Oracle schema in a data step set statement, Specify Oracle schema in select statement
Function translation
Null handling

Index