SAS backfeed macro

来源:互联网 发布:linux mv 多个文件 编辑:程序博客网 时间:2024/06/15 04:07
%include 'G:\MADATA\contexts\emea_apj\stored_process\error_handling.sas';%macro back_feed(channel, audience);%let sourcedb = smb_qa_ec;%let targetdb = smb_preprod_stage;%let server = hqdellnz06;%let authdomain = hqdellnz06;LIBNAME dblib NETEZZA DATABASE=&targetdb SERVER=&server AUTHDOMAIN="&authdomain" DBCONINIT='SET SERIALIZABLE = FALSE;';/* -------------------------  STEP # -1 ------------------------- */PROC SQL ERRORSTOP;%global actual_time actual_time_n actual_time_s campcode;%let actual_time = %sysfunc(datetime());%let actual_time_n = %sysfunc(compress(%sysfunc(tranwrd(%sysfunc(putn(&actual_time,E8601DZ20.)),T, )),Z));%let actual_time_s = %sysfunc(putn(&actual_time,datetime25.));%put campcode=&campcode;%put actual_time_n=&actual_time_n;CONNECT TO NETEZZA (AUTHDOMAIN="&authdomain" DB=&targetdb SERVER=&server DBCONINIT='SET SERIALIZABLE = FALSE;');EXECUTE (call sp_bf_checks (%str(%')&campcode%str(%'),%str(%')&actual_time_n%str(%'))) BY NETEZZA;DISCONNECT FROM NETEZZA;QUIT;%put RC=&RC;%chkerr(Step #-1);%put RC=&RC;%if (%eval(not(&RC = 0))) %then %do;  %goto eof_code_logic;%end;/* -------------------------  STEP #0 ------------------------- */PROC SQL ERRORSTOP;CONNECT TO NETEZZA (AUTHDOMAIN="&authdomain" DB=&targetdb SERVER=&server DBCONINIT='SET SERIALIZABLE = FALSE;');EXECUTE( call sp_bf_checks_notification(%str(%')&campcode%str(%'),%str(%')&actual_time_n%str(%'))) BY NETEZZA;DISCONNECT FROM NETEZZA;QUIT;%put RC=&RC;%chkerr(Step #0);%put RC=&RC;%if (%eval(not(&RC = 0))) %then %do;  %goto eof_code_logic;%end;/* -------------------------  STEP #1 ------------------------- */PROC SQL ERRORSTOP;%global actual_time actual_time_n actual_time_s campcode;%let actual_time = %sysfunc(datetime());%let actual_time_n = %sysfunc(compress(%sysfunc(tranwrd(%sysfunc(putn(&actual_time,E8601DZ20.)),T, )),Z));%let actual_time_s = %sysfunc(putn(&actual_time,datetime25.));CONNECT TO NETEZZA (AUTHDOMAIN="&authdomain" DB=&targetdb SERVER=&server DBCONINIT='SET SERIALIZABLE = FALSE;');EXECUTE (/*way to proof counts*//* modified to cause error call sp_insert_raw_promo_history */%put campcode=&campcode;%put actual_time_n=&actual_time_n;call sp_insert_raw_promo_history(%str(%')&campcode%str(%'), %str(%')&actual_time_n%str(%'))) BY NETEZZA;DISCONNECT FROM NETEZZA;QUIT;%put RC=&RC;%chkerr(Step #1);%put RC=&RC;%if (%eval(not(&RC = 0))) %then %do;  %goto eof_code_logic;%end;/* ------------------------- STEP #2 ------------------------- */PROC SQL ERRORSTOP;%global camp_type coupon_flg;   select distinct camp_type, campaign_coupon_flg  into :camp_type, :coupon_flg       from dblib.Raw_Promo_History      where camp_cd = "&campcode"  and run_dttm = "&actual_time_s"dt ;%let camp_type = &camp_type;%let coupon_flg = &coupon_flg;QUIT;%put RC=&RC;%chkerr(Step #2);%put RC=&RC;%if (%eval(not(&RC = 0))) %then %do;  %goto eof_code_logic;%end;/* ------------------------- STEP #3 ------------------------- */PROC SQL ERRORSTOP;CONNECT TO NETEZZA (AUTHDOMAIN="&authdomain" DB=&targetdb SERVER=&server DBCONINIT='SET SERIALIZABLE = FALSE;');EXECUTE (call sp_bf_raw_to_wave_execution_processing(%str(%')&campcode%str(%'),%str(%')&actual_time_n%str(%'),%str(%')&camp_type%str(%'), %str(%')&coupon_flg%str(%'),  %str(%')&channel%str(%'), %str(%')&audience%str(%') ) ) BY NETEZZA;DISCONNECT FROM NETEZZA;QUIT;%put RC=&RC;%chkerr(Step #3);%put RC=&RC;%if (%eval(not(&RC = 0))) %then %do;  %goto eof_code_logic;%end;/* ------------------------- STEP #4 ------------------------- */PROC SQL ERRORSTOP;CONNECT TO NETEZZA (AUTHDOMAIN="&authdomain" DB=&sourcedb SERVER=&server DBCONINIT='SET SERIALIZABLE = FALSE;');EXECUTE (call sp_bf_from_raw_to_stg_phist_processing_dynamic /* Version 2 */(%str(%')&campcode%str(%'), %str(%')&actual_time_n%str(%'),%str(%')&camp_type%str(%'),%str(%')&coupon_flg%str(%'),  %str(%')&channel%str(%'), %str(%')&audience%str(%'))) BY NETEZZA;DISCONNECT FROM NETEZZA;QUIT;%put RC=&RC;%chkerr(Step #4);%put RC=&RC;%if (%eval(not(&RC = 0))) %then %do;  %goto eof_code_logic;%end;/* ------------------------- STEP #5 ------------------------- */PROC SQL ERRORSTOP;CONNECT TO NETEZZA (AUTHDOMAIN="&authdomain" DB=&targetdb SERVER=&server DBCONINIT='SET SERIALIZABLE = FALSE;');EXECUTE (call sp_update_status_of_wave_execution_history(%str(%')&campcode%str(%'), %str(%')&actual_time_n%str(%'),%str(%')&camp_type%str(%'))) BY NETEZZA;DISCONNECT FROM NETEZZA;QUIT;%put RC=&RC;%chkerr(Step #5);%put RC=&RC;%if (%eval(not(&RC = 0))) %then %do;  %goto eof_code_logic;%end;/* ------------------------- STEP #6 ------------------------- */DATA &outTable;set &inTable;       run;/* If we fail on a %chkerr(); call we will GOTO here */%eof_code_logic:%mend back_feed;

0 0