1%macro irmst_apply_volume_calculations( map_movement_type =
6 %let j = %eval(&activationHorizon.-1);
9 proc sort data=work.volassump out=work.bep_vol_dtls;
11 where activationHorizon = &activationHorizon.;
20 sum(fund_src_vol_percent) as sum_percent
28 data work.bep_vol_posting;
30 posting_group_id length = $50. label =
"Posting Group Id"
31 movement_id length = 8. label =
"Movement Id"
32 movement_desc length = $100. label =
"Movement Description"
33 %irm_get_attrib_def(ds_in = &map_movement_type.)
34 value_src length = $64. label = "Source Model (Projection or External)"
37 set work.bep_vol_dtls;
41 declare hash hVol(dataset: "&actualsData.");
42 hVol.defineKey("account_cd");
43 hVol.defineData("amountT&j.");
47 declare hash hMvmt(dataset: "&map_movement_type.");
48 hMvmt.defineKey("movement_type_cd");
49 hMvmt.definedata("movement_type", "movement_category");
53 declare hash hMod(dataset: "work.modelResults(rename=(forecast_horizon=activationHorizon))");
54 hMod.defineKey("account_cd","activationHorizon");
55 hMod.definedata("amount_model");
59 declare hash perTotLookup(dataset: "work.fundSourceTotals");
60 perTotLookup.defineKey("account_cd");
61 perTotLookup.definedata("sum_percent");
62 perTotLookup.defineDone();
65 call missing(amountT&j.,amount_model,movement_type,movement_category);
68 movement_type_cd = "BS_MODEL";
69 movement_desc = "Volume Assumptions";
75 posting_group_id = cats('VOL_',account_cd);
77 if hVol.find() = 0 then do;
78 if value_src = 'external_model' then do;
80 var = (amount_model-amountT&j.);
82 else if value_src = 'projection_model' then do;
83 bbook = amountT&j.*(1-runoff_bb);
84 fbook = (amountT&j.*growth)*(1-runoff_fb);
85 var = (bbook-amountT&j.)+fbook;
88 if first.account_cd then do;
89 posting_account_id = account_cd;
93 posting_account_id = fund_src_vol_source;
94 call missing(sum_percent);
95 _rc_= perTotLookup.find();
96 if _rc_ ne 0 then sum_percent = 100;
97 variation = -(var * fund_src_vol_percent / sum_percent);
101 put "WARNING: No matching record found in actualsData for record " account_id;
107 create table work.vol_aggregate as
110 , coalesce(t2.amountT&j.,t1.amountT&j.) as amountT&j.
114 , coalesce(t3.vol_variation,0) as vol_variation
116 from (select distinct account_id
119 from &actualsData.) t1
120 left join (select distinct account_id
127 from work.bep_vol_posting) t2
128 on t1.account_cd=t2.account_cd
129 left join (select posting_account_id
130 , sum(variation) as vol_variation
131 from work.bep_vol_posting
132 group by posting_account_id) t3
133 on t1.account_cd=t3.posting_account_id
136%mend irmst_apply_volume_calculations;