I am trying to access the SAS table which I made outside of Teradata Passthrough in working space for query run. Now it gives me an error. My question is how to access the table not in teradata inside the passthrough
proc sql;
connect to teradata (user="&user_id.#LDAP" password="&TERADATA_PASS" server='ABC'
connection=global database="GTY");
select * from connection to teradata(
select * from mm)
;
quit;
mm is not in teradata but made in working directory.
You probably can't access that in passthrough directly. You either need to run your query using libname access to the Teradata, or you need to put the information you need into a macro variable or text file that could be included in the passthrough query. In passthrough you can only access what you could access in an interactive Teradata session - so unless you have SAS defined as an ODBC or such provider for Teradata, it's a no go.
Typically what I do in this case is first try to execute the entire process through libname access, and if that fails (either because of execution time or because of a need for passthrough-only elements like stored procedures) then I use libname access to load the table to a table inside the RDBMS (Teradata here). Then it's available in your passthrough session for use (as a native Teradata table).
Related
I am trying to display from the Oracle table the latest day from each particular month and I am facing a issue with the right function. I am trying like below, but it doesn't work.
proc sql;
connect to Oracle( );
create table work.database as
select * from connection to Oracle
(select * from oracle_table_name
where column_name= intnx('month',column_name, -1,'E');
disconnect from Oracle;
quit;
Your issue here (beyond some typos) is that you are using intnx, a SAS function, in pass-through SQL.
Pass-through SQL means you are submitting Oracle SQL code directly to Oracle and saying "please run this". You need to use the proper Oracle date functions in the where clause.
I have connected to the DB2 database using libname statement and created a table using DATA Step as follows:
libname db2lib db2 user=user pw=pwd database=dbtest schema=schema1;
data db2lib.test_table;
var1 = "1234";
run;
Table got created successfully but nobody else able to run the SELECT query on it.
I know how to grant permissions to the table using PROC SQL execute but is there any way to GRANT privileges as I am connecting to DB2 using LIBNAME.
I am unaware of any DB2 CREATE TABLE options that grant permissions.
However, if there are any, the data set option DBCREATE_TABLE_OPTS= could be specified in your SAS code:
DBCREATE_TABLE_OPTS= Data Set Option
Specifies DBMS-specific syntax to add to the end of the CREATE TABLE statement.
Details
You can use this option to add DBMS-specific clauses at the end of the SQL CREATE TABLE statement. The SAS/ACCESS engine passes the SQL CREATE TABLE statement and its clauses to the DBMS. The DBMS then executes the statement and creates the DBMS table. This option applies only when you are creating a DBMS table by specifying a libref associated with DBMS data.
As you know, the GRANT statement can be issued through The SQL Procedure EXECUTE statement.
Did you know CONNECT can use the existing LIBNAME ?
Proc SQL;
connect using DB2LIB;
execute (
GRANT …
) by DB2LIB;
I am thinking of using SAS and would like to know:
Is it possible to use ODBC to access a Teradata database in SAS?
I know that accessing MS Access using ODBC in SAS is possible, and accessing Teradata with Excel VBA using ODBC is possible, but I can not find anything for SAS with Teradata and ODBC.
connecting to Teradata by connect statement can be done by connect statement as shown below.
proc sql ;
connect to teradata (server=server user=user pw=pw );
create table work.emp as
(select *
from connection to teradata
(select a.*,
row_number()over(partition by deptno order by hiredate) as rn from
prod_targetdb.customer_table a
));
disconnect from teradata;
quit;
looks like connect to ODBC will also work but looks like it has more limitations,
like fastload capability and others, please look into the page 24 in the link given below
https://www.cs.purdue.edu/homes/ake/courses/cs590w/SASACCESS.pdf
I wonder if one of you can help me on how to upload all adventureworks database (every table) into SAS Studio?
I would like to work on adventureworks using sas base
All you need to do is create a libname reference to your database - I don't recommend creating SAS tables from the raw SQL Server data.
Example libref (using OLE DB):
libname &libref OLEDB
PROPERTIES=&sql_properties
DATASOURCE=&sql_dsn
PROVIDER=&sql_provider
SCHEMA=&sql_schema
authdomain="&sql_domain"
connection=shared;
You will need to set the relevant variables as per your environment.
It took a few years.. And the development of sasjs.. But finally, AdventureWorks for SAS is here!
Just run these two lines of code and the 5 AdventureWorks schemas will be created as different libraries under WORK:
filename mc url "https://raw.githubusercontent.com/sasjs/AdventureWorks/main/runme.sas";
%inc mc;
Just modify that file to make permanent libs / datasets. More info in the readme: https://github.com/sasjs/adventureworks
I have to perform data prediction using SAS Enterprise Miner. SAS only has an option to load a SAS table but the problem is i have a database with two tables that i have to use for the prediction. How do i get the two tables from the database into SAS Enterprise Miner.
I have not used Access or Miner in 10 years. However, I would suggest something like:
Does Access have the concept of a view? If so, then create the view in Access and then just use that.
or
Write a stand alone piece of code that pulls the tables from Access and does the join in SAS. I believe you can do this in Miner. If not, just do it in Enterprise Guide and save the table to a location you can pick it up with Miner.
or
Create a SAS view from the Access database that does the join and use that in Miner. Same as above, just save a view instead of a table -- allows you to update the Access database without having to recreate the table.
After looking into this problem I finally decided to use base SAS to read the database and extract the individual tables, save them into a SAS library, in that way they will be saved on the local drive then i could use them in Enterprise Miner.
/*Create a new library to store converted files*/
libname db 'C:\\Users\\Documents\\Data Sources';
/*import the first table from the database into the newly created library*/
proc import out = db.Table1
datatable = 'Table1'
dbms= ACCESS Replace;
database= "C:\\Users\\Documents\\Data Sources\\DBName.mdb";
usedate=yes;
scantime=no;
dbsaslabel=none;
run;
/*import the second table from the database into the newly created library*/
proc import out = db.Table2
datatable = 'Table2'
dbms= ACCESS Replace;
database= "C:\\Users\\Documents\\Data Sources\\DBName.mdb";
usedate=yes;
scantime=no;
dbsaslabel=none;
run;