Loading...
Searching...
No Matches
mpe_tables.dsn.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief fetch extended values for DSN
4 @details Fetches datasets in a library, and ALSO fetches a list of numeric
5 vars for each dataset for use in adjacent columns (such as VAR_PROCESSED,
6 TX_TO etc).
7
8 Available macro variables:
9 @li MPELIB - The DC control library
10 @li LIBDS - The library.dataset being filtered
11 @li VARIABLE_NM - The column being filtered
12
13
14 <h4> Service Outputs </h4>
15 Output should be a single table called "work.dynamic_values" in the format
16 below.
17
18 <h5>DYNAMIC_VALUES</h5>
19 The RAW_VALUE column may be charactor or numeric. If DISPLAY_INDEX is not
20 provided, it is added automatically.
21
22 |DISPLAY_INDEX:best.|RAW_VALUE|
23 |---|---|
24 |1|77.43|
25 |2|88.43|
26
27 <h5>DYNAMIC_EXTENDED_VALUES</h5>
28 This table is optional. If provided, it will map the DISPLAY_INDEX from the
29 DYNAMIC_VALUES table to additional column/value pairs, that will be used to
30 populate dropdowns for _other_ cells in the _same_ row.
31
32 Should be used sparingly! The use of large tables here can slow down the
33 browser.
34
35 The FORCED_VALUE column can be used to force an extended value to be selected
36 by default when a particular value is chosen.
37
38 |DISPLAY_INDEX|EXTRA_COL_NAME:$32.|DISPLAY_TYPE:$1.|RAW_VALUE_NUM|RAW_VALUE_CHAR:$5000|
39 |---|---|---|---|---|
40 |1|DISCOUNT_RT|N|0.5||
41 |1|DISCOUNT_RT|N|0.4||
42 |1|DISCOUNT_RT|N|0.3||
43 |1|CURRENCY_SYMBOL|C||"GBP"|
44 |1|CURRENCY_SYMBOL|C||"RSD"|
45 |2|DISCOUNT_RT|N|0.5||
46 |2|DISCOUNT_RT|N|0.4||
47 |2|CURRENCY_SYMBOL|C||"EUR"|
48 |2|CURRENCY_SYMBOL|C||"HKD"|
49
50
51 <h4> SAS Macros </h4>
52 @li dc_getlibs.sas
53
54
55**/
56
57
58/* send back the raw and formatted values */
59%let tgtlib=0;
60%let varlibds=%mf_getuniquename();
61%let vartgtlib=%mf_getuniquename();
62%let var_is_lib=%mf_getuniquename();
63data _null_;
64 length &varlibds $41 &vartgtlib $8;
65 set work.source_row;
66 &varlibds=upcase(symget('libds'));
67 if &varlibds="&mpelib..MPE_TABLES" then &vartgtlib=LIBREF;
68 else putlog "something unexpected happened";
69
70 /* validate name */
71 if nvalid(&vartgtlib,'v7') then call symputx('tgtlib',&vartgtlib);
72 call symputx('vartgtlib',&vartgtlib);
73
74 putlog (_all_)(=);
75run;
76
77%mp_abort(iftrue= ("&tgtlib" ="0" )
78 ,mac=&_program..sas
79 ,msg=%str(Invalid library - %superq(vartgtlib))
80 ,errds=work.dc_error_response
81)
82
83%dc_assignlib(READ,&tgtlib)
84
85
86proc sql;
87create table work.source as
88 select upcase(memname) as memname
89 ,upcase(name) as name
90 ,type
91 from dictionary.columns
92 where libname="&TGTLIB"
93 and memtype='DATA';
94
95create table work.members as
96 select distinct upcase(memname) as raw_value
97 from work.source;
98
99data work.DYNAMIC_VALUES;
100 set work.members;
101 display_index=_n_;
102run;
103
104proc sql;
105create table work.dynamic_extended_values as
106 select a.display_index
107 ,a.raw_value
108 ,"C" as display_type
109 ,b.name as RAW_VALUE_CHAR
110 ,. as RAW_VALUE_NUM
111 from work.dynamic_values a
112 left join work.source b
113 on a.raw_value=b.memname
114 where b.type='num';
115
116data work.dynamic_extended_values;
117 set work.DYNAMIC_EXTENDED_VALUES;
118 extra_col_name='VAR_PROCESSED';output;
119 extra_col_name='VAR_TXFROM';output;
120 extra_col_name='VAR_TXTO';output;
121 extra_col_name='VAR_BUSFROM';output;
122 extra_col_name='VAR_BUSTO';output;
123run;
124/* set some force flags */
125data work.dynamic_extended_values;
126 set work.DYNAMIC_EXTENDED_VALUES;
127 forced_value=0;
128 if extra_col_name='VAR_TXFROM' & raw_value_char='TX_FROM' then forced_value=1;
129 if extra_col_name='VAR_TXTO' & raw_value_char='TX_TO' then forced_value=1;
130run;
131
132proc sort;
133 by extra_col_name display_index;
134run;