BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

works:

LIBNAME myora ORACLE PATH=BIxxx.vwxxxx.de USER=SAS PASSWORD='xcxxxsds';

data MKT.CONSENTIMIENTOS(promote=yes);
set myora.CONSENTIMIENTOS;
run;

does not work:

proc cas;
function doesTableExist(casLib,casTable);
  table.tableExists result=r status=rc / caslib=casLib table=casTable;
  tableExists = dictionary(r, "exists");
  return tableExists;
end func;
tableExists = doesTableExist("mkt", "MKT.CONSENTIMIENTOS");
if tableExists=0 then 
dataStep.runCode result=r status=rc / code='/* BEGIN data step with the output table data */
data CONSENTIMIENTOS(caslib="mkt" promote=yes);
set CONSENTIMIENTOS(caslib="myora");
run;';
run;

proc cas;
dataStep.runCode result=r status=rc / code='/* BEGIN data step with the output table data */
data CONSENTIMIENTOS(caslib="mkt" promote=yes);
set MYORA.CONSENTIMIENTOS;
run;';
run;

error code

pic.png

1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
Ammonite | Level 13

Code running in CAS has absolutely no access to SAS libraries on the Compute Server. This means that your DATA step in CAS can't use data from the myOra libref in the SAS session. To use Oracle in CAS, you need an Oracle-based CASLIB. Here is some example code:

 

cas mySession;
/* Establish an Oracle caslib so you can access Oracle in CAS*/
caslib myOra desc="Oracle caslib" 
              datasource=(
                srctype="oracle"
               ,username="SAS"
               ,pwd='xcxxxsds'
               ,path="BIxxx.vwxxxx.de"
                ) 
      ;

proc cas;

function doesTableExist(casLib,casTable);
  table.tableExists result=r status=rc / caslib=casLib table=casTable;
  tableExists = dictionary(r, "exists");
  return tableExists;
end func;

/* 
 It's easier to write DATA steps in a source block than to write 
 the code within a string parameter. Use caslib.table_name format
 to reference CAS tables when running in CAS. 
*/
source myDataStep;
data mkt.CONSENTIMIENTOS(promote=yes);
   set myOra.CONSENTIMIENTOS;
run;
endsource;

tableExists = doesTableExist("casORA", "CONSENTIMIENTOS");
if tableExists=0 then do;
   /* Execute the DATA step code from the source block named myDataStep */
   dataStep.runCode result=r status=rc / 
	   code=myDataStep;
end;
run;

Remember that, in CAS, tables written to the Oracle caslib (myOra) are still CAS in-memory tables, and have NOT been saved to the Oracle database yet. You must explicitly save it to the database, for example using the table.save action.

May the SAS be with you!
Mark 

Check out my Jedi SAS Tricks for SAS Users

View solution in original post

1 REPLY 1
SASJedi
Ammonite | Level 13

Code running in CAS has absolutely no access to SAS libraries on the Compute Server. This means that your DATA step in CAS can't use data from the myOra libref in the SAS session. To use Oracle in CAS, you need an Oracle-based CASLIB. Here is some example code:

 

cas mySession;
/* Establish an Oracle caslib so you can access Oracle in CAS*/
caslib myOra desc="Oracle caslib" 
              datasource=(
                srctype="oracle"
               ,username="SAS"
               ,pwd='xcxxxsds'
               ,path="BIxxx.vwxxxx.de"
                ) 
      ;

proc cas;

function doesTableExist(casLib,casTable);
  table.tableExists result=r status=rc / caslib=casLib table=casTable;
  tableExists = dictionary(r, "exists");
  return tableExists;
end func;

/* 
 It's easier to write DATA steps in a source block than to write 
 the code within a string parameter. Use caslib.table_name format
 to reference CAS tables when running in CAS. 
*/
source myDataStep;
data mkt.CONSENTIMIENTOS(promote=yes);
   set myOra.CONSENTIMIENTOS;
run;
endsource;

tableExists = doesTableExist("casORA", "CONSENTIMIENTOS");
if tableExists=0 then do;
   /* Execute the DATA step code from the source block named myDataStep */
   dataStep.runCode result=r status=rc / 
	   code=myDataStep;
end;
run;

Remember that, in CAS, tables written to the Oracle caslib (myOra) are still CAS in-memory tables, and have NOT been saved to the Oracle database yet. You must explicitly save it to the database, for example using the table.save action.

May the SAS be with you!
Mark 

Check out my Jedi SAS Tricks for SAS Users

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 654 views
  • 0 likes
  • 2 in conversation