Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. LIBNAME PROJECT '/home/mlglazewska0/BIBL';
  2. data PROJECT.tmp;
  3. set PROJECT.Loan;
  4. if status='A' or status='C' then loan_status=0;
  5. else loan_status=1;
  6. run;
  7. proc sort data=PROJECT.tmp;
  8. by status;
  9. run;
  10. data PROJECT.client_disp;
  11. merge PROJECT.client(in=a) PROJECT.disp(in=b);
  12. by client_id;
  13. if a=b;
  14. run;
  15. proc sort data=PROJECT.tmp;
  16. by account_id;
  17. run;
  18. proc sort data=PROJECT.account;
  19. by account_id;
  20. run;
  21. data PROJECT.client_account;
  22. merge PROJECT.client_disp(in=a) PROJECT.account(in=b);
  23. by account_id;
  24. if a=b;
  25. run;
  26. proc sql;
  27. create table PROJECT.owner_account as select * from PROJECT.client_account where type='OWNER';
  28. quit;
  29. data PROJECT.result;
  30. merge PROJECT.tmp(in=b rename=(date=credit_date)) PROJECT.owner_account(in=c);
  31. by account_id;
  32. if b;
  33. run;
  34. data PROJECT.result;
  35. set PROJECT.result;
  36. if(birth_number-(round(birth_number/10000))*10000)<0 then sex=1;
  37. else sex=0;
  38. age=year(credit_date)-(1900+round(birth_number/10000));
  39. seniority=round((credit_date-date)/12);
  40. run;
  41. proc sort data=PROJECT.trans;
  42. by account_id;
  43. run;
  44. proc sort data=PROJECT.loan;
  45. by account_id;
  46. run;
  47. data PROJECT.amount;
  48. merge PROJECT.loan(in=a rename=(date=credit_date)) PROJECT.trans(in=b);
  49. by account_id;
  50. if a=b;
  51. run;
  52. data PROJECT.amount;
  53. set PROJECT.amount;
  54. where date < credit_date;
  55. run;
  56.  
  57. data PROJECT.amount_30;
  58. set PROJECT.amount;
  59. where date < credit_date and date > (credit_date -30);
  60. run;
  61. data PROJECT.amount_60;
  62. set PROJECT.amount;
  63. where date < credit_date and date > (credit_date -60);
  64. run;
  65. data PROJECT.amount_90;
  66. set PROJECT.amount;
  67. where date < credit_date and date > (credit_date -90);
  68. run;
  69.  
  70. data PROJECT.balance;
  71. set PROJECT.amount;
  72. by account_id;
  73. if last.account_id then output;
  74. keep account_id balance;
  75. run;
  76. data PROJECT.payments_30;
  77. set PROJECT.amount_30(where=(type='PRIJEM'));
  78. by account_id;
  79. if first.account_id then payment_30=0;
  80. payment_30+amount;
  81. if last.account_id then output;
  82. keep account_id payment_30;
  83. run;
  84. data PROJECT.payments_60;
  85. set PROJECT.amount_60(where=(type='PRIJEM'));
  86. by account_id;
  87. if first.account_id then payment_60=0;
  88. payment_60+amount;
  89. if last.account_id then output;
  90. keep account_id payment_60;
  91. run;
  92. data PROJECT.payments_90;
  93. set PROJECT.amount_90(where=(type='PRIJEM'));
  94. by account_id;
  95. if first.account_id then payment_90=0;
  96. payment_90+amount;
  97. if last.account_id then output;
  98. keep account_id payment_90;
  99. run;
  100. data PROJECT.withdrawns_30;
  101. set PROJECT.amount_30(where=(type='VYDAJ'));
  102. by account_id;
  103. if first.account_id then withdrawn_30=0;
  104. withdrawn_30+amount;
  105. if last.account_id then output;
  106. keep account_id withdrawn_30;
  107. run;
  108. data PROJECT.withdrawns_60;
  109. set PROJECT.amount_60(where=(type='VYDAJ'));
  110. by account_id;
  111. if first.account_id then withdrawn_60=0;
  112. withdrawn_60+amount;
  113. if last.account_id then output;
  114. keep account_id withdrawn_60;
  115. run;
  116. data PROJECT.withdrawns_90;
  117. set PROJECT.amount_90(where=(type='VYDAJ'));
  118. by account_id;
  119. if first.account_id then withdrawn_90=0;
  120. withdrawn_90+amount;
  121. if last.account_id then output;
  122. keep account_id withdrawn_90;
  123. run;
  124. data PROJECT.result;
  125. merge PROJECT.result(in=a) PROJECT.balance(in=b);
  126. by account_id;
  127. if a=b;
  128. run;
  129. data PROJECT.result;
  130. merge PROJECT.result(in=a) PROJECT.payments_30(in=b);
  131. by account_id;
  132. if a;
  133. run;
  134. data PROJECT.result;
  135. merge PROJECT.result(in=a) PROJECT.payments_60(in=b);
  136. by account_id;
  137. if a;
  138. run;
  139. data PROJECT.result;
  140. merge PROJECT.result(in=a) PROJECT.payments_90(in=b);
  141. by account_id;
  142. if a;
  143. run;
  144. data PROJECT.result;
  145. merge PROJECT.result(in=a) PROJECT.withdrawns_30(in=b);
  146. by account_id;
  147. if a;
  148. run;
  149. data PROJECT.result;
  150. merge PROJECT.result(in=a) PROJECT.withdrawns_60(in=b);
  151. by account_id;
  152. if a;
  153. run;
  154. data PROJECT.result;
  155. merge PROJECT.result(in=a) PROJECT.withdrawns_90(in=b);
  156. by account_id;
  157. if a;
  158. run;
  159. data PROJECT.result;
  160. set PROJECT.result;
  161. if frequency='POPLATEK MESICNE' then transaction_frequency=1;
  162. else if frequency='POPLATEK TYDNE' then transaction_frequency=2;
  163. else transaction_frequency=0;
  164. run;
  165. proc sql;
  166. create table PROJECT.owner_district as select * from PROJECT.owner_account order by district_id;
  167. quit;
  168. data PROJECT.client_d;
  169. merge PROJECT.owner_district(in=a) PROJECT.district(in=b rename=(A1=district_id));
  170. by district_id;
  171. if a=b;
  172. run;
  173. data PROJECT.client_district_s;
  174. set PROJECT.client_d(rename=(A10=urban_level A11=salary_avg A12=unemployment_95 A13=unemployment_96 A14=enterprises));
  175. keep account_id urban_level salary_avg unemployment_95 unemployment_96 enterprises;
  176. run;
  177. proc sql;
  178. create table PROJECT.client_district as select * from PROJECT.client_district_s order by account_id;
  179. quit;
  180. data PROJECT.result;
  181. merge PROJECT.result(in=a) PROJECT.client_district(in=b);
  182. by account_id;
  183. if a=b;
  184. run;
  185. data PROJECT.result;
  186. set PROJECT.result;
  187. if (year(credit_date)<1996) then unemployment=unemployment_95;
  188. else unemployment=unemployment_96;
  189. drop unemployment_95 unemployment_96;
  190. run;
  191. proc sql;
  192. create table PROJECT.cards as select * from PROJECT.card order by disp_id;
  193. quit;
  194. data PROJECT.account_card;
  195. merge PROJECT.owner_account(in=a) PROJECT.cards(in=b rename=(type=card_type));
  196. by disp_id;
  197. if a=b;
  198. keep disp_id card_type issued;
  199. run;
  200. data PROJECT.result;
  201. merge PROJECT.result(in=a) PROJECT.account_card(in=b);
  202. by disp_id;
  203. if a;
  204. run;
  205. data PROJECT.result;
  206. set PROJECT.result;
  207. if card_type='golden' and issued<credit_date then type_of_card=3;
  208. else if card_type='classic' and issued<credit_date then type_of_card=2;
  209. else if card_type='junior' and issued<credit_date then type_of_card=1;
  210. else type_of_card=0;
  211. drop card_type issued;
  212. run;
  213. data PROJECT.insurrance_30;
  214. set PROJECT.amount_30(where=(k_symbol='POJISTNE'));
  215. by account_id;
  216. if first.account_id then insurrance_30=0;
  217. insurrance_30+amount;
  218. if last.account_id then output;
  219. keep account_id insurrance_30;
  220. run;
  221. data PROJECT.insurrance_90;
  222. set PROJECT.amount_90(where=(k_symbol='POJISTNE'));
  223. by account_id;
  224. if first.account_id then insurrance_90=0;
  225. insurrance_90+amount;
  226. if last.account_id then output;
  227. keep account_id insurrance_90;
  228. run;
  229. data PROJECT.result;
  230. merge PROJECT.result(in=a) PROJECT.insurrance_30(in=b);
  231. by account_id;
  232. if a;
  233. run;
  234. data PROJECT.result;
  235. merge PROJECT.result(in=a) PROJECT.insurrance_90(in=b);
  236. by account_id;
  237. if a;
  238. run;
  239. data PROJECT.result;
  240. set PROJECT.result;
  241. if insurrance_30='.' then insurrance_30=0;
  242. if insurrance_90='.' then insurrance_90=0;
  243. run;
  244. data PROJECT.costs;
  245. set PROJECT.order;
  246. by account_id;
  247. if first.account_id then household=0;
  248. if first.account_id then all_costs=0;
  249. if k_symbol='SIPO' then household+amount;
  250. all_costs+amount;
  251. if last.account_id then output;
  252. keep account_id household all_costs;
  253. run;
  254.  
  255. data PROJECT.household_avg;
  256. set PROJECT.costs;
  257. household_avg = round(household/all_costs,0.01);
  258. keep account_id all_costs household_avg;
  259. run;
  260.  
  261. data PROJECT.result;
  262. merge PROJECT.result(in=a) PROJECT.household_avg(in=b);
  263. by account_id;
  264. if a=b;
  265. run;
  266. data PROJECT.client_crime;
  267. set PROJECT.client_district;
  268. crimes_rate_95=round(A15/10000,0.01);
  269. crimes_rate_96=round(A16/10000,0.01);
  270. keep account_id crimes_rate_95 crimes_rate_96;
  271. run;
  272. proc sql;
  273. create table PROJECT.district_crime as select * from PROJECT.client_crime order by account_id;
  274. quit;
  275. data PROJECT.result;
  276. merge PROJECT.result(in=a) PROJECT.district_crime(in=b);
  277. by account_id;
  278. if a=b;
  279. run;
  280. data PROJECT.result;
  281. set PROJECT.result;
  282. if (year(credit_date)<1996) then crimes_rate=crimes_rate_95;
  283. else crimes_rate=crimes_rate_96;
  284. drop crimes_rate_95 crimes_rate_96;
  285. run;
  286. data PROJECT.municipal;
  287. set PROJECT.district;
  288. if round(A8/(SUM(A5,A6,A7)),0.01)='.' then municipal=0;
  289. else municipal = round(A8/(SUM(A5,A6,A7)),0.01);
  290. KEEP A1 municipal;
  291. run;
  292. PROC SORT data=PROJECT.result;
  293. by district_id;
  294. run;
  295. data PROJECT.result;
  296. merge PROJECT.result(in=a) PROJECT.municipal(in=b rename=(A1=district_id));
  297. by district_id;
  298. if a=b;
  299. run;
  300. PROC SORT data=PROJECT.result;
  301. by account_id;
  302. run;
  303. data PROJECT.sanctions;
  304. set PROJECT.trans;
  305. by account_id;
  306. if first.account_id then sanction=0;
  307. if k_symbol in ('UROK', 'SANKC') then sanction=1;
  308. else sanction=0;
  309. if last.account_id then output;
  310. keep account_id sanction;
  311. run;
  312. data PROJECT.other_loan;
  313. set PROJECT.trans;
  314. by account_id;
  315. if first.account_id then other_loan=0;
  316. if k_symbol ='UVER' then other_loan=1;
  317. else other_loan=0;
  318. if last.account_id then output;
  319. keep account_id other_loan;
  320. run;
  321. data PROJECT.result;
  322. merge PROJECT.result(in=a) PROJECT.sanctions(in=b);
  323. by account_id;
  324. if a=b;
  325. run;
  326.  
  327. data PROJECT.result;
  328. merge PROJECT.result(in=a) PROJECT.other_loan(in=b);
  329. by account_id;
  330. if a=b;
  331. run;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement