connecting sas to a teradata server · pdf file| connecting sas to a teradata server below is...

18
Westpac Banking Corporation ABN 33 007 457 141. CONNECTING SAS TO A TERADATA SERVER KEVIN MARK DATA SCIENTIST, GROUP COLLECTIONS WEDNESDAY 25 OCTOBER 2017

Upload: phamnhi

Post on 01-Feb-2018

239 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

Westpac Banking Corporation ABN 33 007 457 141.

CONNECTING SAS TO ATERADATA SERVERKEVIN MARKDATA SCIENTIST, GROUP COLLECTIONS

WEDNESDAY 25 OCTOBER 2017

Page 2: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Problem of data not in SAS format

2

Images from http://www.teradata.com/Resources/Videos/Enabling-in-database-processing-with-SAS-ACCE and http://www.teradata.com/Solutions-and-Industries/sas-optimization/

GOAL: Bring the data stored on the

Teradata server into a SAS session.

Enterprise Guide

Page 3: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Overview

3

Connecting SAS with Teradata

Two interfaces to connect SAS with Teradata

Concealing your Teradata password

Importing Teradata data to SAS

Joining a small SAS dataset with Teradata data

Questions

Disclaimer: The presentation are the views of the presenter and not that of the Westpac Group.

Page 4: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

CONNECTING SAS WITH TERADATATwo interfaces

Page 5: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Two interfaces to connect SAS with Teradata

5

Images from http://www.teradata.com/Resources/Videos/Enabling-in-database-processing-with-SAS-ACCE and http://www.teradata.com/Solutions-and-Industries/sas-optimization/

SAS/Access Interface to Teradata

SAS/Access Interface to ODBC

UNIX SERVER

SAS EG running with a

Profile connected to a

SAS Unix Server

Page 6: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Battle of the Interfaces

6

Access Interface to ODBC Access Interface to Teradata

Connects from local PC Server Connects from SAS Unix Server

• Requires SAS EG to be connected

to SAS Unix Server

Implicit connection via a libname

statement

Implicit connection via a libname

statement

Explicit connection via an ODBC

connection in a SQL procedure

Explicit connection via a Teradata

connection in a SQL procedure

Ability to execute Teradata commands

from SAS

• Including ability to create and use

temporary (volatile) tables.

Page 7: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

CONCEALING YOUR PASSWORD

Page 8: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Concealing your Teradata password

8

proc pwencode in=‘my_password’;

run;

The SAS Log outputs the following:

{sas002}

DBCC5712369DE1C65B19864C1564FB850F39

8DCF

%let password={sas002}

DBCC5712369DE1C65B19864C1564FB850F39

8DCF;

User names and passwords to a Teradata

server need to be specified in SAS code.

We want to write, save and run code without

divulging passwords, especially in LOGs.

The PWENCODE Procedure will encrypt a

password which you can use.

Not perfect. See SAS Documentation on the

procedure for how to use this securely.

Example SAS Code:Situation

Page 9: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

IMPORTING TERADATA DATA TO SAS

Page 10: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Importing Teradata data to SAS

10

Images from http://www.teradata.com/Resources/Videos/Enabling-in-database-processing-with-SAS-ACCE and http://www.teradata.com/Solutions-and-Industries/sas-optimization/

SAS/Access Interface to Teradata

SAS/Access Interface to ODBC

UNIX SERVER

Database=DB1 Table=Employees

Columns: employee_id, date,…

GOAL: Create the SAS

dataset Emps_Today of

today’s employees with all

available columns.

ODBC Data Source Name

dsn=“TD_Server”

Teradata Server Address

tdpid=“12.34.567.89”

Page 11: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Implicit connection via a libname statement

11

libname TD_DB1

teradata

tdpid=“12.34.567.89”

user=“user-id”

password=“&password.”

database=“DB1”;

data work.Emps_Today;

set TD_DB1.Employees;

where date=‘25OCT2017’d;

run;

Access Interface to Teradata

libname TD_DB1

odbc

dsn=“TD_Server”

user=“user-id”

password=“&password.”

schema=“DB1”;

data work.Emps_Today;

set TD_DB1.Employees;

where date=‘25OCT2017’d;

run;

Access Interface to ODBC

Page 12: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Explicit connection via a SQL Procedure

12

proc sql;

connect to teradata (

tdpid=“12.34.567.89”

user=“user-id”

password=“&password.”);

create table work.Emps_Today as

select * from connection to teradata

(select * from DB1.Employees

where date=date ‘2017-10-25’);

quit;

Access Interface to Teradata

proc sql;

connect to ODBC (

dsn=“TD_Server”

user=“user-id”

password=“&password.”);

create table work.Emps_Today as

select * from connection to ODBC

(select * from DB1.Employees

where date=date ‘2017-10-25’);

quit;

Access Interface to ODBC

Page 13: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

JOINING A SMALL SAS DATASETWITH TERADATA DATA

Page 14: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

14

Images from http://www.teradata.com/Resources/Videos/Enabling-in-database-processing-with-SAS-ACCE and http://www.teradata.com/Solutions-and-Industries/sas-optimization/

Database=DB1 Table=Employees

Columns: employee_id, date,…

Has millions of rows

SAS Dataset=EMPS

Columns: employee_id, date

Has only 100 rows.Create a temporary (volatile)

table in Teradata called

EMPS_TEMP

Join data in

Teradata

Upload SAS

Dataset to

Teradata

SAS Dataset=EMPS_Output

Columns: employee_id, date,…

Has only 100 rows.

Page 15: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Joining a small SAS dataset with Teradata data

15

execute(

create multiset volatile table

EMPS_TEMP (

employee_id VARCHAR(10)

date DATE)

primary index (employee_id)

on commit preserve rows;

) by teradata;

execute (commit work) by teradata;

quit;

libname temp teradata

tdpid=“12.34.567.89”

user=“user-id”

password=“&password.”

connection=GLOBAL

dbmstemp=YES;

proc sql;

connect to teradata (

tdpid=“12.34.567.89”

user=“user-id”

password=“&password.”

connection=GLOBAL);

Create a volatile table EMPS_TEMPConnect globally to temporary Teradata

Page 16: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Joining a small SAS dataset with Teradata data

16

proc append

base=temp.EMPS_TEMP (MULTISTMT=yes)

data=EMPS (keep=employee_id date);

run;

Upload SAS data to a Teradata volatile table

Page 17: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Joining a small SAS dataset with Teradata data

17

select

b.*

from EMPS_TEMP a

inner join Employees b

on b.employee_id=a.employee_id

and b.date=a.date

);

quit;

proc sql;

connect to teradata (

tdpid=“12.34.567.89”

user=“user-id”

password=“&password.”

connection=GLOBAL);

create table work.EMPS_OUTPUT as

select * from connection to teradata

(

…an explicit Teradata SQL select statementCreate the resultant SAS dataset with …

Page 18: CONNECTING SAS TO A TERADATA SERVER · PDF file| Connecting SAS to a Teradata server Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually

| Connecting SAS to a Teradata server

Below is the chart colour sequence. If your chart has more than 12 series‘ you will need to manually colour the additional series.

B102 B199

Thank you and Questions

18

[email protected]