@sasjs/core 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,92 @@
1
+ /**
2
+ @file
3
+ @brief Create the permanent Core tables
4
+ @details Several macros in the [core](https://github.com/sasjs/core) library
5
+ make use of permanent tables. To avoid duplication in definitions, this
6
+ macro provides a central location for managing the corresponding DDL.
7
+
8
+ Example usage:
9
+
10
+ %mp_coretable(LOCKTABLE,libds=work.locktable)
11
+
12
+ @param [in] table_ref The type of table to create. Example values:
13
+ @li FILTER_DETAIL - For storing detailed filter values. Used by
14
+ mp_filterstore.sas.
15
+ @li FILTER_SUMMARY - For storing summary filter values. Used by
16
+ mp_filterstore.sas.
17
+ @li LOCKANYTABLE - For "locking" tables prior to multipass loads. Used by
18
+ mp_lockanytable.sas
19
+ @li MAXKEYTABLE - For storing the maximum retained key information. Used
20
+ by mp_retainedkey.sas
21
+ @param [in] libds= (0) The library.dataset reference used to create the table.
22
+ If not provided, then the DDL is simply printed to the log.
23
+
24
+ <h4> Related Macros </h4>
25
+ @li mp_filterstore.sas
26
+ @li mp_lockanytable.sas
27
+ @li mp_retainedkey.sas
28
+
29
+ @version 9.2
30
+ @author Allan Bowe
31
+
32
+ **/
33
+
34
+ %macro mp_coretable(table_ref,libds=0
35
+ )/*/STORE SOURCE*/;
36
+ %local outds ;
37
+ %let outds=%sysfunc(ifc(&libds=0,_data_,&libds));
38
+ proc sql;
39
+ %if &table_ref=LOCKTABLE %then %do;
40
+ create table &outds(
41
+ lock_lib char(8),
42
+ lock_ds char(32),
43
+ lock_status_cd char(10) not null,
44
+ lock_user_nm char(100) not null ,
45
+ lock_ref char(200),
46
+ lock_pid char(10),
47
+ lock_start_dttm num format=E8601DT26.6,
48
+ lock_end_dttm num format=E8601DT26.6,
49
+ constraint pk_mp_lockanytable primary key(lock_lib,lock_ds));
50
+ %end;
51
+ %else %if &table_ref=FILTER_SUMMARY %then %do;
52
+ create table &outds(
53
+ filter_rk num not null,
54
+ filter_hash char(32) not null,
55
+ filter_table char(41) not null,
56
+ processed_dttm num not null format=E8601DT26.6,
57
+ constraint pk_mpe_filteranytable
58
+ primary key(filter_rk));
59
+ %end;
60
+ %else %if &table_ref=FILTER_DETAIL %then %do;
61
+ create table &outds(
62
+ filter_hash char(32) not null,
63
+ filter_line num not null,
64
+ group_logic char(3) not null,
65
+ subgroup_logic char(3) not null,
66
+ subgroup_id num not null,
67
+ variable_nm varchar(32) not null,
68
+ operator_nm varchar(12) not null,
69
+ raw_value varchar(4000) not null,
70
+ processed_dttm num not null format=E8601DT26.6,
71
+ constraint pk_mpe_filteranytable
72
+ primary key(filter_hash,filter_line));
73
+ %end;
74
+ %else %if &table_ref=MAXKEYTABLE %then %do;
75
+ create table &outds(
76
+ keytable varchar(41) label='Base table in libref.dataset format',
77
+ keycolumn char(32) format=$32.
78
+ label='The Retained key field containing the key values.',
79
+ max_key num label=
80
+ 'Integer representing current max RK or SK value in the KEYTABLE',
81
+ processed_dttm num format=E8601DT26.6
82
+ label='Datetime this value was last updated',
83
+ constraint pk_mpe_maxkeyvalues
84
+ primary key(keytable));
85
+ %end;
86
+
87
+
88
+ %if &libds=0 %then %do;
89
+ describe table &syslast;
90
+ drop table &syslast;
91
+ %end;
92
+ %mend mp_coretable;
@@ -0,0 +1,213 @@
1
+ /**
2
+ @file
3
+ @brief Checks & Stores an input filter table and returns the Filter Key
4
+ @details Used to generate a FILTER_RK from an input query dataset. This
5
+ process requires several permanent tables (names are configurable). The
6
+ benefit of storing query values at backend is to enable stored 'views' of
7
+ filtered tables at frontend (ie, when building [SAS-Powered Apps](
8
+ https://sasapps.io)). This macro is also used in [Data Controller for SAS](
9
+ https://datacontroller.io).
10
+
11
+
12
+ @param [in] libds= The target dataset to be filtered (lib should be assigned)
13
+ @param [in] queryds= (WORK.FILTERQUERY) The temporary input query dataset to
14
+ be validated. Has the following format:
15
+ |GROUP_LOGIC:$3|SUBGROUP_LOGIC:$3|SUBGROUP_ID:8.|VARIABLE_NM:$32|OPERATOR_NM:$10|RAW_VALUE:$32767|
16
+ |---|---|---|---|---|---|
17
+ |AND|AND|1|SOME_BESTNUM|>|1|
18
+ |AND|AND|1|SOME_TIME|=|77333|
19
+ @param [in] filter_summary= (PERM.FILTER_SUMMARY) Permanent table containing
20
+ summary filter values. The definition is available by running
21
+ mp_coretable.sas as follows: `mp_coretable(FILTER_SUMMARY)`. Example
22
+ values:
23
+ |FILTER_RK:best.|FILTER_HASH:$32.|FILTER_TABLE:$41.|PROCESSED_DTTM:datetime19.|
24
+ |---|---|---|---|
25
+ |`1 `|`540E96F566D194AB58DD4C413C99C9DB `|`VIYA6014.MPE_TABLES `|`1956084246 `|
26
+ |`2 `|`87737DB9EEE2650F5C89956CEAD0A14F `|`VIYA6014.MPE_X_TEST `|`1956084452.1`|
27
+ |`3 `|`8048BD908DBBD83D013560734E90D394 `|`VIYA6014.MPE_TABLES `|`1956093620.6`|
28
+ @param [in] filter_detail= (PERM.FILTER_DETAIL) Permanent table containing
29
+ detailed (raw) filter values. The definition is available by running
30
+ mp_coretable.sas as follows: `mp_coretable(FILTER_DETAIL)`. Example
31
+ values:
32
+ |FILTER_HASH:$32.|FILTER_LINE:best.|GROUP_LOGIC:$3.|SUBGROUP_LOGIC:$3.|SUBGROUP_ID:best.|VARIABLE_NM:$32.|OPERATOR_NM:$12.|RAW_VALUE:$4000.|PROCESSED_DTTM:datetime19.|
33
+ |---|---|---|---|---|---|---|---|---|
34
+ |`540E96F566D194AB58DD4C413C99C9DB `|`1 `|`AND `|`AND `|`1 `|`LIBREF `|`CONTAINS `|`DC`|`1956084245.8 `|
35
+ |`540E96F566D194AB58DD4C413C99C9DB `|`2 `|`AND `|`OR `|`2 `|`DSN `|`= `|` MPE_LOCK_ANYTABLE `|`1956084245.8 `|
36
+ |`87737DB9EEE2650F5C89956CEAD0A14F `|`1 `|`AND `|`AND `|`1 `|`PRIMARY_KEY_FIELD `|`IN `|`(1,2,3) `|`1956084451.9 `|
37
+ @param [in] lock_table= (PERM.LOCK_TABLE) Permanent locking table. Used to
38
+ manage concurrent access. The definition is available by running
39
+ mp_coretable.sas as follows: `mp_coretable(LOCKTABLE)`.
40
+ @param [in] maxkeytable= (0) Optional permanent reference table used for
41
+ retained key tracking. Described in mp_retainedkey.sas.
42
+ @param [in] mdebug= set to 1 to enable DEBUG messages
43
+ @param [out] outresult= The result table with the FILTER_RK
44
+ @param [out] outquery= The original query, taken as extract after table load
45
+
46
+
47
+ <h4> SAS Macros </h4>
48
+ @li mf_getuniquename.sas
49
+ @li mf_getvalue.sas
50
+ @li mf_islibds.sas
51
+ @li mf_nobs.sas
52
+ @li mp_abort.sas
53
+ @li mp_filtercheck.sas
54
+ @li mp_hashdataset.sas
55
+ @li mp_retainedkey.sas
56
+
57
+ <h4> Related Macros </h4>
58
+ @li mp_filtercheck.sas
59
+ @li mp_filtergenerate.sas
60
+ @li mp_filtervalidate.sas
61
+ @li mp_filterstore.test.sas
62
+
63
+ @version 9.2
64
+ @author [Allan Bowe](https://www.linkedin.com/in/allanbowe)
65
+
66
+ **/
67
+
68
+ %macro mp_filterstore(libds=,
69
+ queryds=work.filterquery,
70
+ filter_summary=PERM.FILTER_SUMMARY,
71
+ filter_detail=PERM.FILTER_DETAIL,
72
+ lock_table=PERM.LOCK_TABLE,
73
+ maxkeytable=PERM.MAXKEYTABLE,
74
+ outresult=work.result,
75
+ outquery=work.query,
76
+ mdebug=1
77
+ );
78
+ %put &sysmacroname entry vars:;
79
+ %put _local_;
80
+
81
+ %local ds1 ds2 ds3 ds4 filter_hash;
82
+ %mp_abort(iftrue= (&syscc ne 0)
83
+ ,mac=mp_filterstore
84
+ ,msg=%str(syscc=&syscc on macro entry)
85
+ )
86
+ %mp_abort(iftrue= (%mf_islibds(&filter_summary)=0)
87
+ ,mac=mp_filterstore
88
+ ,msg=%str(Invalid filter_summary value: &filter_summary)
89
+ )
90
+ %mp_abort(iftrue= (%mf_islibds(&filter_detail)=0)
91
+ ,mac=mp_filterstore
92
+ ,msg=%str(Invalid filter_detail value: &filter_detail)
93
+ )
94
+ %mp_abort(iftrue= (%mf_islibds(&lock_table)=0)
95
+ ,mac=mp_filterstore
96
+ ,msg=%str(Invalid lock_table value: &lock_table)
97
+ )
98
+
99
+ /* validate query */
100
+ %mp_filtercheck(&queryds,targetds=&libds,abort=YES)
101
+
102
+ /* hash the result */
103
+ %let ds1=%mf_getuniquename(prefix=hashds);
104
+ %mp_hashdataset(&queryds,outds=&ds1,salt=&libds)
105
+ %let filter_hash=%upcase(%mf_getvalue(&ds1,hashkey));
106
+ %if &mdebug=1 %then %do;
107
+ data _null_;
108
+ putlog "filter_hash=&filter_hash";
109
+ set &ds1;
110
+ putlog (_all_)(=);
111
+ run;
112
+ %end;
113
+
114
+ /* check if data already exists for this hash */
115
+ data &outresult;
116
+ set &filter_summary;
117
+ where filter_hash="&filter_hash";
118
+ run;
119
+
120
+ %mp_abort(iftrue= (&syscc ne 0)
121
+ ,mac=mp_filterstore
122
+ ,msg=%str(syscc=&syscc after hash check)
123
+ )
124
+ %mp_abort(iftrue= ("&filter_hash"=" ")
125
+ ,mac=mp_filterstore
126
+ ,msg=%str(problem with filter_hash generation)
127
+ )
128
+
129
+ %if %mf_nobs(&outresult)=0 %then %do;
130
+
131
+ /* update detail table first */
132
+ %let ds2=%mf_getuniquename(prefix=filterdetail);
133
+ data &ds2;
134
+ if 0 then set &filter_detail;
135
+ set &queryds;
136
+ format filter_hash $hex32. filter_line 8. processed_dttm E8601DT26.6;
137
+ filter_hash="&filter_hash";
138
+ filter_line=_n_;
139
+ PROCESSED_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt;
140
+ run;
141
+ %mp_lockanytable(LOCK,
142
+ lib=%scan(&filter_detail,1,.)
143
+ ,ds=%scan(&filter_detail,2,.)
144
+ ,ref=MP_FILTERSTORE update - &filter_hash
145
+ ,ctl_ds=&lock_table
146
+ )
147
+ proc append base=&filter_detail data=&ds2;
148
+ run;
149
+
150
+ %mp_lockanytable(UNLOCK,
151
+ lib=%scan(&filter_detail,1,.)
152
+ ,ds=%scan(&filter_detail,2,.)
153
+ ,ref=MP_FILTERSTORE update - &filter_hash
154
+ ,ctl_ds=&lock_table
155
+ )
156
+
157
+ /* now update summary table */
158
+ %let ds3=%mf_getuniquename(prefix=filtersum);
159
+ data &ds3;
160
+ if 0 then set &filter_summary;
161
+ filter_table=symget('libds');
162
+ filter_hash="&filter_hash";
163
+ PROCESSED_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt;
164
+ output;
165
+ stop;
166
+ run;
167
+
168
+ %mp_lockanytable(LOCK,
169
+ lib=%scan(&filter_summary,1,.)
170
+ ,ds=%scan(&filter_summary,2,.)
171
+ ,ref=MP_FILTERSTORE update - &filter_hash
172
+ ,ctl_ds=&lock_table
173
+ )
174
+
175
+ %let ds4=%mf_getuniquename(prefix=filtersumappend);
176
+ %mp_retainedkey(
177
+ base_lib=%scan(&filter_summary,1,.)
178
+ ,base_dsn=%scan(&filter_summary,2,.)
179
+ ,append_lib=work
180
+ ,append_dsn=&ds3
181
+ ,retained_key=filter_rk
182
+ ,business_key=filter_hash
183
+ ,maxkeytable=&maxkeytable
184
+ ,locktable=&lock_table
185
+ ,outds=work.&ds4
186
+ )
187
+ proc append base=&filter_summary data=&ds4;
188
+ run;
189
+
190
+ %mp_lockanytable(UNLOCK,
191
+ lib=%scan(&filter_summary,1,.)
192
+ ,ds=%scan(&filter_summary,2,.)
193
+ ,ref=MP_FILTERSTORE update - &filter_hash
194
+ ,ctl_ds=&lock_table
195
+ )
196
+
197
+ data &outresult;
198
+ set &filter_summary;
199
+ where filter_hash="&filter_hash";
200
+ run;
201
+
202
+ %end;
203
+
204
+ proc sort data=&filter_detail(where=(filter_hash="&filter_hash")) out=&outquery;
205
+ by filter_line;
206
+ run;
207
+
208
+ %mp_abort(iftrue= (&syscc ne 0)
209
+ ,mac=mp_filterstore
210
+ ,msg=%str(syscc=&syscc on macro exit)
211
+ )
212
+
213
+ %mend mp_filterstore;
@@ -14,19 +14,8 @@
14
14
  @param [in] ref= A meaningful reference to enable the lock to be traced. Max
15
15
  length is 200 characters.
16
16
  @param [out] ctl_ds= (0) The control table which controls the actual locking.
17
- Should already be assigned and available. Definition as follows:
18
-
19
- proc sql;
20
- create table &ctl_ds(
21
- lock_lib char(8),
22
- lock_ds char(32),
23
- lock_status_cd char(10) not null,
24
- lock_user_nm char(100) not null ,
25
- lock_ref char(200),
26
- lock_pid char(10),
27
- lock_start_dttm num format=E8601DT26.6,
28
- lock_end_dttm num format=E8601DT26.6,
29
- constraint pk_mp_lockanytable primary key(lock_lib,lock_ds));
17
+ Should already be assigned and available. The definition is available by
18
+ running mp_coretable.sas as follows: `mp_coretable(LOCKTABLE)`.
30
19
 
31
20
  @param [in] loops= (25) Number of times to check for a lock.
32
21
  @param [in] loop_secs= (1) Seconds to wait between each lock attempt
@@ -24,19 +24,12 @@
24
24
  @li permlib.base_table - the target table to be loaded (**not** loaded by this
25
25
  macro)
26
26
  @li permlib.maxkeytable - optional, used to store load metaadata.
27
- The structure is as follows:
28
-
29
- proc sql;
30
- create table yourlib.maxkeytable(
31
- keytable varchar(41) label='Base table in libref.dataset format',
32
- keycolumn char(32) format=$32.
33
- label='The Retained key field containing the key values.',
34
- max_key num label=
35
- 'Integer representing current max RK or SK value in the KEYTABLE',
36
- processed_dttm num format=E8601DT26.6
37
- label='Datetime this value was last updated',
38
- constraint pk_mpe_maxkeyvalues
39
- primary key(keytable));
27
+ The definition is available by running mp_coretable.sas as follows:
28
+ `mp_coretable(MAXKEYTABLE)`.
29
+ @li permlib.locktable - Necessary if maxkeytable is being populated. The
30
+ definition is available by running mp_coretable.sas as follows:
31
+ `mp_coretable(LOCKTABLE)`.
32
+
40
33
 
41
34
  @param [in] base_lib= (WORK) Libref of the base (target) table.
42
35
  @param [in] base_dsn= (BASETABLE) Name of the base (target) table.
@@ -72,6 +65,7 @@
72
65
  @li mp_lockanytable.sas
73
66
 
74
67
  <h4> Related Macros </h4>
68
+ @li mp_filterstore.sas
75
69
  @li mp_retainedkey.test.sas
76
70
 
77
71
  @version 9.2
@@ -101,7 +95,7 @@
101
95
  %let tempds1=%mf_getuniquename();
102
96
  %let tempds2=%mf_getuniquename();
103
97
  %let comma_pk=%mf_getquotedstr(in_str=%str(&business_key),dlm=%str(,),quote=);
104
-
98
+ %let outds=%sysfunc(ifc(%index(&outds,.)=0,work.&outds,&outds));
105
99
  /* validation checks */
106
100
  %let iserr=0;
107
101
  %if &syscc>0 %then %do;
@@ -132,14 +126,18 @@
132
126
  %do x=1 %to %sysfunc(countw(&business_key));
133
127
  /* check business key values exist */
134
128
  %let key_field=%scan(&business_key,&x,%str( ));
135
- %if (not %mf_existvar(&app_libds,&key_field))
136
- or (not %mf_existvar(&base_libds,&key_field))
137
- %then %do;
129
+ %if not %mf_existvar(&app_libds,&key_field) %then %do;
130
+ %let iserr=1;
131
+ %let msg=Business key (&key_field) not found on &app_libds!;
132
+ %goto err;
133
+ %end;
134
+ %else %if not %mf_existvar(&base_libds,&key_field) %then %do;
138
135
  %let iserr=1;
139
- %let msg=Business key (&key_field) not found!;
136
+ %let msg=Business key (&key_field) not found on &base_libds!;
137
+ %goto err;
140
138
  %end;
141
139
  %end;
142
-
140
+ %err:
143
141
  %if &iserr=1 %then %do;
144
142
  /* err case so first perform an unlock of the base table before exiting */
145
143
  %mp_lockanytable(
@@ -203,7 +201,7 @@ quit;
203
201
  * Update maxkey table if link provided
204
202
  */
205
203
  %if &maxkeytable ne 0 %then %do;
206
- proc sql;
204
+ proc sql noprint;
207
205
  select count(*) into: check from &maxkeytable
208
206
  where upcase(keytable)="&base_libds";
209
207
 
package/package.json CHANGED
@@ -38,5 +38,5 @@
38
38
  "dependencies": {
39
39
  "ts-loader": "^9.2.6"
40
40
  },
41
- "version": "3.6.0"
41
+ "version": "3.7.0"
42
42
  }