SHARE
TWEET

Untitled

a guest Dec 14th, 2018 167 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. LIBNAME PRO '/folders/myshortcuts/SAS_myfolder/tabele';
  2.  
  3. data PRO.Tabela;
  4. set Pro.Loan;
  5. if status='A' or status='C' then loan_status=0;
  6. else loan_status=1;
  7. run;
  8. proc sort data=Pro.Tabela;
  9. by status;
  10. run;
  11. data pro.client_disp;
  12. merge pro.client(in=a) pro.disp(in=b);
  13. by client_id;
  14. if a=b;
  15. run;
  16. proc sort data=pro.tabela;
  17. by account_id;
  18. run;
  19. proc sort data=pro.account;
  20. by account_id;
  21. run;
  22. data pro.client_account;
  23. merge pro.client_disp(in=a) pro.account(in=b);
  24. by account_id;
  25. if a=b;
  26. run;
  27. proc sql;
  28. create table pro.account_client as select * from pro.client_account where type='OWNER';
  29. quit;
  30. data pro.tabela_a; /*tabela na razie wystarczy */
  31. merge pro.tabela(in=b rename=(date=credit_date)) pro.account_client(in=c);
  32. by account_id;
  33. if b;
  34. run;
  35. data pro.tabela_a;
  36. set pro.tabela_a;
  37. if(birth_number-(round(birth_number/10000))*10000)<0 then sex=1; /*kobieta*/
  38. else sex=0;
  39. age=year(credit_date)-(1900+round(birth_number/10000));
  40. client_since=round((credit_date-date)/12);
  41. run;
  42. proc sort data=pro.trans;
  43. by account_id;
  44. run;
  45. proc sort data=pro.loan;
  46. by account_id;
  47. run;
  48. data pro.trans_cred;
  49. merge pro.loan(in=a rename=(date=credit_date)) pro.trans(in=b);
  50. by account_id;
  51. if a=b;
  52. run;
  53. data pro.trans_cred;
  54. set pro.trans_cred;
  55. where date < credit_date;
  56. run;
  57. data pro.trans_cred_30;
  58. set pro.trans_cred;
  59. where date < credit_date and date > (credit_date -30);
  60. run;
  61. data pro.trans_cred_60;
  62. set pro.trans_cred;
  63. where date < credit_date and date > (credit_date -60);
  64. run;
  65. data pro.trans_cred_90;
  66. set pro.trans_cred;
  67. where date < credit_date and date > (credit_date -90);
  68. run;
  69. data pro.balance;
  70. set pro.trans_cred;
  71. by account_id;
  72. if last.account_id then output;
  73. keep account_id balance;
  74. run;
  75. data pro.credits_30;
  76. set pro.trans_cred_30(where=(type='PRIJEM'));
  77. by account_id;
  78. if first.account_id then sum_credit_30=0;
  79. sum_credit_30+amount;
  80. if last.account_id then output;
  81. keep account_id sum_credit_30;
  82. run;
  83. data pro.credits_60;
  84. set pro.trans_cred_60(where=(type='PRIJEM'));
  85. by account_id;
  86. if first.account_id then sum_credit_60=0;
  87. sum_credit_60+amount;
  88. if last.account_id then output;
  89. keep account_id sum_credit_60;
  90. run;
  91. data pro.credits_90;
  92. set pro.trans_cred_90(where=(type='PRIJEM'));
  93. by account_id;
  94. if first.account_id then sum_credit_90=0;
  95. sum_credit_90+amount;
  96. if last.account_id then output;
  97. keep account_id sum_credit_90;
  98. run;
  99. data pro.withdrawn_30;
  100. set pro.trans_cred_30(where=(type='VYDAJ'));
  101. by account_id;
  102. if first.account_id then sum_withdrawn_30=0;
  103. sum_withdrawn_30+amount;
  104. if last.account_id then output;
  105. keep account_id sum_withdrawn_30;
  106. run;
  107. data pro.withdrawn_60;
  108. set pro.trans_cred_60(where=(type='VYDAJ'));
  109. by account_id;
  110. if first.account_id then sum_withdrawn_60=0;
  111. sum_withdrawn_60+amount;
  112. if last.account_id then output;
  113. keep account_id sum_withdrawn_60;
  114. run;
  115. data pro.withdrawn_90;
  116. set pro.trans_cred_90(where=(type='VYDAJ'));
  117. by account_id;
  118. if first.account_id then sum_withdrawn_90=0;
  119. sum_withdrawn_90+amount;
  120. if last.account_id then output;
  121. keep account_id sum_withdrawn_90;
  122. run;
  123. data pro.tabela_a;
  124. merge pro.tabela_a(in=a) pro.balance(in=b);
  125. by account_id;
  126. if a=b;
  127. run;
  128. data pro.tabela_a;
  129. merge pro.tabela_a(in=a) pro.credits_30(in=b);
  130. by account_id;
  131. if a;
  132. run;
  133. data pro.tabela_a;
  134. merge pro.tabela_a(in=a) pro.credits_60(in=b);
  135. by account_id;
  136. if a;
  137. run;
  138. data pro.tabela_a;
  139. merge pro.tabela_a(in=a) pro.credits_90(in=b);
  140. by account_id;
  141. if a;
  142. run;
  143. data pro.tabela_a;
  144. merge pro.tabela_a(in=a) pro.withdrawn_30(in=b);
  145. by account_id;
  146. if a;
  147. run;
  148. data pro.tabela_a;
  149. merge pro.tabela_a(in=a) pro.withdrawn_60(in=b);
  150. by account_id;
  151. if a;
  152. run;
  153. data pro.tabela_a;
  154. merge pro.tabela_a(in=a) pro.withdrawn_90(in=b);
  155. by account_id;
  156. if a;
  157. run;
  158. data pro.tabela_a;
  159. set pro.tabela_a;
  160. if frequency='POPLATEK MESICNE' then freq_issuance=1;
  161. else if frequency='POPLATEK TYDNE' then freq_issuance=2;
  162. else freq_issuance=0;
  163. run;
  164. proc sql;
  165. create table pro.account_client_d as select * from pro.account_client order by district_id;
  166. quit;
  167. data pro.client_district;
  168. merge pro.account_client_d(in=a) pro.district(in=b rename=(A1=district_id));
  169. by district_id;
  170. if a=b;
  171. run;
  172. data pro.client_district;
  173. set pro.client_district(rename=(A11=avg_salary A12=unempl_rate_95 A13=unempl_rate_96 A14=enterpr_rate));
  174. keep account_id avg_salary unempl_rate_95 unempl_rate_96 entepr_rate;
  175. run;
  176. proc sql;
  177. create table pro.client_distr as select * from pro.client_district order by account_id;
  178. quit;
  179. data pro.tabela_a;
  180. merge pro.tabela_a(in=a) pro.client_distr(in=b);
  181. by account_id;
  182. if a=b;
  183. run;
  184. data pro.tabela_a;
  185. set pro.tabela_a;
  186. if (year(credit_date)<1996) then unempl_rate=unempl_rate_95;
  187. else unempl_rate=unempl_rate_96;
  188. drop unempl_rate_95 unempl_rate_96;
  189. run;
  190. proc sql;
  191. create table pro.cards as select * from pro.card order by disp_id;
  192. quit;
  193. data pro.account_card;
  194. merge pro.account_client(in=a) pro.cards(in=b rename=(type=card_type));
  195. by disp_id;
  196. if a=b;
  197. keep disp_id card_type issued;
  198. run;
  199. data pro.tabela_a;
  200. merge pro.tabela_a(in=a) pro.account_card(in=b);
  201. by disp_id;
  202. if a;
  203. run;
  204. data pro.tabela_a;
  205. set pro.tabela_a;
  206. if card_type='golden' and issued<credit_date then type_of_card=3;
  207. else if card_type='classic' and issued<credit_date  then type_of_card=2;
  208. else if card_type='junior' and issued<credit_date then type_of_card=1;
  209. else type_of_card=0;
  210. drop card_type issued;
  211. run;
  212. data pro.insurrance_30;
  213. set pro.trans_cred_30(where=(k_symbol='POJISTNE'));
  214. by account_id;
  215. if first.account_id then insurrance_30=0;
  216. insurrance_30+amount;
  217. if last.account_id then output;
  218. keep account_id insurrance_30;
  219. run;
  220. data pro.insurrance_90;
  221. set pro.trans_cred_90(where=(k_symbol='POJISTNE'));
  222. by account_id;
  223. if first.account_id then insurrance_90=0;
  224. insurrance_90+amount;
  225. if last.account_id then output;
  226. keep account_id insurrance_90;
  227. run;
  228. data pro.tabela_a;
  229. merge pro.tabela_a(in=a) pro.insurrance_30(in=b);
  230. by account_id;
  231. if a;
  232. run;
  233. data pro.tabela_a;
  234. merge pro.tabela_a(in=a) pro.insurrance_90(in=b);
  235. by account_id;
  236. if a;
  237. run;
  238. data pro.tabela_a;
  239. set pro.tabela_a;
  240. if insurrance_30='.' then insurrance_30=0;
  241. if insurrance_90='.' then insurrance_90=0;
  242. run;
  243.  
  244. data pro.leasing;
  245. set pro.order;
  246. by account_id;
  247. if first.account_id then has_leasing=0;
  248. if k_symbol='LEASING' then has_leasing+1;
  249. else has_leasing+0;
  250. if last.account_id then output;
  251. keep account_id has_leasing;
  252. run;
  253.  
  254. data pro.costs;
  255. set pro.order;
  256. by account_id;
  257. if first.account_id then household=0;
  258. if first.account_id then all_costs=0;
  259. if k_symbol='SIPO' then household+amount;
  260. all_costs+amount;
  261. if last.account_id then output;
  262. keep account_id household all_costs;
  263. run;
  264.  
  265. data pro.household_avg;
  266. set pro.costs;
  267. household_avg = household/all_costs;
  268. keep account_id household_avg;
  269. run;
  270.  
  271. data pro.tabela_a;
  272. merge pro.tabela_a(in=a) pro.leasing(in=b);
  273. by account_id;
  274. if a=b;
  275.  
  276. data pro.tabela_a;
  277. merge pro.tabela_a(in=a) pro.household_avg(in=b);
  278. by account_id;
  279. if a=b;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top