Using - SASeg - Effectively - Proc SQL Good One Read at Home
Using - SASeg - Effectively - Proc SQL Good One Read at Home
Now What ?
EG Default Behaviour
EG Default Setup
EG SASUSER
EG Profiles
EG Profiles
What is Pass-Through ?
SAS Access engines for RDBMS eg. Teradata, Oracle, ODBC essentially APIs to communicate with the DB explicit pass-through o SAS program connects to DB o SQL is passed through to DB SQL must be native to DB implicit pass-through o SAS decides and takes care of it for you
Explicit Pass-Through
open a program window in EG
proc sql; connect to teradata ( user=&user pass="&pass" server=&server); create table pp_sum_cube as select * from connection to teradata ( select s.brand_name, m.* from mi_analytics.v_bm_f_pp_migration_sum_cube m left join mi_data.bm_d_segment s on m.segment_cd = s.segment_cd where m.period_dt in ( '2012-03-01', '2012-03-02' ) order by m.period_dt, s.brand_name ); quit;
Implicit Pass-Through
You write SAS SAS interprets your code and it writes Teradata SQL o functions o ... if possible ... In Database processing o SAS Procedures o SAS formats
Implicit Pass-Through
libname mitddata teradata user=&user pass="&pass" server=&server sql_functions=all ;
SAS LIBNAME statement Teradata engine SAS SQL summary query runs entirely in Teradata o small result set returned to SAS
Implicit Pass-Through
libname mitddata teradata user=&user pass="&pass" server=&server sql_functions=all; proc freq data = mitddata.BM_D_Segment; tables segment_tier_0 /missing nopercent ; run; 514 515 516 proc freq data = mitddata.BM_D_Segment; tables segment_tier_0 /missing nopercent ; run;
NOTE: SQL generation will be used to construct frequency and crosstabulation tables.
runs forevvvvvvvvvver
WHERE
( (
SAS will happily run in Oracle turns SQL into Oracle query much happiness
15,000 rows left joined to 120,000,000 o 576 amps !??! 48 minutes later...
ERROR: This SQL statement will not be passed to the DBMS for processing because it involves a join across librefs with different connection properties.
TERADATA: trqacol- Casting decimals. Raw row size=38, Casted size=38, CAST_OVERHEAD_MAXPERCENT=20% TERADATA_8: Prepared: on connection 4 SELECT "OLD_PP_SOC_CD","NEW_PP_SOC_CD",CAST("SERVICE_ACTIVITY_KEY" AS FLOAT),"PERIOD_DT",CAST("SERVICE_ACTIVITY_KEY_PREV" AS FLOAT) FROM mi_stage."STG_SC_PP_MIGRATION"
NOTE: PROCEDURE SQL used (Total process time): 48:12.89 real time user cpu time 30:29.85 system cpu time 6:40.33
NOTE: PROCEDURE SQL used (Total process time): 4.66 seconds real time user cpu time 0.22 seconds system cpu time 0.04 seconds
Temporary Tables
need historical data for these 10,000 subscribers 1. Pull subscriber history down to SAS, join 2. where subscriber_no in ( 123,345,567 x 10K ) 3. Push 10,000 subscriber numbers up o do the join in DB o pull only what you need down o minimize slow data transfers
Temporary Tables
Oracle Teradata global temp tables volatile tables
exist for the duration of the session o like SAS WORK datasets requires o LIBNAME engine o explicit pass-thru EXECUTE ( DDL statement ) by teradata; o implicit pass-thru to load subset o explicit pass-thru for final result
Temporary Tables
libname td_volt teradata server="&server" user=&user password="&pass" dbmstemp=yes connection=global dbcommit=0; proc sql; connect to teradata ( server="&server" user=&user password="&pass" connection=global mode=teradata ); /* create an empty volatile table */ execute ( create multiset volatile table test_vol ... ( .. columns .. ) ) by teradata; quit;
Temporary Tables
/* Put rows into the volatile table via the libname if lots of records, additional options necessary, e.g. fastload */ proc sql; insert into td_volt.test_vol select subscriber_number as subscriber_no from midata.dim_subscriber ( obs = 100 ) ; quit;
Temporary Tables
/* Execute pass-thru query to join Teradata table to volatile table */ proc sql; connect to teradata (server="&server" user=&user password="&pass" connection=global); create table sas_datastet_of_results as select * from connection to teradata ( select s.* from bmbi_view.vb_subscriber s, test_vol v where v.subscriber_no = s.sub_no ); quit;
Conclusion
do stuff where it makes sense o use power of DB o summarize, subset, sort in DB not all implicit pass-thru is o use option SASTRACE use EXPLAIN
Contact
Harry Droogendyk harry.droogendyk@bell.ca harry@stratia.ca Phone: Web: 905-282-3476 www.stratia.ca/papers