sas aeroplan sample

20

Click here to load reader

Upload: kenneth-miller

Post on 21-Aug-2015

20 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: sas aeroplan sample

  /* forty categories in final table. check tiers & tiers2 tables for inconsistencies*/ libname mast "/iim/corp1/core/all/mast/test_data";libname attr '/iim/corp1/core/prod/canada';libname canroc "/iim/corp1/core/roc/canada";libname usroc "/iim/corp1/core/roc/us"; proc contents data=attr.acct_attr;run; proc contents data=mast.mast_cm_canada;run; proc contents data=mast.mast_cid_canada;run; /*product*/ proc contents data=mast.mast_cm_canada;run; proc freq data= mast.mast_cm_canada; tables Market_Product;run; %let period1 = 01NOV2014;%let period2 = 01DEC2014; /*first*/ data aeroplan_&period1.(keep=cg_id year month cv_mon rocs cif market_product);set mast.mast_cm_canada;year=year(month);where (month)="&period1"d;run; data aeroplan2_&period1.;set aeroplan_&period1.;length product $32.;if (market_product) in ('Aeroplan/Gold','Aeroplan/Platinum', 'Aeroplan/Elite Gold') then

Page 2: sas aeroplan sample

product = 'Cobrand';else if (market_product) not in ('Aeroplan/Gold','Aeroplan/Platinum', 'Aeroplan/Elite Gold')thenproduct = 'Other';run; proc freq data= aeroplan2_&period1.; tables market_product;run; proc summary data=aeroplan2_&period1. nway noprint missing;class cg_id month product;output out=aeroplan2_&period1._summ (drop=_type_ _freq_) sum(cif)= sum(rocs)= sum(cv_mon)=;run; /*second*/ data aeroplan_&period2.(keep=cg_id year month rocs cif cv_mon market_product);set mast.mast_cm_canada;year=year(month);where (month)="&period2"d;run; data aeroplan2_&period2.;set aeroplan_&period2.;length product $32.;if (market_product) in ('Aeroplan/Gold','Aeroplan/Platinum', 'Aeroplan/Elite Gold') thenproduct = 'Cobrand';else if (market_product) not in ('Aeroplan/Gold','Aeroplan/Platinum', 'Aeroplan/Elite Gold')thenproduct = 'Other';run; proc summary data=aeroplan2_&period2. nway noprint missing;class cg_id month product ;output out=aeroplan2_&period2._summ (drop=_type_ _freq_) sum(cif)= sum(rocs)= sum(cv_mon)=;run; proc sort data=aeroplan2_&period1._summ;by cg_id product;run;

Page 3: sas aeroplan sample

proc sort data=aeroplan2_&period2._summ;by cg_id product;run; /*transpose metrics*/ proc transpose data=aeroplan2_&period1._summ out=aeroplan_&period1._cifs(drop=_:) prefix=prevcifs_; by cg_id; id product; var cif ; run; proc transpose data=aeroplan2_&period2._summ out=aeroplan_&period2._cifs(drop=_:) prefix=currcifs_; by cg_id; id product; var cif ; run; proc transpose data=aeroplan2_&period1._summ out=aeroplan_&period1._rocs(drop=_:) prefix=prevrocs_; by cg_id; id product; var rocs ; run; proc transpose data=aeroplan2_&period2._summ out=aeroplan_&period2._rocs(drop=_:) prefix=currrocs_; by cg_id; id product; var rocs; run; proc transpose data=aeroplan2_&period1._summ out=aeroplan_&period1._cv(drop=_:) prefix=prevcv_; by cg_id; id product; var cv_mon; run; proc transpose data=aeroplan2_&period2._summ out=aeroplan_&period2._cv(drop=_:) prefix=currcv_; by cg_id; id product; var cv_mon;

Page 4: sas aeroplan sample

run; data merged;merge aeroplan_&period1._cifs aeroplan_&period2._cifs aeroplan_&period1._cv aeroplan_&period2._cv aeroplan_&period1._rocs aeroplan_&period2._rocs;by cg_id;run; data merged2;length type $32.;set merged;if (prevcifs_cobrand)> 0 and (currcifs_cobrand) >0 then type = 'organic'; elseif missing (prevcifs_cobrand) and missing (prevcifs_other) and (currcifs_cobrand)>0 then type = 'new_new'; elseif (prevcifs_other) >0 and missing(prevcifs_cobrand) and (currcifs_cobrand)>0 then type = 'new_expansion'; elseif missing(currcifs_cobrand) and (prevcifs_cobrand)>0 then type = 'loss';run; /*portrfolio sheet*/ proc summary data=merged2 nway noprint missing;class type;output out = acct_summ (drop=_type_ rename=(_freq_ = accounts))sum(currcifs_cobrand)= sum(currrocs_cobrand)= sum(currcv_cobrand)=;where type ne '';run; proc freq data= merged2; tables type;run; libname mcidlib "/iim/corp1/core/all/master_cid"; /*tiers*/ proc contents data = attr.acct_attr;run;

Page 5: sas aeroplan sample

data tiers(keep=cg_id market market_product acct11 cd_no mr_tier_cd mr_tier_class);set attr.acct_attr;where (market = 'canada' and market_product like ('Aero%'));run; /* Platinum cards that are tier W earners*/ data tiers;set tiers; if acct11 in ('37906354189', '37906354489', '37906354789', '37906355589', '37906355689', '37906355789', '37906355889', '37906355989','37906244837', '37906340579', '37906381766') then mr_tier_cd = 'W';run; /******************/ data tiers2;set tiers;if mr_tier_cd = 'W' then class=1; elseif mr_tier_cd = 'X' then class=.5;run; proc sort data=tiers2;by acct11 cd_no;run; proc transpose data=tiers2 out=tiers2_summ(drop=_:) prefix=tier_; /*some tier codes missing*/ by acct11 cd_no; id mr_tier_cd; var class; run; proc freq data= tiers; tables cd_no;run; data acct_tiers(keep=cd_no tier_W tier_X acct11);

Page 6: sas aeroplan sample

merge tiers2_summtiers2;by acct11 cd_no;run; data acct_tiers;set acct_tiers;if tier_x = '' and tier_w='' then delete;run; data tiers_&period2.(keep=acct11 year month cd_no cv_mon rocs cif market_product);set mast.mast_cm_canada;year=year(month);where (month)="&period2"d and market_product in ('Aeroplan/Gold','Aeroplan/Platinum', 'Aeroplan/Elite Gold');run; proc summary data=tiers_&period2. nway noprint missing;class acct11 cd_no month market_product cif ;output out=tiers2_&period2._summ (drop=_type_ _freq_) sum(rocs)= sum(cv_mon)=;run; proc sort data=acct_tiers;by acct11 cd_no;run; proc sort data=tiers2_&period2._summ;by acct11 cd_no;run; data tiers_&period2._cv(keep=tier_: cd_no acct11 market_product rocs cif cv_mon);merge tiers2_&period2._summ (in=a)acct_tiers (in=b);by acct11 cd_no;if a and b;run; /*inactive & active cif*/ proc summary data=tiers_&period2._cv nway noprint missing;class market_product tier_: cif;output out=product_&period2 (drop=_type_ rename=(_freq_ = cifs))sum(cv_mon)= sum(rocs)= ;

Page 7: sas aeroplan sample

run; /* find merchants*/ /* air canada*/ /*proc sql ;connect to sybase (user=user pass=pass server=IQAX) ;create table aircan as select * from connection to sybase ( select dba_nm, se10 from dbo.se_char )where upcase(dba_nm) like ('AIR CANADA%');quit;*/ %include '~/.sasnetrc' ; proc sql; connect to teradata (user=&tduser server=edw pass=&tdpass database=udw mode=teradata connection=global); create table aircan as select * from connection to teradata (select dba_nm, se10 from udw.se_char where dba_nm (NOT CASESPECIFIC) like ('AIR CANADA%') ); disconnect from teradata;quit; data aircan2;length senumber $10.;set aircan;where upcase(dba_nm) in ('AIR CANADA', 'AIR CANADA (EUROPE)', 'AIR CANADA (GLOBAL)', 'AIR CANADA IRELAND', 'AIR CANADA (LAC)', 'AIR CANADA (JAPA)', 'AIR CANADA (EMEA)', 'AIR CANADA (NORTH AMERICA)', 'AIR CANADA GUADALAJARA', 'AIR CANADA DENMARK', 'AIR CANADA FRANCE', 'AIR CANADA GERMANY', 'AIR CANADA ITALY', 'AIR CANADA NETHERLANDS'

Page 8: sas aeroplan sample

'AIR CANADA NORWAY', 'AIR CANADA SPAIN', 'AIR CANADA SWEDEN', 'AIR CANADA SWITZERLAND', 'AIR CANADA CHINA', 'AIR CANADA EGYPT', 'AIR CANADA TAIWAN', 'AIR CANADA COSTA RICA', 'AIR CANADA CZECH', 'AIR CANADA HUNGARY', 'AIR CANADA MALAYSIA', 'AIR CANADA POLAND', 'AIR CANADA SAUDI', 'AIR CANADA SINGAPORE', 'AIR CANADA THAILAND', 'AIR CANADA SAUDI ARABIA', 'AIR CANADA BAHRAIN', 'AIR CANADA OMANI', 'AIR CANADA QATAR', 'AIR CANADA KUWAIT', 'AIR CANADA JORDAN', 'AIR CANADA AUSTRALIA', 'AIR CANADA JAPAN', 'AIR CANADA HONG KONG', 'AIR CANADA U.K.', 'AIR CANADA UAE', 'AIR CANADA, CANADA', 'AIR CANADA TURKEY', 'AIR CANADA - AUSTRALIA' 'AIR CANADA OSAKA', 'AIR CANADA SHANGHAI OFFICE', 'AIR CANADA SUC.ARGENTINA');senumber=se10;run; /*Marriott*/ /*proc sql;connect to sybase (user=user pass=pass server=IQAX) ;create table marriott as select * from connection to sybase ( select dba_nm, se10, city, state_cd, country_cd from dbo.se_char ) where upcase(dba_nm) like ('%MARRIOTT HOTELS%') or upcase(dba_nm) like ('%JW MARRIOTT%') or upcase(dba_nm) like ('%RENAISSANCE HOTELS%') or

Page 9: sas aeroplan sample

upcase(dba_nm) like ('%COURTYARD BY MARRIOTT%') or upcase(dba_nm) like ('%RESIDENCE INN%') or upcase(dba_nm) like ('%SPRINGHILL SUITES%') or upcase(dba_nm) like ('%FAIRFIELD INN%') or upcase(dba_nm) like ('%TOWNEPLACE SUITES%');quit;*/ proc sql;connect to teradata (user=&tduser server=edw pass=&tdpass database=udw mode=teradata connection=global);create table marriott as select * from connection to teradata ( select dba_nm, se10, city, state_cd, country_cd from udw.se_char where dba_nm (NOT CASESPECIFIC) like ('%MARRIOTT HOTELS%') or dba_nm (NOT CASESPECIFIC) like ('%JW MARRIOTT%') orf dba_nm (NOT CASESPECIFIC) like ('%RENAISSANCE HOTELS%') or dba_nm (NOT CASESPECIFIC) like ('%COURTYARD BY MARRIOTT%') or dba_nm (NOT CASESPECIFIC) like ('%RESIDENCE INN%') or dba_nm (NOT CASESPECIFIC) like ('%SPRINGHILL SUITES%') or dba_nm (NOT CASESPECIFIC) like ('%FAIRFIELD INN%') or dba_nm (NOT CASESPECIFIC) like ('%TOWNEPLACE SUITES%') ); disconnect from teradata;quit; proc sort data=marriott;by dba_nm;run; data marriott2;length senumber $10.;set marriott;where /*country_cd = '124' and*/ (city) not in ('NIAGARA FALLS', 'MONT TREMBLANT');/*Marriott Canada only locations.Niagara Falls, ON, Mont Tremblant, Quebec are not part of the program*/

Page 10: sas aeroplan sample

senumber=se10;run; /*Avis Budget Group*/ /*proc sql;connect to sybase (user=user pass=pass server=IQAX) ;create table abg as select * from connection to sybase ( select dba_nm, se10, city, state_cd, country_cd from dbo.se_char ) where upcase(dba_nm) like ('%AVIS RENT%') or upcase(dba_nm) like('%BUDGET RENT%') or upcase(dba_nm) like('%AVIS BUDGET%');quit; */ proc sql;connect to teradata (user=&tduser server=edw pass=&tdpass database=udw mode=teradata connection=global);create table abg as select * from connection to teradata ( select dba_nm, se10, city, state_cd, country_cd from udw.se_char where dba_nm (NOT CASESPECIFIC) like ('%AVIS RENT%') or dba_nm (NOT CASESPECIFIC) like ('%BUDGET RENT%') or dba_nm (NOT CASESPECIFIC) like ('%AVIS BUDGET%') ); disconnect from teradata;quit; data abg2;length senumber $10.;set abg;where country_cd in('840', '124'); /*US and Canadian Avis/Budget locations*/senumber=se10;run; /*cobrand cids*/ proc summary data=aeroplan2_&period2. nway noprint missing;class cg_id product;output out=cobrand_cids_&period2. (drop=_type_ _freq_);where product = 'Cobrand';run;

Page 11: sas aeroplan sample

/*canada & us cv*/ data canroc_&period2.;set canroc.trans_201412; /*define period2*/where senumber not in ('0000000000','0000000001', '0000000002', '0000000003', '');run; data usroc_&period2.;set usroc.trans_201412; /*define period2*/where senumber not in ('0000000000','0000000001', '0000000002', '0000000003', '');run; proc sort data=canroc_&period2.;by senumber;run; proc sort data=usroc_&period2.;by senumber;run; data roc_&period2;set usroc_&period2 canroc_&period2.;run; proc sort data=roc_&period2.;by senumber;run; /*aircanada*/ proc sort data=aircan2;by senumber;run; data ac_roc_&period2.(keep=cg_id procmon cv dba_nm);merge roc_&period2. (in=a)aircan2(in=b);by senumber;if a and b;run; proc summary data=ac_roc_&period2. nway noprint missing;class procmon cg_id;

Page 12: sas aeroplan sample

output out=ac_roc_summ_&period2. (drop=_type_ rename=(_freq_=rocs)) sum(cv)=;run; proc sort data=ac_roc_summ_&period2.;by cg_id;run; proc sort data=cobrand_cids_&period2.;by cg_id;run; data ac_cobrand_&period2.;merge ac_roc_summ_&period2. (in=a)cobrand_cids_&period2. (in=b);by cg_id;if a and b;run; proc summary data=ac_cobrand_&period2. nway noprint missing;class procmon;output out=ac_cobrand_&period2._summ (drop=_type_ _freq_)sum(rocs)=sum(cv)=;run; data ac_cobrand_&period2._summ;length partner $64.;partner="Air Canada";set ac_cobrand_&period2._summ;run; /* avis budget group us & canada cv*/ proc sort data=roc_&period2.;by senumber;run; proc sort data=abg2;by senumber;run; data abg_roc_&period2.;merge roc_&period2. (in=a)abg2(in=b);by senumber;if a and b;

Page 13: sas aeroplan sample

run; proc summary data=abg_roc_&period2. nway noprint missing;class procmon cg_id;output out=abg_roc_&period2._summ (drop=_type_ rename=(_freq_=rocs)) sum(cv)=;run; proc sort data=abg_roc_&period2._summ;by cg_id;run; proc sort data=cobrand_cids_&period2;by cg_id;run; data abg_cobrand_&period2.;merge abg_roc_&period2._summ (in=a)cobrand_cids_&period2. (in=b);by cg_id;if a and b;run; proc summary data=abg_cobrand_&period2. nway noprint missing;class procmon;output out=abg_cobrand_&period2._summ (drop=_type_ _freq_)sum(rocs)= sum(cv)= ;run; data abg_cobrand_&period2._summ;length partner $64.;partner="Avis Budget Group";set abg_cobrand_&period2._summ;run; /* marriott*/ proc sort data=marriott2;by senumber;run; data mar_roc_&period2.;merge canroc_&period2. (in=a)marriott2(in=b);by senumber;if a and b;

Page 14: sas aeroplan sample

run; proc summary data=mar_roc_&period2. nway noprint missing;class procmon cg_id;output out=mar_roc_&period2._summ (drop=_type_ rename=(_freq_ = rocs)) sum(cv)=;run; proc sort data=canroc_&period2.;by cg_id;run; proc sort data=mar_roc_&period2._summ;by cg_id;run; proc sort data=cobrand_cids_&period2.;by cg_id;run; data mar_cobrand_&period2.;merge mar_roc_&period2._summ (in=a)cobrand_cids_&period2. (in=b);by cg_id;if a and b;run; proc summary data=mar_cobrand_&period2. nway noprint missing;class procmon;output out=mar_cobrand_&period2._summ (drop=_type_ _freq_)sum(rocs)=sum(cv)=;run; data mar_cobrand_&period2._summ;length partner $64.;partner="Marriott";set mar_cobrand_&period2._summ;run; /* combine partners*/ libname aerolib "/iim/corp3/2014032_kmille_aeroplan"; data partners_cv (drop=rocs metric partner);length metric label $64.;set ac_cobrand_&period2._summ

Page 15: sas aeroplan sample

abg_cobrand_&period2._summ mar_cobrand_&period2._summ; metric='cv'; label=strip(partner)||"_"||strip(metric);run; data partners_rocs (drop=cv metric partner);length metric label $64.;set ac_cobrand_&period2._summ abg_cobrand_&period2._summ mar_cobrand_&period2._summ; metric='rocs'; label=strip(partner)||"_"||strip(metric);run; proc transpose data=partners_cv out=partners_cv(drop=_:) ; by label; id procmon; var cv; run; proc transpose data=partners_rocs out=partners_rocs(drop=_:) ; by label; id procmon; var rocs; run; data combined_&period2.;set partners_rocs partners_cv;run; /*combine acct status*/ data cv_summ(drop=currrocs_cobrand currcifs_cobrand accounts type metric);length metric label $64.;format month mmddyy10.;set acct_summ;metric = 'cv';label=strip(type)||"_"||strip(metric);month = "&period2"d;run; data rocs_summ(drop=currcv_cobrand currcifs_cobrand accounts type metric);length metric label$64.;

Page 16: sas aeroplan sample

format month mmddyy10.;set acct_summ;metric='rocs';label=strip(type)||"_"||strip(metric);month = "&period2"d;run; data cifs_summ(drop=currcv_cobrand currrocs_cobrand accounts type metric);length metric $64.;format month mmddyy10.;set acct_summ;metric='cifs';label=strip(type)||"_"||strip(metric);month = "&period2"d;run; data accounts_summ(drop=currcv_cobrand currrocs_cobrand currcifs_cobrand type metric);length metric $64.;format month mmddyy10.;set acct_summ;metric='accounts';label=strip(type)||"_"||strip(metric);month = "&period2"d;run; proc transpose data=cv_summ out=cv_summ(drop=_:) ; by label; id month; var currcv_cobrand; run; proc transpose data=rocs_summ out=rocs_summ(drop=_:) ; by label; id month; var currrocs_cobrand; run; proc transpose data=cifs_summ out=cifs_summ(drop=_:) ; by label; id month; var currcifs_cobrand; run; proc transpose data=accounts_summ out=accounts_summ(drop=_:) ;

Page 17: sas aeroplan sample

by label; id month; var accounts; run; data combined2_&period2.;set cv_summ rocs_summ cifs_summ accounts_summ combined_&period2;run; /*combine product*/ data product_cv_summ(drop=cifs rocs metric market_product tier_w tier_x cif);length metric label $64.;format month mmddyy10.;set product_&period2.;metric = 'cv';label=strip(market_product)||"_"||strip(metric)||"_"||strip(tier_w)||"_"||strip(tier_x)||"_"||strip(cif);month = "&period2"d;run; data product_cifs_summ(drop=cv_mon rocs metric market_product tier_w tier_x cif);length metric $64.;format month mmddyy10.;set product_&period2.;metric = 'cifs';label=strip(market_product)||"_"||strip(metric)||"_"||strip(tier_w)||"_"||strip(tier_x)||"_"||strip(cif);month = "&period2"d;run; data product_rocs_summ(drop=cv_mon cifs metric market_product tier_w tier_x cif);length metric $64.;format month mmddyy10.;set product_&period2.;metric = 'rocs';label=strip(market_product)||"_"||strip(metric)||"_"||strip(tier_w)||"_"||strip(tier_x)||"_"||strip(cif);month = "&period2"d;run; proc transpose data=product_cv_summ out=product_cv_summ2(drop=_:) ;

Page 18: sas aeroplan sample

by label; id month; var cv_mon; run; proc transpose data=product_cifs_summ out=product_cifs_summ2(drop=_:) ; by label; id month; var cifs; run; proc transpose data=product_rocs_summ out=product_rocs_summ2(drop=_:) ; by label; id month; var rocs; run; data aerolib.combined3_&period2.;set product_cv_summ2 product_rocs_summ2 product_cifs_summ2 combined2_&period2;run; /*monthly*/ proc sort data=aerolib.combined3_01jan2014;by label;run; proc sort data=aerolib.combined3_01feb2014;by label;run; proc sort data=aerolib.combined3_01mar2014;by label;run; proc sort data=aerolib.combined3_01apr2014;by label;run; proc sort data=aerolib.combined3_01may2014;by label;run;

Page 19: sas aeroplan sample

proc sort data=aerolib.combined3_01jun2014;by label;run; proc sort data=aerolib.combined3_01jul2014;by label;run; proc sort data=aerolib.combined3_01aug2014;by label;run; proc sort data=aerolib.combined3_01sep2014;by label;run; proc sort data=aerolib.combined3_01oct2014;by label;run; proc sort data=aerolib.combined3_01nov2014;by label;run; proc sort data=aerolib.combined3_01dec2014;by label;run; data aerolib.final;merge aerolib.combined3_01JAN2014 aerolib.combined3_01FEB2014 aerolib.combined3_01MAR2014 aerolib.combined3_01APR2014 aerolib.combined3_01MAY2014 aerolib.combined3_01JUN2014 aerolib.combined3_01JUL2014 aerolib.combined3_01AUG2014 aerolib.combined3_01SEP2014 aerolib.combined3_01OCT2014 aerolib.combined3_01NOV2014 aerolib.combined3_01DEC2014;by label;run;

Page 20: sas aeroplan sample

 Kenneth Miller-------------------------------------Corporate Insight and Analytics | RIMGlobal Corporate PaymentsAEDR - PhoenixEmail: [email protected] | Office: 602.537.9687 

American Express made the following annotations

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

American Express a ajouté le commentaire suivant le Ce courrier et toute pièce jointe qu'il contient sont réservés au seul destinataire indiqué et peuvent renfermer des renseignements confidentiels et privilégiés. Si vous n'êtes pas le destinataire prévu, toute divulgation, duplication, utilisation ou distribution du courrier ou de toute pièce jointe est interdite. Si vous avez reçu cette communication par erreur, veuillez nous en aviser par courrier et détruire immédiatement le courrier et les pièces jointes. Merci.