Thursday, April 28, 2016

Terminology For Air Business

Solution – A collection of Slices

Slice – A collection of segments containing the directional journey
Round Trip is 2 Slices
One way is 1 Slice

Segment
The smallest unit a carrier and  flight number exists

Leg
Even smaller

AA-123 ORD-MCI – leg 1, segment 1, slice 1
AA-123 MCI-LAS – leg 2, segment 1, slice 1
AA-456 LAS-SFO – leg 3, segment 2, slice 1
AA-789 SFO-ORD – leg 4, segment 3, slice 2


Oneline – Single carrier throughout the solution
AA-123
AA-456

Interline – 2 or more carriers in a solution
AA-123
UA-111

Codeshare – One “markets” a flight, a different one “operates” it

Plating carrier – the carrier that pays us commission. Only one per solution.


concatenate two data frame column r

paste(df$c1, df$c2,

Wednesday, April 27, 2016

When Random Forest Will Not Perform Better

When they are very few variables which are significant, RF will not perform better than Linear Model.

Monday, April 25, 2016

Get The Length Of Each Values In A Column

nchar takes a character vector as an argument and returns a vector whose elements contain the sizes of the corresponding elements of x.
nzchar is a fast way to find out if elements of a character vector are non-empty strings.

Why Ifelse Returns Numeric Values?

ock$ref_id2<-ifelse(substr(ock$ref_id,1,4)=="FLT.",substr(ock$ref_id,5,11),ock$ref_id)

because ref_id is factor

Saturday, April 23, 2016

How To Read Variable Length String Correctly In SAS


data oc;
infile "&file_dir./orb_air_clk_2016.csv" dlm=',' firstobs=2;
input local_date $10. mktg_code : $100. ref_id : $50. clicks spend;
run;


The : (colon) format modifier enables you to use list input but also to specify an informat after a variable name, whether character or numeric. SAS reads until it encounters a blank column, the defined length of the variable (character only), or the end of the data line, whichever comes first.

Write A SAS Dataset to A SQL Script


data _null_;
*file "/dfs/public/AA/thuang/sql/ta_orb_dsk_rpc.sql";
file "/dfs/marketing/thuang/sql/ta_orb_dsk_rpc.sql";
set rpc.ta_orb_dsk_rpc_&fid. end=last;
length sql_stmt $1000.;

if _n_ = 1 then do;

put 'DROP TABLE IF EXISTS sandbox.tch_ta_orb_dsk_rpc10;';
put 'CREATE TABLE sandbox.tch_ta_orb_dsk_rpc10 (';
put 'oneg_id INT,rpc FLOAT,new_ind INT, update_dt DATE)';
put 'DISTRIBUTED BY (oneg_id, rpc);';
put 'GRANT ALL PRIVILEGES ON sandbox.tch_ta_orb_dsk_rpc10 TO PUBLIC;';
put 'INSERT INTO sandbox.tch_ta_orb_dsk_rpc10 VALUES';

end;


if last then
sql_stmt=  compress("("||oneg_id||","||adj_rpc||","||new_ind||",'"||&update_dt.||"');");
else sql_stmt=  compress("("||oneg_id||","||adj_rpc||","||new_ind||",'"||&update_dt.||"'),");

put sql_stmt;

run;