BookmarkSubscribeRSS Feed
ScottBass
Rhodochrosite | Level 12

Hi,

 

In this code:

 

%let server=yourserver;
%let authdomain=TeraDevAuth;

options sastrace=',,,d' sastraceloc=saslog;

/* Set global connection for all tables. */
libname x  teradata server=&server authdomain=&authdomain connection=global;

/* Create a volatile table. */
proc sql;
   connect to teradata(server=&server authdomain=&authdomain connection=global);
   execute (CREATE VOLATILE TABLE temp1 (col1 INT) 
            ON COMMIT PRESERVE ROWS) by teradata;
   execute (COMMIT WORK) by teradata;
quit;

/* Insert 1 row into the volatile table. */
proc sql;
   connect to teradata(server=&server authdomain=&authdomain connection=global);
   execute (INSERT INTO temp1 VALUES(1)) by teradata;
   execute (COMMIT WORK) by teradata;
quit;

/* Access the temporary table through the global libref. */
proc print data=x.temp1;
run;

/* Create a volatile table with an index. */
proc sql;
   connect to teradata(server=&server authdomain=&authdomain connection=global);
   execute (CREATE VOLATILE TABLE temp2 (col1 INT) 
            UNIQUE PRIMARY INDEX (col1)
            ON COMMIT PRESERVE ROWS) by teradata;
   execute (COMMIT WORK) by teradata;
quit;

/* Insert 1 row into the volatile table. */
proc sql;
   connect to teradata(server=&server authdomain=&authdomain connection=global);
   execute (INSERT INTO temp2 VALUES(2)) by teradata;
   execute (COMMIT WORK) by teradata;
quit;

/* Access the temporary table through the global libref. */
proc print data=x.temp2;
run;

/* Let SAS do the work of creating the volatile table */
libname x teradata server=&server authdomain=&authdomain connection=global dbmstemp=yes; data x.temp3; col1=3; run; /* Access the temporary table through the global libref. */ proc print data=x.temp3; run; /* A more realistic example */ data x.table_with_sk; sk+1; set sashelp.cars; run; proc print data=x.table_with_sk; run;

The 2nd example is explicitly defining the volatile table (VT), including the index definition.  In the 3rd example, I let SAS do the work of creating the VT table definition.  See the trace output in the log.

 

But, in the 3rd example, is there a way to create an index on the VT?

 

From the trace output, It appears to me that the teradata engine is intercepting/parsing the SAS code and translating that into teradata SQL.  If so, then couldn't the parser/engine do something with:

 

data x.temp3 (index=(col1));
   col1=3;
run;

And translate that to (edited sastrace exerpt):

 

TERADATA_8: Executed: on connection 2 41 1463718006 no_name 0 DATASTEP
CREATE  VOLATILE MULTISET TABLE "temp3" ("col1" FLOAT) UNIQUE PRIMARY INDEX (col1) ON COMMIT 
PRESERVE ROWS ;COMMIT WORK 42 1463718006 no_name 0 DATASTEP

Regardless of whether I think it should work this way, if there is a way to get SAS to create the table definition per the 3rd example, and also create an index(es), please let me know.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
1 REPLY 1
ChrisNZ
Tourmaline | Level 20

 

>if there is a way to get SAS to create the table definition per the 3rd example

 

I don't think so. Having ot use explicit SQL pass-through to modify internal database organisation or optimisation (such as index management) does not seem like an excessive burden to me. So while having this feature might be an improvement for some, it may be unneeded for most, but as usual ummv.

 

One thing that's odd: don't you get a meaningful LOG message when you attempt this? Here is what is displayed in the LOG if you try with Oracle.

 

 

data ORA.IP_ID1(index=(IP_ID)); 
                -----
                76

WARNING 76-63: The option INDEX is not implemented in the ORACLE engine.

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 4555 views
  • 0 likes
  • 2 in conversation