Loading...
Searching...
No Matches
getcolvals.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Retrieves column info to enable population of dropdowns
4 @details An optional filterquery may be provided, if so then it is validated
5 and then used to filter the subsequent results.
6
7 <h4> Service Inputs </h4>
8
9 <h5> IWANT </h5>
10
11 The STARTROW and ROWS variables are used to fetch additional values beyond
12 the initial default (4000).
13
14 |libds:$19.|col:$9.|STARTROW:8.|ROWS:8.|
15 |---|---|---|---|
16 |DC258467.MPE_X_TEST|SOME_TIME|4001|1000
17
18 <h5> FILTERQUERY </h5>
19 |GROUP_LOGIC:$3|SUBGROUP_LOGIC:$3|SUBGROUP_ID:8.|VARIABLE_NM:$32|OPERATOR_NM:$10|RAW_VALUE:$32767|
20 |---|---|---|---|---|---|
21 |AND|AND|1|SOME_BESTNUM|>|1|
22 |AND|AND|1|SOME_TIME|=|77333|
23
24 <h4> Service Outputs </h4>
25 <h5> VALS </h5>
26 The type of this column actually depends on the underlying column type, so it can change
27 |FORMATTED|UNFORMATTED|
28 |---|---|
29 |$44.00|44|
30
31 <h5> META </h5>
32 |COLUMN:$32.|SASFORMAT:$32.|STARTROW:8.|ROWS:8.|
33 |---|---|---|---|
34 |COL_NAME|DOLLAR8.2|4001|1000
35
36 <h4> SAS Macros </h4>
37 @li mf_existds.sas
38 @li mf_verifymacvars.sas
39 @li dc_assignlib.sas
40 @li mf_getvarformat.sas
41 @li mp_abort.sas
42 @li mp_cntlout.sas
43 @li mp_filtercheck.sas
44 @li mp_filtergenerate.sas
45 @li mp_validatecol.sas
46 @li mpe_validatecol.sas
47
48 @version 9.2
49 @author 4GL Apps Ltd.
50 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
51 and may not be re-distributed or re-sold without the express permission of
52 4GL Apps Ltd.
53
54**/
55%mpeinit()
56
57/* input table may or may not exist */
58data work.initvars;
59 length GROUP_LOGIC $3 SUBGROUP_LOGIC $3 SUBGROUP_ID 8 VARIABLE_NM $32
60 OPERATOR_NM $10 RAW_VALUE $32767;
61 call missing(of _all_);
62 stop;
63data work.filterquery;
64 set %sysfunc(ifc(
65 %mf_existds(work.filterquery)=1
66 ,work.filterquery
67 ,work.initvars
68 ));
69run;
70
71/* print data for debugging */
72data _null_;
73 set work.iwant;
74 put (_all_)(=);
75run;
76data _null_;
77 set work.filterquery;
78 put (_all_)(=);
79run;
80
81/**
82 * libds and col are request inputs that flow into executable positions
83 * (set &libds, proc sql select &col2). They are read from the IWANT
84 * table with symget in a data step (never re-resolved) and validated
85 * here before use - mf_getvalue would re-resolve any macro content in
86 * the value before this code ran.
87 */
88%let libds=;
89%let col2=;
90%let is_libds=0;
91%let is_col=0;
92data _null_;
93 length _libds $64 _col $32;
94 set work.iwant;
95 _libds=libds;
96 _col=col;
97 %mpe_validatecol(_libds,LIBDS,is_libds)
98 %mp_validatecol(_col,ISNAME,is_col)
99 if is_libds=0 then putlog 'ERR' 'OR: Invalid libds:' _libds;
100 if is_col=0 then putlog 'ERR' 'OR: Invalid col:' _col;
101 call symputx('is_libds',is_libds,'l');
102 call symputx('is_col',is_col,'l');
103 if is_libds=1 then call symputx('libds',upcase(_libds),'l');
104 if is_col=1 then call symputx('col2',upcase(_col),'l');
105 stop;
106run;
107
108%let is_fmt=0;
109%let startrow=1;
110%let rows=4000;
111
112%mp_abort(iftrue= (%mf_verifymacvars(libds col2)=0)
113 ,mac=&_program..sas
114 ,msg=%str(Missing inputs from iwant)
115)
116%mp_abort(iftrue= (&is_libds ne 1)
117 ,mac=&_program..sas
118 ,msg=%str(Invalid libds)
119)
120%mp_abort(iftrue= (&is_col ne 1)
121 ,mac=&_program..sas
122 ,msg=%str(Invalid col)
123)
124
125%dc_assignlib(WRITE,%scan(&libds,1,.))
126
127data _null_;
128 call missing(startrow,rows);
129 set work.iwant;
130 /* check if the request is for a format catalog */
131 call symputx('orig_libds',libds);
132 is_fmt=0;
133 if substr(cats(reverse(libds)),1,3)=:'CF-' then do;
134 libds=scan(libds,1,'-');
135 putlog "Format Catalog Captured";
136 call symputx('libds','work.fmtextract');
137 is_fmt=1;
138 end;
139 call symputx('is_fmt',is_fmt);
140 call symputx('startrow',coalesce(startrow,&startrow));
141 call symputx('rows',coalesce(rows,&rows));
142 putlog (_all_)(=);
143run;
144
145%mp_cntlout(
146 iftrue=(&is_fmt=1)
147 ,libcat=&orig_libds
148 ,fmtlist=0
149 ,cntlout=work.fmtextract
150)
151
152
153/**
154 * Validate the filter query
155 */
156%mp_filtercheck(work.filterquery,targetds=&libds,abort=YES)
157
158/**
159 * Prepare the query
160 */
161%mp_filtergenerate(work.filterquery,outref=myfilter)
162
163/* cannot %inc in a sql where clause, only data step, so - use a view */
164data work.vw_vals/view=work.vw_vals;
165 set &libds;
166 where %inc myfilter;;
167run;
168
169proc sql;
170create view work.vw_vals_sorted as
171 select distinct
172 put(&col2,%mf_getVarFormat(&libds,&col2,force=1)) as formatted,
173 &col2 as unformatted
174 from work.vw_vals;
175
176/* restrict num of output values */
177data work.vals;
178 set work.vw_vals_sorted;
179 if _n_ ge &startrow;
180 x+1;
181 if x>&rows then stop;
182 drop x;
183run;
184
185data vals;
186 /* ensure empty value if table is empty, for dropdowns */
187 if nobs=0 then output;
188 set vals nobs=nobs;
189 format unformatted ;
190 output;
191run;
192
193proc sql noprint;
194select count(*) into: nobs from work.vw_vals_sorted;
195data meta;
196 column="&col2";
197 sasformat="%mf_getVarFormat(&libds,&col2)";
198 startrow=&startrow;
199 rows=&rows;
200 nobs=&nobs;
201run;
202
203%mp_abort(iftrue= (&syscc ne 0)
204 ,mac=&_program..sas
205 ,msg=%str(syscc=&syscc)
206)
207
208%webout(OPEN)
209%webout(OBJ,vals,missing=STRING,showmeta=YES)
210%webout(OBJ,meta)
211%webout(CLOSE)
212
213
214%mpeterm()