SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_market_regenerate_econsim.sas
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 SAS Institute Inc. Cary, NC, USA
3 */
4
5/**
6 \file
7 \anchor irmst_market_regenerate_econsim
8
9 \brief This macro regenerates the economic simulation data using the scenario data.
10
11 \details
12
13 Assuming that a group of variables, var_1-var_k, are avaialble both in the scenario and in the economic simulation,
14 Then var_1-var_k in the economic simulation data set are recreated as:
15 var_1=var1(from the scenario)*var_1(from the economic simulation)
16 var_2=var2(from the scenario)*var_2(from the economic simulation)
17 ............
18 var_k=var_k(from the scenario)*var_k(from the economic simulation)
19
20 \ingroup DynamicPortfolio
21
22 \author SAS Institute INC.
23 \date 2021
24*/
25
26%macro irmst_market_regenerate_econsim(ds_in_scenario =
27 , ds_in_econsim =
28 );
29
30 %local
31 __common__vars__cnt__
32 __common__vars__
33 __common__vars__csv__
34 __common__vars__quoted__csv__
35 ;
36
37 proc contents data=&ds_in_econsim. out=econsim_cont(keep=NAME);
38 run;
39 proc sort data=econsim_cont;
40 by name;
41 run;
42
43 proc contents data=&ds_in_scenario. out=scenario_cont(keep=NAME);
44 run;
45 proc sort data=scenario_cont;
46 by name;
47 run;
48
49 data common_vars;
50 merge econsim_cont(in=a) scenario_cont(in=b);
51 by name;
52 if a and b then output;
53 run;
54
55 proc sql noprint;
56 select count(*), name into :__common__vars__cnt__, :__common__vars__ separated by " "
57 from common_vars;
58 quit;
59
60
61 %if &__common__vars__cnt__.>0 %then %do;
62
63 %put NOTE: This is a short summary about the common variables: &=__common__vars__cnt__ &=__common__vars__;
64
65 /* Create an unquoted list of the by variables separated by commas */
66 %let __common__vars__csv__ = %sysfunc(prxchange(s/\s+/%str(, )/i, -1, &__common__vars__.));
67 /* Create a quoted list of the by variables separated by commas */
68 %let __common__vars__quoted__csv__ = %sysfunc(prxchange(s/(\w+)/"$1"/i, -1, %bquote(&__common__vars__csv__.)));
69
70
71 data &ds_in_econsim.;
72 set &ds_in_econsim.;
73 if _N_=1 then do;
74 declare hash h(dataset: "&ds_in_scenario.(rename=(date=_date_)");
75 h.definedata(&__common__vars__quoted__csv__.);
76 h.definekey("_date_");
77 h.defineDone();
78 end;
79 %do i_var=1 %to &__common__vars__cnt__.;
80 var_&i_var.=%scan(&__common__vars__., &i_var., %str( ));
81 %end;
82 rc=h.find();
83 if rc=0 then do;
84 %do i_var=1 %to &__common__vars__cnt__.;
85 %scan(&__common__vars__., &i_var., %str( ))=var_&i_var. * %scan(&__common__vars__., &i_var., %str( )) ;
86 %end;
87 end;
88 *drop rc;
89 run;
90
91 %put NOTE: The Regeneration of the economic simulation data has been performed.;
92 %end;
93 %else %do;
94 %put NOTE: The Regeneration of the economic simulation data has not been performed.;
95 %put NOTE: There are not common variables between the scenario data set and the economic scenario data set.;
96 %end;
97
98%mend;