@sasjs/core 4.5.0 → 4.9.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.
- package/README.md +16 -5
- package/base/mf_getplatform.sas +6 -0
- package/base/mp_assertscope.sas +1 -1
- package/base/mp_cntlout.sas +85 -0
- package/base/mp_coretable.sas +17 -70
- package/base/mp_filterstore.sas +4 -25
- package/base/mp_getformats.sas +4 -26
- package/base/mp_loadformat.sas +298 -0
- package/base/mp_lockanytable.sas +1 -1
- package/base/mp_lockfilecheck.sas +7 -1
- package/base/mp_md5.sas +58 -0
- package/base/mp_storediffs.sas +11 -2
- package/base/mp_streamfile.sas +7 -7
- package/base/mp_wait4file.sas +1 -3
- package/ddl/mddl_dc_difftable.sas +34 -0
- package/ddl/mddl_dc_filterdetail.sas +27 -0
- package/ddl/mddl_dc_filtersummary.sas +22 -0
- package/ddl/mddl_dc_locktable.sas +25 -0
- package/ddl/mddl_dc_maxkeytable.sas +24 -0
- package/ddl/mddl_sas_cntlout.sas +43 -0
- package/package.json +1 -1
- package/server/mfs_httpheader.sas +52 -0
package/README.md
CHANGED
|
@@ -31,19 +31,28 @@ Documentation: https://core.sasjs.io
|
|
|
31
31
|
|
|
32
32
|
## Components
|
|
33
33
|
|
|
34
|
-
### BASE library (
|
|
34
|
+
### BASE library (All Platforms)
|
|
35
35
|
|
|
36
36
|
- OS independent
|
|
37
|
-
-
|
|
37
|
+
- Works on all SAS Platforms
|
|
38
38
|
- No X command
|
|
39
39
|
- Prefixes: _mf_, _mp_
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
### DDL library (All Platforms)
|
|
42
|
+
|
|
43
|
+
- OS independent
|
|
44
|
+
- Works on all SAS Platforms
|
|
45
|
+
- No X command
|
|
46
|
+
- Prefixes: _mddl_(lib)_ -> where lib can be "SAS" (in relation to a SAS component) or "DC" (in relation to a Data Controller component)
|
|
47
|
+
|
|
48
|
+
This library will not be used for storing data entries (such as formats or datalines). Where this becomes necessary in the future, a new repo will be created, in order to keep the NPM bundle size down (for the benefit of those looking to embed purely macros in their applications).
|
|
49
|
+
|
|
50
|
+
#### FCMP library (All Platforms)
|
|
51
|
+
|
|
42
52
|
- Function and macro names are identical, except for special cases
|
|
43
53
|
- Prefixes: _mcf_
|
|
44
54
|
|
|
45
|
-
The fcmp macros are used to generate fcmp functions, and can be used with or
|
|
46
|
-
without the `proc fcmp` wrapper.
|
|
55
|
+
The fcmp macros are used to generate fcmp functions, and can be used with or without the `proc fcmp` wrapper.
|
|
47
56
|
|
|
48
57
|
### META library (SAS9 only)
|
|
49
58
|
|
|
@@ -125,6 +134,7 @@ filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
|
|
125
134
|
- one macro per file
|
|
126
135
|
- prefixes:
|
|
127
136
|
- _mcf_ for macro compiled functions (proc fcmp)
|
|
137
|
+
- _mddl_ for macros containing DDL (Data Definition Language)
|
|
128
138
|
- _mf_ for macro functions (can be used in open code).
|
|
129
139
|
- _ml_ for macros that are used to compile LUA modules
|
|
130
140
|
- _mm_ for metadata macros (interface with the metadata server).
|
|
@@ -198,6 +208,7 @@ We are currently on major release v4. Breaking changes should be marked with th
|
|
|
198
208
|
* `insert_cmplib` option of mcf_xxx macros will be deprecated (the option is now checked automatically with value inserted only if needed)
|
|
199
209
|
* mcf_xxx macros to have `wrap=` option defaulted to YES for convenience. Set this option explicitly to avoid issues.
|
|
200
210
|
* mp_getddl.sas to be renamed to mp_ds2ddl.sas (consistent with other ds2xxx macros). A wrapper macro is already in place, and you are able to use this immediately. The default for SHOWLOG will also be YES instead of NO.
|
|
211
|
+
* mp_coretable.sas will be replaced by the standalone macros in the `ddl` folder (which are already available)
|
|
201
212
|
|
|
202
213
|
## Star Gazing
|
|
203
214
|
|
package/base/mf_getplatform.sas
CHANGED
|
@@ -22,6 +22,12 @@
|
|
|
22
22
|
)/*/STORE SOURCE*/;
|
|
23
23
|
%local a b c;
|
|
24
24
|
%if &switch.NONE=NONE %then %do;
|
|
25
|
+
%if %symexist(sasjsprocessmode) %then %do;
|
|
26
|
+
%if &sasjsprocessmode=Stored Program %then %do;
|
|
27
|
+
SASJS
|
|
28
|
+
%return;
|
|
29
|
+
%end;
|
|
30
|
+
%end;
|
|
25
31
|
%if %symexist(sysprocessmode) %then %do;
|
|
26
32
|
%if "&sysprocessmode"="SAS Object Server"
|
|
27
33
|
or "&sysprocessmode"= "SAS Compute Server" %then %do;
|
package/base/mp_assertscope.sas
CHANGED
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
create table _data_ as
|
|
99
99
|
select name,offset,value
|
|
100
100
|
from dictionary.macros
|
|
101
|
-
where scope="&scope" and name not in (%mf_getquotedstr(&ilist))
|
|
101
|
+
where scope="&scope" and upcase(name) not in (%mf_getquotedstr(&ilist))
|
|
102
102
|
order by name,offset;
|
|
103
103
|
|
|
104
104
|
%let ds=&syslast;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file mp_cntlout.sas
|
|
3
|
+
@brief Creates a cntlout dataset in a consistent format
|
|
4
|
+
@details The dataset produced by proc format in the cntlout option will vary
|
|
5
|
+
according to its contents.
|
|
6
|
+
|
|
7
|
+
When dealing with formats from an ETL perspective (eg in [Data Controller for
|
|
8
|
+
SAS](https://datacontroller.io)), it is important that the output dataset
|
|
9
|
+
has a consistent model (and compariable values).
|
|
10
|
+
|
|
11
|
+
This macro makes use of mddl_sas_cntlout.sas to provide the consistent model,
|
|
12
|
+
and will left-align the start and end values when dealing with numeric ranges
|
|
13
|
+
to enable consistency when checking for differences.
|
|
14
|
+
|
|
15
|
+
usage:
|
|
16
|
+
|
|
17
|
+
%mp_cntlout(libcat=yourlib.cat,cntlout=work.formatexport)
|
|
18
|
+
|
|
19
|
+
@param [in] libcat The library.catalog reference
|
|
20
|
+
@param [in] fmtlist= (0) provide a space separated list of specific formats to
|
|
21
|
+
extract
|
|
22
|
+
@param [in] iftrue= (1=1) A condition under which the macro should be executed
|
|
23
|
+
@param [out] cntlout= (work.fmtextract) Libds reference for the output dataset
|
|
24
|
+
|
|
25
|
+
<h4> SAS Macros </h4>
|
|
26
|
+
@li mddl_sas_cntlout.sas
|
|
27
|
+
@li mf_getuniquename.sas
|
|
28
|
+
|
|
29
|
+
<h4> Related Macros </h4>
|
|
30
|
+
@li mf_getvarformat.sas
|
|
31
|
+
@li mp_getformats.sas
|
|
32
|
+
@li mp_loadformat.sas
|
|
33
|
+
@li mp_ds2fmtds.sas
|
|
34
|
+
|
|
35
|
+
@version 9.2
|
|
36
|
+
@author Allan Bowe
|
|
37
|
+
@cond
|
|
38
|
+
**/
|
|
39
|
+
|
|
40
|
+
%macro mp_cntlout(
|
|
41
|
+
iftrue=(1=1)
|
|
42
|
+
,libcat=
|
|
43
|
+
,cntlout=work.fmtextract
|
|
44
|
+
,fmtlist=0
|
|
45
|
+
)/*/STORE SOURCE*/;
|
|
46
|
+
%local ddlds cntlds i;
|
|
47
|
+
|
|
48
|
+
%if not(%eval(%unquote(&iftrue))) %then %return;
|
|
49
|
+
|
|
50
|
+
%let ddlds=%mf_getuniquename();
|
|
51
|
+
%let cntlds=%mf_getuniquename();
|
|
52
|
+
|
|
53
|
+
%mddl_sas_cntlout(libds=&ddlds)
|
|
54
|
+
|
|
55
|
+
%if %index(&libcat,-)>0 and %scan(&libcat,2,-)=FC %then %do;
|
|
56
|
+
%let libcat=%scan(&libcat,1,-);
|
|
57
|
+
%end;
|
|
58
|
+
|
|
59
|
+
proc format lib=&libcat cntlout=&cntlds;
|
|
60
|
+
%if "&fmtlist" ne "0" %then %do;
|
|
61
|
+
select
|
|
62
|
+
%do i=1 %to %sysfunc(countw(&fmtlist));
|
|
63
|
+
%scan(&fmtlist,&i,%str( ))
|
|
64
|
+
%end;
|
|
65
|
+
;
|
|
66
|
+
%end;
|
|
67
|
+
run;
|
|
68
|
+
|
|
69
|
+
data &cntlout;
|
|
70
|
+
if 0 then set &ddlds;
|
|
71
|
+
set &cntlds;
|
|
72
|
+
if type="N" then do;
|
|
73
|
+
start=cats(start);
|
|
74
|
+
end=cats(end);
|
|
75
|
+
end;
|
|
76
|
+
run;
|
|
77
|
+
proc sort;
|
|
78
|
+
by fmtname start;
|
|
79
|
+
run;
|
|
80
|
+
|
|
81
|
+
proc sql;
|
|
82
|
+
drop table &ddlds,&cntlds;
|
|
83
|
+
|
|
84
|
+
%mend mp_cntlout;
|
|
85
|
+
/** @endcond */
|
package/base/mp_coretable.sas
CHANGED
|
@@ -16,19 +16,21 @@
|
|
|
16
16
|
%mp_coretable(LOCKTABLE,libds=work.locktable)
|
|
17
17
|
|
|
18
18
|
@param [in] table_ref The type of table to create. Example values:
|
|
19
|
-
@li DIFFTABLE
|
|
20
|
-
|
|
21
|
-
@li
|
|
22
|
-
|
|
23
|
-
@li
|
|
24
|
-
mp_filterstore.sas.
|
|
25
|
-
@li LOCKANYTABLE - For "locking" tables prior to multipass loads. Used by
|
|
26
|
-
mp_lockanytable.sas
|
|
27
|
-
@li MAXKEYTABLE - For storing the maximum retained key information. Used
|
|
28
|
-
by mp_retainedkey.sas
|
|
19
|
+
@li DIFFTABLE
|
|
20
|
+
@li FILTER_DETAIL
|
|
21
|
+
@li FILTER_SUMMARY
|
|
22
|
+
@li LOCKANYTABLE
|
|
23
|
+
@li MAXKEYTABLE
|
|
29
24
|
@param [in] libds= (0) The library.dataset reference used to create the table.
|
|
30
25
|
If not provided, then the DDL is simply printed to the log.
|
|
31
26
|
|
|
27
|
+
<h4> SAS Macros </h4>
|
|
28
|
+
@li mddl_dc_difftable.sas
|
|
29
|
+
@li mddl_dc_filterdetail.sas
|
|
30
|
+
@li mddl_dc_filtersummary.sas
|
|
31
|
+
@li mddl_dc_locktable.sas
|
|
32
|
+
@li mddl_dc_maxkeytable.sas
|
|
33
|
+
|
|
32
34
|
<h4> Related Macros </h4>
|
|
33
35
|
@li mp_filterstore.sas
|
|
34
36
|
@li mp_lockanytable.sas
|
|
@@ -47,76 +49,21 @@
|
|
|
47
49
|
%let outds=%sysfunc(ifc(&libds=0,_data_,&libds));
|
|
48
50
|
proc sql;
|
|
49
51
|
%if &table_ref=DIFFTABLE %then %do;
|
|
50
|
-
|
|
51
|
-
load_ref char(36) label='unique load reference',
|
|
52
|
-
processed_dttm num format=E8601DT26.6 label='Processed at timestamp',
|
|
53
|
-
libref char(8) label='Library Reference (8 chars)',
|
|
54
|
-
dsn char(32) label='Dataset Name (32 chars)',
|
|
55
|
-
key_hash char(32) label=
|
|
56
|
-
'MD5 Hash of primary key values (pipe seperated)',
|
|
57
|
-
move_type char(1) label='Either (A)ppended, (D)eleted or (M)odified',
|
|
58
|
-
is_pk num label='Is Primary Key Field? (1/0)',
|
|
59
|
-
is_diff num label=
|
|
60
|
-
'Did value change? (1/0/-1). Always -1 for appends and deletes.',
|
|
61
|
-
tgtvar_type char(1) label='Either (C)haracter or (N)umeric',
|
|
62
|
-
tgtvar_nm char(32) label='Target variable name (32 chars)',
|
|
63
|
-
oldval_num num format=best32. label='Old (numeric) value',
|
|
64
|
-
newval_num num format=best32. label='New (numeric) value',
|
|
65
|
-
oldval_char char(32765) label='Old (character) value',
|
|
66
|
-
newval_char char(32765) label='New (character) value',
|
|
67
|
-
constraint pk_mpe_audit
|
|
68
|
-
primary key(load_ref,libref,dsn,key_hash,tgtvar_nm)
|
|
69
|
-
);
|
|
52
|
+
%mddl_dc_difftable(libds=&outds)
|
|
70
53
|
%end;
|
|
71
54
|
%else %if &table_ref=LOCKTABLE %then %do;
|
|
72
|
-
|
|
73
|
-
lock_lib char(8),
|
|
74
|
-
lock_ds char(32),
|
|
75
|
-
lock_status_cd char(10) not null,
|
|
76
|
-
lock_user_nm char(100) not null ,
|
|
77
|
-
lock_ref char(200),
|
|
78
|
-
lock_pid char(10),
|
|
79
|
-
lock_start_dttm num format=E8601DT26.6,
|
|
80
|
-
lock_end_dttm num format=E8601DT26.6,
|
|
81
|
-
constraint pk_mp_lockanytable primary key(lock_lib,lock_ds));
|
|
55
|
+
%mddl_dc_locktable(libds=&outds)
|
|
82
56
|
%end;
|
|
83
57
|
%else %if &table_ref=FILTER_SUMMARY %then %do;
|
|
84
|
-
|
|
85
|
-
filter_rk num not null,
|
|
86
|
-
filter_hash char(32) not null,
|
|
87
|
-
filter_table char(41) not null,
|
|
88
|
-
processed_dttm num not null format=E8601DT26.6,
|
|
89
|
-
constraint pk_mpe_filteranytable
|
|
90
|
-
primary key(filter_rk));
|
|
58
|
+
%mddl_dc_filtersummary(libds=&outds)
|
|
91
59
|
%end;
|
|
92
60
|
%else %if &table_ref=FILTER_DETAIL %then %do;
|
|
93
|
-
|
|
94
|
-
filter_hash char(32) not null,
|
|
95
|
-
filter_line num not null,
|
|
96
|
-
group_logic char(3) not null,
|
|
97
|
-
subgroup_logic char(3) not null,
|
|
98
|
-
subgroup_id num not null,
|
|
99
|
-
variable_nm varchar(32) not null,
|
|
100
|
-
operator_nm varchar(12) not null,
|
|
101
|
-
raw_value varchar(4000) not null,
|
|
102
|
-
processed_dttm num not null format=E8601DT26.6,
|
|
103
|
-
constraint pk_mpe_filteranytable
|
|
104
|
-
primary key(filter_hash,filter_line));
|
|
61
|
+
%mddl_dc_filterdetail(libds=&outds)
|
|
105
62
|
%end;
|
|
106
63
|
%else %if &table_ref=MAXKEYTABLE %then %do;
|
|
107
|
-
|
|
108
|
-
keytable varchar(41) label='Base table in libref.dataset format',
|
|
109
|
-
keycolumn char(32) format=$32.
|
|
110
|
-
label='The Retained key field containing the key values.',
|
|
111
|
-
max_key num label=
|
|
112
|
-
'Integer representing current max RK or SK value in the KEYTABLE',
|
|
113
|
-
processed_dttm num format=E8601DT26.6
|
|
114
|
-
label='Datetime this value was last updated',
|
|
115
|
-
constraint pk_mpe_maxkeyvalues
|
|
116
|
-
primary key(keytable));
|
|
64
|
+
%mddl_dc_maxkeytable(libds=&outds)
|
|
117
65
|
%end;
|
|
118
66
|
|
|
119
|
-
|
|
120
67
|
%if &libds=0 %then %do;
|
|
121
68
|
describe table &syslast;
|
|
122
69
|
drop table &syslast;
|
package/base/mp_filterstore.sas
CHANGED
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
<h4> SAS Macros </h4>
|
|
53
|
+
@li mddl_sas_cntlout.sas
|
|
53
54
|
@li mf_getuniquename.sas
|
|
54
55
|
@li mf_getvalue.sas
|
|
55
56
|
@li mf_islibds.sas
|
|
@@ -111,36 +112,14 @@
|
|
|
111
112
|
%if "%substr(&libds,%length(&libds)-2,3)"="-FC" %then %do;
|
|
112
113
|
%let libds=%scan(&libds,1,-); /* chop off -FC extension */
|
|
113
114
|
%let ds0=%mf_getuniquename(prefix=fmtds_);
|
|
115
|
+
%let libds=&ds0;
|
|
114
116
|
/*
|
|
115
117
|
There is no need to export the entire format catalog here - the validations
|
|
116
118
|
are done against the data model, not the data values. So we can simply
|
|
117
119
|
hardcode the structure based on the cntlout dataset.
|
|
118
120
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
FMTNAME char(32)
|
|
122
|
-
,START char(16)
|
|
123
|
-
,END char(16)
|
|
124
|
-
,LABEL char(256)
|
|
125
|
-
,MIN num length=3
|
|
126
|
-
,MAX num length=3
|
|
127
|
-
,DEFAULT num length=3
|
|
128
|
-
,LENGTH num length=3
|
|
129
|
-
,FUZZ num
|
|
130
|
-
,PREFIX char(2)
|
|
131
|
-
,MULT num
|
|
132
|
-
,FILL char(1)
|
|
133
|
-
,NOEDIT num length=3
|
|
134
|
-
,TYPE char(1)
|
|
135
|
-
,SEXCL char(1)
|
|
136
|
-
,EEXCL char(1)
|
|
137
|
-
,HLO char(13)
|
|
138
|
-
,DECSEP char(1)
|
|
139
|
-
,DIG3SEP char(1)
|
|
140
|
-
,DATATYPE char(8)
|
|
141
|
-
,LANGUAGE char(8)
|
|
142
|
-
);
|
|
143
|
-
%let libds=&ds0;
|
|
121
|
+
%mddl_sas_cntlout(libds=&ds0)
|
|
122
|
+
|
|
144
123
|
%end;
|
|
145
124
|
%mp_filtercheck(&queryds,targetds=&libds,abort=YES)
|
|
146
125
|
|
package/base/mp_getformats.sas
CHANGED
|
@@ -40,6 +40,7 @@ https://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#
|
|
|
40
40
|
|`WHICHPATH `|`**OTHER** `|`**OTHER** `|`big fat problem if not path1 `|`1 `|`40 `|`28 `|`28 `|`1E-12 `|` `|`0 `|` `|`0 `|`N `|`N `|`N `|`O `|` `|` `|` `|` `|
|
|
41
41
|
|
|
42
42
|
<h4> SAS Macros </h4>
|
|
43
|
+
@li mddl_sas_cntlout.sas
|
|
43
44
|
@li mf_dedup.sas
|
|
44
45
|
@li mf_getfmtlist.sas
|
|
45
46
|
@li mf_getfmtname.sas
|
|
@@ -94,30 +95,7 @@ create table &outsummary as
|
|
|
94
95
|
|
|
95
96
|
%if "&outdetail" ne "0" %then %do;
|
|
96
97
|
/* ensure base table always exists */
|
|
97
|
-
|
|
98
|
-
create table &outdetail(
|
|
99
|
-
FMTNAME char(32) label='Format name'
|
|
100
|
-
,START char(16) label='Starting value for format'
|
|
101
|
-
,END char(16) label='Ending value for format'
|
|
102
|
-
,LABEL char(256) label='Format value label'
|
|
103
|
-
,MIN num length=3 label='Minimum length'
|
|
104
|
-
,MAX num length=3 label='Maximum length'
|
|
105
|
-
,DEFAULT num length=3 label='Default length'
|
|
106
|
-
,LENGTH num length=3 label='Format length'
|
|
107
|
-
,FUZZ num label='Fuzz value'
|
|
108
|
-
,PREFIX char(2) label='Prefix characters'
|
|
109
|
-
,MULT num label='Multiplier'
|
|
110
|
-
,FILL char(1) label='Fill character'
|
|
111
|
-
,NOEDIT num length=3 label='Is picture string noedit?'
|
|
112
|
-
,TYPE char(1) label='Type of format'
|
|
113
|
-
,SEXCL char(1) label='Start exclusion'
|
|
114
|
-
,EEXCL char(1) label='End exclusion'
|
|
115
|
-
,HLO char(13) label='Additional information'
|
|
116
|
-
,DECSEP char(1) label='Decimal separator'
|
|
117
|
-
,DIG3SEP char(1) label='Three-digit separator'
|
|
118
|
-
,DATATYPE char(8) label='Date/time/datetime?'
|
|
119
|
-
,LANGUAGE char(8) label='Language for date strings'
|
|
120
|
-
);
|
|
98
|
+
%mddl_sas_cntlout(libds=&outdetail)
|
|
121
99
|
/* grab the location of each format */
|
|
122
100
|
%let fmtcnt=0;
|
|
123
101
|
data _null_;
|
|
@@ -135,10 +113,10 @@ create table &outsummary as
|
|
|
135
113
|
select &&fmtname&i;
|
|
136
114
|
run;
|
|
137
115
|
data &tempds;
|
|
138
|
-
|
|
116
|
+
if 0 then set &outdetail;
|
|
139
117
|
set &tempds;
|
|
140
118
|
run;
|
|
141
|
-
proc append base=&outdetail data=&tempds;
|
|
119
|
+
proc append base=&outdetail data=&tempds ;
|
|
142
120
|
run;
|
|
143
121
|
%end;
|
|
144
122
|
%end;
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Loads a format catalog from a staging dataset
|
|
4
|
+
@details When loading staged data, it is common to receive only the records
|
|
5
|
+
that have actually changed. However, when loading a format catalog, if
|
|
6
|
+
records are missing they are presumed to be no longer required.
|
|
7
|
+
|
|
8
|
+
This macro will augment a staging dataset with other records from the same
|
|
9
|
+
format, to prevent loss of data - UNLESS the input dataset contains a marker
|
|
10
|
+
column, specifying that a particular row needs to be deleted (`delete_col=`).
|
|
11
|
+
|
|
12
|
+
This macro can also be used to identify which records would be (or were)
|
|
13
|
+
considered new, modified or deleted (`loadtarget=`) by creating the following
|
|
14
|
+
tables:
|
|
15
|
+
|
|
16
|
+
@li work.outds_add
|
|
17
|
+
@li work.outds_del
|
|
18
|
+
@li work.outds_mod
|
|
19
|
+
|
|
20
|
+
For example usage, see mp_loadformat.test.sas
|
|
21
|
+
|
|
22
|
+
@param [in] libcat The format catalog to be loaded
|
|
23
|
+
@param [in] libds The staging table to load
|
|
24
|
+
@param [in] loadtarget= (NO) Set to YES to actually load the target catalog
|
|
25
|
+
@param [in] delete_col= (_____DELETE__THIS__RECORD_____) The column used to
|
|
26
|
+
mark a record for deletion. Values should be "Yes" or "No".
|
|
27
|
+
@param [out] auditlibds= (0) For change tracking, set to the libds of an audit
|
|
28
|
+
table as defined in mddl_dc_difftable.sas
|
|
29
|
+
@param [in] locklibds= (0) For multi-user (parallel) situations, set to the
|
|
30
|
+
libds of the DC lock table as defined in the mddl_dc_locktable.sas macro.
|
|
31
|
+
@param [out] outds_add= (0) Set a libds here to see the new records added
|
|
32
|
+
@param [out] outds_del= (0) Set a libds here to see the records deleted
|
|
33
|
+
@param [out] outds_mod= (0) Set a libds here to see the modified records
|
|
34
|
+
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages and preserve outputs
|
|
35
|
+
|
|
36
|
+
<h4> SAS Macros </h4>
|
|
37
|
+
@li mddl_sas_cntlout.sas
|
|
38
|
+
@li mf_getuniquename.sas
|
|
39
|
+
@li mf_nobs.sas
|
|
40
|
+
@li mp_abort.sas
|
|
41
|
+
@li mp_cntlout.sas
|
|
42
|
+
@li mp_lockanytable.sas
|
|
43
|
+
|
|
44
|
+
<h4> Related Macros </h4>
|
|
45
|
+
@li mddl_dc_difftable.sas
|
|
46
|
+
@li mddl_dc_locktable.sas
|
|
47
|
+
@li mp_loadformat.test.sas
|
|
48
|
+
@li mp_lockanytable.sas
|
|
49
|
+
@li mp_storediffs.sas
|
|
50
|
+
@li mp_stackdiffs.sas
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@version 9.2
|
|
54
|
+
@author Allan Bowe
|
|
55
|
+
|
|
56
|
+
**/
|
|
57
|
+
|
|
58
|
+
%macro mp_loadformat(libcat,libds
|
|
59
|
+
,loadtarget=NO
|
|
60
|
+
,auditlibds=0
|
|
61
|
+
,locklibds=0
|
|
62
|
+
,delete_col=_____DELETE__THIS__RECORD_____
|
|
63
|
+
,outds_add=0
|
|
64
|
+
,outds_del=0
|
|
65
|
+
,outds_mod=0
|
|
66
|
+
,mdebug=0
|
|
67
|
+
);
|
|
68
|
+
/* set up local macro variables and temporary tables (with a prefix) */
|
|
69
|
+
%local err msg prefix dslist i var fmtlist ibufsize;
|
|
70
|
+
%let dslist=base_fmts template inlibds ds1 stagedata storediffs;
|
|
71
|
+
%if &outds_add=0 %then %let dslist=&dslist outds_add;
|
|
72
|
+
%if &outds_del=0 %then %let dslist=&dslist outds_del;
|
|
73
|
+
%if &outds_mod=0 %then %let dslist=&dslist outds_mod;
|
|
74
|
+
%let prefix=%substr(%mf_getuniquename(),1,21);
|
|
75
|
+
%do i=1 %to %sysfunc(countw(&dslist));
|
|
76
|
+
%let var=%scan(&dslist,&i);
|
|
77
|
+
%local &var;
|
|
78
|
+
%let &var=%upcase(&prefix._&var);
|
|
79
|
+
%end;
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
format values can be up to 32767 wide. SQL joins on such a wide column can
|
|
83
|
+
cause buffer issues. Update ibufsize and reset at the end.
|
|
84
|
+
*/
|
|
85
|
+
%let ibufsize=%sysfunc(getoption(ibufsize));
|
|
86
|
+
options ibufsize=32767 ;
|
|
87
|
+
|
|
88
|
+
/* in DC, format catalogs maybe specified in the libds with a -FC extension */
|
|
89
|
+
%let libcat=%scan(&libcat,1,-);
|
|
90
|
+
|
|
91
|
+
/* perform input validations */
|
|
92
|
+
%let err=0;
|
|
93
|
+
%let msg=0;
|
|
94
|
+
data _null_;
|
|
95
|
+
if _n_=1 then putlog "&sysmacroname entry vars:";
|
|
96
|
+
set sashelp.vmacro;
|
|
97
|
+
where scope="&sysmacroname";
|
|
98
|
+
value=upcase(value);
|
|
99
|
+
if &mdebug=0 then put name '=' value;
|
|
100
|
+
if name=:'LOAD' and value not in ('YES','NO') then do;
|
|
101
|
+
call symputx('msg',"invalid value for "!!name!!":"!!value);
|
|
102
|
+
call symputx('err',1);
|
|
103
|
+
stop;
|
|
104
|
+
end;
|
|
105
|
+
else if name='LIBCAT' then do;
|
|
106
|
+
if exist(value,'CATALOG') le 0 then do;
|
|
107
|
+
call symputx('msg',"Unable to open catalog: "!!value);
|
|
108
|
+
call symputx('err',1);
|
|
109
|
+
stop;
|
|
110
|
+
end;
|
|
111
|
+
end;
|
|
112
|
+
else if name='LIBDS' then do;
|
|
113
|
+
if exist(value) le 0 then do;
|
|
114
|
+
call symputx('msg',"Unable to open staging table: "!!value);
|
|
115
|
+
call symputx('err',1);
|
|
116
|
+
stop;
|
|
117
|
+
end;
|
|
118
|
+
end;
|
|
119
|
+
else if (name=:'OUTDS' or name in ('DELETE_COL','LOCKLIBDS','AUDITLIBDS'))
|
|
120
|
+
and missing(value) then do;
|
|
121
|
+
call symputx('msg',"missing value in var: "!!name);
|
|
122
|
+
call symputx('err',1);
|
|
123
|
+
stop;
|
|
124
|
+
end;
|
|
125
|
+
run;
|
|
126
|
+
|
|
127
|
+
%mp_abort(
|
|
128
|
+
iftrue=(&err ne 0)
|
|
129
|
+
,mac=&sysmacroname
|
|
130
|
+
,msg=%str(&msg)
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* First, extract only relevant formats from the catalog
|
|
135
|
+
*/
|
|
136
|
+
proc sql noprint;
|
|
137
|
+
select distinct fmtname into: fmtlist separated by ' ' from &libds;
|
|
138
|
+
|
|
139
|
+
%mp_cntlout(libcat=&libcat,fmtlist=&fmtlist,cntlout=&base_fmts)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Ensure input table and base_formats have consistent lengths and types
|
|
144
|
+
*/
|
|
145
|
+
%mddl_sas_cntlout(libds=&template)
|
|
146
|
+
data &inlibds;
|
|
147
|
+
if 0 then set &template;
|
|
148
|
+
set &libds;
|
|
149
|
+
if missing(type) then do;
|
|
150
|
+
if substr(fmtname,1,1)='$' then type='C';
|
|
151
|
+
else type='N';
|
|
152
|
+
end;
|
|
153
|
+
if type='N' then do;
|
|
154
|
+
start=cats(start);
|
|
155
|
+
end=cats(end);
|
|
156
|
+
end;
|
|
157
|
+
run;
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Identify new records
|
|
162
|
+
*/
|
|
163
|
+
proc sql;
|
|
164
|
+
create table &outds_add(drop=&delete_col) as
|
|
165
|
+
select a.*
|
|
166
|
+
from &inlibds a
|
|
167
|
+
left join &base_fmts b
|
|
168
|
+
on a.fmtname=b.fmtname
|
|
169
|
+
and a.start=b.start
|
|
170
|
+
where b.fmtname is null
|
|
171
|
+
and upcase(a.&delete_col) ne "YES"
|
|
172
|
+
order by fmtname, start;;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Identify deleted records
|
|
176
|
+
*/
|
|
177
|
+
create table &outds_del(drop=&delete_col) as
|
|
178
|
+
select a.*
|
|
179
|
+
from &inlibds a
|
|
180
|
+
inner join &base_fmts b
|
|
181
|
+
on a.fmtname=b.fmtname
|
|
182
|
+
and a.start=b.start
|
|
183
|
+
where upcase(a.&delete_col)="YES"
|
|
184
|
+
order by fmtname, start;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Identify modified records
|
|
188
|
+
*/
|
|
189
|
+
create table &outds_mod (drop=&delete_col) as
|
|
190
|
+
select a.*
|
|
191
|
+
from &inlibds a
|
|
192
|
+
inner join &base_fmts b
|
|
193
|
+
on a.fmtname=b.fmtname
|
|
194
|
+
and a.start=b.start
|
|
195
|
+
where upcase(a.&delete_col) ne "YES"
|
|
196
|
+
order by fmtname, start;
|
|
197
|
+
|
|
198
|
+
options ibufsize=&ibufsize;
|
|
199
|
+
|
|
200
|
+
%mp_abort(
|
|
201
|
+
iftrue=(&syscc ne 0)
|
|
202
|
+
,mac=&sysmacroname
|
|
203
|
+
,msg=%str(SYSCC=&syscc prior to load prep)
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
%if &loadtarget=YES %then %do;
|
|
207
|
+
data &ds1;
|
|
208
|
+
merge &base_fmts(in=base)
|
|
209
|
+
&outds_mod(in=mod)
|
|
210
|
+
&outds_add(in=add)
|
|
211
|
+
&outds_del(in=del);
|
|
212
|
+
if not del and not mod;
|
|
213
|
+
by fmtname start;
|
|
214
|
+
run;
|
|
215
|
+
data &stagedata;
|
|
216
|
+
set &ds1 &outds_mod;
|
|
217
|
+
run;
|
|
218
|
+
proc sort;
|
|
219
|
+
by fmtname start;
|
|
220
|
+
run;
|
|
221
|
+
%end;
|
|
222
|
+
/* mp abort needs to run outside of conditional blocks */
|
|
223
|
+
%mp_abort(
|
|
224
|
+
iftrue=(&syscc ne 0)
|
|
225
|
+
,mac=&sysmacroname
|
|
226
|
+
,msg=%str(SYSCC=&syscc prior to actual load)
|
|
227
|
+
)
|
|
228
|
+
%if &loadtarget=YES %then %do;
|
|
229
|
+
%if %mf_nobs(&stagedata)=0 %then %do;
|
|
230
|
+
%put There are no changes to load in &libcat!;
|
|
231
|
+
%return;
|
|
232
|
+
%end;
|
|
233
|
+
%if &locklibds ne 0 %then %do;
|
|
234
|
+
/* prevent parallel updates */
|
|
235
|
+
%mp_lockanytable(LOCK
|
|
236
|
+
,lib=%scan(&libcat,1,.)
|
|
237
|
+
,ds=%scan(&libcat,2,.)-FC
|
|
238
|
+
,ref=MP_LOADFORMAT commencing format load
|
|
239
|
+
,ctl_ds=&locklibds
|
|
240
|
+
)
|
|
241
|
+
%end;
|
|
242
|
+
/* do the actual load */
|
|
243
|
+
proc format lib=&libcat cntlin=&stagedata;
|
|
244
|
+
run;
|
|
245
|
+
%if &locklibds ne 0 %then %do;
|
|
246
|
+
/* unlock the table */
|
|
247
|
+
%mp_lockanytable(UNLOCK
|
|
248
|
+
,lib=%scan(&libcat,1,.)
|
|
249
|
+
,ds=%scan(&libcat,2,.)-FC
|
|
250
|
+
,ref=MP_LOADFORMAT completed format load
|
|
251
|
+
,ctl_ds=&locklibds
|
|
252
|
+
)
|
|
253
|
+
%end;
|
|
254
|
+
/* track the changes */
|
|
255
|
+
%if &auditlibds ne 0 %then %do;
|
|
256
|
+
%if &locklibds ne 0 %then %do;
|
|
257
|
+
%mp_lockanytable(LOCK
|
|
258
|
+
,lib=%scan(&auditlibds,1,.)
|
|
259
|
+
,ds=%scan(&auditlibds,2,.)
|
|
260
|
+
,ref=MP_LOADFORMAT commencing audit table load
|
|
261
|
+
,ctl_ds=&locklibds
|
|
262
|
+
)
|
|
263
|
+
%end;
|
|
264
|
+
|
|
265
|
+
%mp_storediffs(&libcat-FC
|
|
266
|
+
,&inlibds
|
|
267
|
+
,FMTNAME START
|
|
268
|
+
,delds=&outds_del
|
|
269
|
+
,modds=&outds_mod
|
|
270
|
+
,appds=&outds_add
|
|
271
|
+
,outds=&storediffs
|
|
272
|
+
,mdebug=&mdebug
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
%if &locklibds ne 0 %then %do;
|
|
276
|
+
%mp_lockanytable(UNLOCK
|
|
277
|
+
,lib=%scan(&auditlibds,1,.)
|
|
278
|
+
,ds=%scan(&auditlibds,2,.)
|
|
279
|
+
,ref=MP_LOADFORMAT commencing audit table load
|
|
280
|
+
,ctl_ds=&locklibds
|
|
281
|
+
)
|
|
282
|
+
%end;
|
|
283
|
+
%end;
|
|
284
|
+
%end;
|
|
285
|
+
%mp_abort(
|
|
286
|
+
iftrue=(&syscc ne 0)
|
|
287
|
+
,mac=&sysmacroname
|
|
288
|
+
,msg=%str(SYSCC=&syscc after load)
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
%if &mdebug=0 %then %do;
|
|
292
|
+
proc datasets lib=work;
|
|
293
|
+
delete &prefix:;
|
|
294
|
+
run;
|
|
295
|
+
%put &sysmacroname exit vars:;
|
|
296
|
+
%put _local_;
|
|
297
|
+
%end;
|
|
298
|
+
%mend mp_loadformat;
|
package/base/mp_lockanytable.sas
CHANGED
|
@@ -37,7 +37,7 @@ run;
|
|
|
37
37
|
,mac=checklock.sas
|
|
38
38
|
,msg=Aborting with syscc=&syscc on entry.
|
|
39
39
|
)
|
|
40
|
-
%mp_abort(iftrue= (&libds=0)
|
|
40
|
+
%mp_abort(iftrue= ("&libds"="0")
|
|
41
41
|
,mac=&sysmacroname
|
|
42
42
|
,msg=%str(libds not provided)
|
|
43
43
|
)
|
|
@@ -46,6 +46,12 @@ run;
|
|
|
46
46
|
%let lib=%upcase(%scan(&libds,1,.));
|
|
47
47
|
%let ds=%upcase(%scan(&libds,2,.));
|
|
48
48
|
|
|
49
|
+
/* in DC, format catalogs are passed with a -FC suffix. No saslock here! */
|
|
50
|
+
%if %scan(&libds,2,-)=FC %then %do;
|
|
51
|
+
%put &sysmacroname: Format Catalog detected, no lockfile applied to &libds;
|
|
52
|
+
%return;
|
|
53
|
+
%end;
|
|
54
|
+
|
|
49
55
|
/* do not proceed if no observations can be processed */
|
|
50
56
|
%let msg=options obs = 0. syserrortext=%superq(syserrortext);
|
|
51
57
|
%mp_abort(iftrue= (%sysfunc(getoption(OBS))=0)
|
package/base/mp_md5.sas
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Generates an md5 expression for hashing a set of variables
|
|
4
|
+
@details This is the same algorithm used to hash records in
|
|
5
|
+
[Data Controller for SAS](https://datacontroller.io) (free for up
|
|
6
|
+
to 5 users).
|
|
7
|
+
|
|
8
|
+
It is not designed to be efficient - it is designed to be effective,
|
|
9
|
+
given the range of edge cases (large floating points, special missing
|
|
10
|
+
numerics, thousands of columns, very wide columns).
|
|
11
|
+
|
|
12
|
+
It can be used only in data step, eg as follows:
|
|
13
|
+
|
|
14
|
+
data _null_;
|
|
15
|
+
set sashelp.class;
|
|
16
|
+
hashvar=%mp_md5(cvars=name sex, nvars=age height weight);
|
|
17
|
+
put hashvar=;
|
|
18
|
+
run;
|
|
19
|
+
|
|
20
|
+
Unfortunately it will not run in SQL - it fails with the following message:
|
|
21
|
+
|
|
22
|
+
> The width value for HEX is out of bounds. It should be between 1 and 16
|
|
23
|
+
|
|
24
|
+
The macro will also cause errors if the data contains (non-special) missings
|
|
25
|
+
and the (undocumented) `options dsoptions=nonote2err;` is in effect.
|
|
26
|
+
|
|
27
|
+
This can be avoided in two ways:
|
|
28
|
+
|
|
29
|
+
@li Global option: `options dsoptions=nonote2err;`
|
|
30
|
+
@li Data step option: `data YOURLIB.YOURDATASET /nonote2err;`
|
|
31
|
+
|
|
32
|
+
@param cvars= Space seperated list of character variables
|
|
33
|
+
@param nvars= Space seperated list of numeric variables
|
|
34
|
+
|
|
35
|
+
<h4> Related Programs </h4>
|
|
36
|
+
@li mp_init.sas
|
|
37
|
+
|
|
38
|
+
@version 9.2
|
|
39
|
+
@author Allan Bowe
|
|
40
|
+
**/
|
|
41
|
+
|
|
42
|
+
%macro mp_md5(cvars=,nvars=);
|
|
43
|
+
%local i var sep;
|
|
44
|
+
put(md5(
|
|
45
|
+
%do i=1 %to %sysfunc(countw(&cvars));
|
|
46
|
+
%let var=%scan(&cvars,&i,%str( ));
|
|
47
|
+
&sep put(md5(trim(&var)),$hex32.)
|
|
48
|
+
%let sep=!!;
|
|
49
|
+
%end;
|
|
50
|
+
%do i=1 %to %sysfunc(countw(&nvars));
|
|
51
|
+
%let var=%scan(&nvars,&i,%str( ));
|
|
52
|
+
/* multiply by 1 to strip precision errors (eg 0 != 0) */
|
|
53
|
+
/* but ONLY if not missing, else will lose any special missing values */
|
|
54
|
+
&sep put(md5(trim(put(ifn(missing(&var),&var,&var*1),binary64.))),$hex32.)
|
|
55
|
+
%let sep=!!;
|
|
56
|
+
%end;
|
|
57
|
+
),hex32.)
|
|
58
|
+
%mend mp_md5;
|
package/base/mp_storediffs.sas
CHANGED
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
%else %let dbg=*;
|
|
91
91
|
|
|
92
92
|
/* set up unique and temporary vars */
|
|
93
|
-
%local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist;
|
|
93
|
+
%local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist vlist;
|
|
94
94
|
%let ds1=%upcase(work.%mf_getuniquename(prefix=mpsd_ds1));
|
|
95
95
|
%let ds2=%upcase(work.%mf_getuniquename(prefix=mpsd_ds2));
|
|
96
96
|
%let ds3=%upcase(work.%mf_getuniquename(prefix=mpsd_ds3));
|
|
@@ -144,12 +144,21 @@ proc transpose data=&ds1
|
|
|
144
144
|
by &inds_keep &hashkey;
|
|
145
145
|
var _character_;
|
|
146
146
|
run;
|
|
147
|
+
|
|
148
|
+
%if %index(&libds,-)>0 and %scan(&libds,2,-)=FC %then %do;
|
|
149
|
+
/* this is a format catalog - cannot query cols directly */
|
|
150
|
+
%let vlist="FMTNAME","START","END","LABEL","MIN","MAX","DEFAULT","LENGTH"
|
|
151
|
+
,"FUZZ","PREFIX","MULT","FILL","NOEDIT","TYPE","SEXCL","EEXCL","HLO"
|
|
152
|
+
,"DECSEP","DIG3SEP","DATATYPE","LANGUAGE";
|
|
153
|
+
%end;
|
|
154
|
+
%else %let vlist=%mf_getvarlist(&libds,dlm=%str(,),quote=DOUBLE);
|
|
155
|
+
|
|
147
156
|
data &ds4;
|
|
148
157
|
length &inds_keep $41 tgtvar_nm $32;
|
|
149
158
|
set &ds2 &ds3 indsname=&inds_auto;
|
|
150
159
|
|
|
151
160
|
tgtvar_nm=upcase(tgtvar_nm);
|
|
152
|
-
if tgtvar_nm in (%upcase(
|
|
161
|
+
if tgtvar_nm in (%upcase(&vlist));
|
|
153
162
|
|
|
154
163
|
if &inds_auto="&ds2" then tgtvar_type='N';
|
|
155
164
|
else if &inds_auto="&ds3" then tgtvar_type='C';
|
package/base/mp_streamfile.sas
CHANGED
|
@@ -55,7 +55,7 @@ data _null_;
|
|
|
55
55
|
run;
|
|
56
56
|
|
|
57
57
|
%if &contentype=CSV %then %do;
|
|
58
|
-
%if &platform=SASMETA and &streamweb=1 %then %do;
|
|
58
|
+
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
|
59
59
|
data _null_;
|
|
60
60
|
rc=stpsrv_header('Content-type','application/csv');
|
|
61
61
|
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
|
@@ -69,7 +69,7 @@ run;
|
|
|
69
69
|
%end;
|
|
70
70
|
%else %if &contentype=EXCEL %then %do;
|
|
71
71
|
/* suitable for XLS format */
|
|
72
|
-
%if &platform=SASMETA and &streamweb=1 %then %do;
|
|
72
|
+
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
|
73
73
|
data _null_;
|
|
74
74
|
rc=stpsrv_header('Content-type','application/vnd.ms-excel');
|
|
75
75
|
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
|
@@ -82,7 +82,7 @@ run;
|
|
|
82
82
|
%end;
|
|
83
83
|
%end;
|
|
84
84
|
%else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do;
|
|
85
|
-
%if &platform=SASMETA and &streamweb=1 %then %do;
|
|
85
|
+
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
|
86
86
|
data _null_;
|
|
87
87
|
rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)");
|
|
88
88
|
run;
|
|
@@ -99,7 +99,7 @@ run;
|
|
|
99
99
|
%end;
|
|
100
100
|
%end;
|
|
101
101
|
%else %if &contentype=TEXT %then %do;
|
|
102
|
-
%if &platform=SASMETA and &streamweb=1 %then %do;
|
|
102
|
+
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
|
103
103
|
data _null_;
|
|
104
104
|
rc=stpsrv_header('Content-type','application/text');
|
|
105
105
|
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
|
@@ -112,7 +112,7 @@ run;
|
|
|
112
112
|
%end;
|
|
113
113
|
%end;
|
|
114
114
|
%else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do;
|
|
115
|
-
%if &platform=SASMETA and &streamweb=1 %then %do;
|
|
115
|
+
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
|
116
116
|
data _null_;
|
|
117
117
|
rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)");
|
|
118
118
|
run;
|
|
@@ -123,7 +123,7 @@ run;
|
|
|
123
123
|
%end;
|
|
124
124
|
%end;
|
|
125
125
|
%else %if &contentype=XLSX %then %do;
|
|
126
|
-
%if &platform=SASMETA and &streamweb=1 %then %do;
|
|
126
|
+
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
|
127
127
|
data _null_;
|
|
128
128
|
rc=stpsrv_header('Content-type',
|
|
129
129
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
@@ -138,7 +138,7 @@ run;
|
|
|
138
138
|
%end;
|
|
139
139
|
%end;
|
|
140
140
|
%else %if &contentype=ZIP %then %do;
|
|
141
|
-
%if &platform=SASMETA and &streamweb=1 %then %do;
|
|
141
|
+
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
|
142
142
|
data _null_;
|
|
143
143
|
rc=stpsrv_header('Content-type','application/zip');
|
|
144
144
|
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
package/base/mp_wait4file.sas
CHANGED
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
@details Loops with a `sleep()` command until a file arrives or the max wait
|
|
5
5
|
period expires.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Wait 3 minutes OR for /tmp/flag.txt to appear
|
|
7
|
+
Example: Wait 3 minutes OR for /tmp/flag.txt to appear
|
|
10
8
|
|
|
11
9
|
%mp_wait4file(/tmp/flag.txt , maxwait=60*3)
|
|
12
10
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Difftable DDL
|
|
4
|
+
@details Used to store changes to tables. Used by mp_storediffs.sas
|
|
5
|
+
and mp_stackdiffs.sas
|
|
6
|
+
|
|
7
|
+
**/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
%macro mddl_dc_difftable(libds=WORK.DIFFTABLE);
|
|
11
|
+
|
|
12
|
+
proc sql;
|
|
13
|
+
create table &libds(
|
|
14
|
+
load_ref char(36) label='unique load reference',
|
|
15
|
+
processed_dttm num format=E8601DT26.6 label='Processed at timestamp',
|
|
16
|
+
libref char(8) label='Library Reference (8 chars)',
|
|
17
|
+
dsn char(32) label='Dataset Name (32 chars)',
|
|
18
|
+
key_hash char(32) label=
|
|
19
|
+
'MD5 Hash of primary key values (pipe seperated)',
|
|
20
|
+
move_type char(1) label='Either (A)ppended, (D)eleted or (M)odified',
|
|
21
|
+
is_pk num label='Is Primary Key Field? (1/0)',
|
|
22
|
+
is_diff num label=
|
|
23
|
+
'Did value change? (1/0/-1). Always -1 for appends and deletes.',
|
|
24
|
+
tgtvar_type char(1) label='Either (C)haracter or (N)umeric',
|
|
25
|
+
tgtvar_nm char(32) label='Target variable name (32 chars)',
|
|
26
|
+
oldval_num num format=best32. label='Old (numeric) value',
|
|
27
|
+
newval_num num format=best32. label='New (numeric) value',
|
|
28
|
+
oldval_char char(32765) label='Old (character) value',
|
|
29
|
+
newval_char char(32765) label='New (character) value',
|
|
30
|
+
constraint pk_mpe_audit
|
|
31
|
+
primary key(load_ref,libref,dsn,key_hash,tgtvar_nm)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
%mend mddl_dc_difftable;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Filtertable DDL
|
|
4
|
+
@details For storing detailed filter values. Used by
|
|
5
|
+
mp_filterstore.sas.
|
|
6
|
+
|
|
7
|
+
**/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
%macro mddl_dc_filterdetail(libds=WORK.FILTER_DETAIL);
|
|
11
|
+
|
|
12
|
+
proc sql;
|
|
13
|
+
create table &libds(
|
|
14
|
+
filter_hash char(32) not null,
|
|
15
|
+
filter_line num not null,
|
|
16
|
+
group_logic char(3) not null,
|
|
17
|
+
subgroup_logic char(3) not null,
|
|
18
|
+
subgroup_id num not null,
|
|
19
|
+
variable_nm varchar(32) not null,
|
|
20
|
+
operator_nm varchar(12) not null,
|
|
21
|
+
raw_value varchar(4000) not null,
|
|
22
|
+
processed_dttm num not null format=E8601DT26.6,
|
|
23
|
+
constraint pk_mpe_filteranytable
|
|
24
|
+
primary key(filter_hash,filter_line)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
%mend mddl_dc_filterdetail;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Filtersummary DDL
|
|
4
|
+
@details For storing summary filter values. Used by
|
|
5
|
+
mp_filterstore.sas.
|
|
6
|
+
|
|
7
|
+
**/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
%macro mddl_dc_filtersummary(libds=WORK.FILTER_SUMMARY);
|
|
11
|
+
|
|
12
|
+
proc sql;
|
|
13
|
+
create table &libds(
|
|
14
|
+
filter_rk num not null,
|
|
15
|
+
filter_hash char(32) not null,
|
|
16
|
+
filter_table char(41) not null,
|
|
17
|
+
processed_dttm num not null format=E8601DT26.6,
|
|
18
|
+
constraint pk_mpe_filteranytable
|
|
19
|
+
primary key(filter_rk)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
%mend mddl_dc_filtersummary;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Locktable DDL
|
|
4
|
+
@details For "locking" tables prior to multipass loads. Used by
|
|
5
|
+
mp_lockanytable.sas
|
|
6
|
+
|
|
7
|
+
**/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
%macro mddl_dc_locktable(libds=WORK.LOCKTABLE);
|
|
11
|
+
|
|
12
|
+
proc sql;
|
|
13
|
+
create table &libds(
|
|
14
|
+
lock_lib char(8),
|
|
15
|
+
lock_ds char(32),
|
|
16
|
+
lock_status_cd char(10) not null,
|
|
17
|
+
lock_user_nm char(100) not null ,
|
|
18
|
+
lock_ref char(200),
|
|
19
|
+
lock_pid char(10),
|
|
20
|
+
lock_start_dttm num format=E8601DT26.6,
|
|
21
|
+
lock_end_dttm num format=E8601DT26.6,
|
|
22
|
+
constraint pk_mp_lockanytable primary key(lock_lib,lock_ds)
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
%mend mddl_dc_locktable;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Maxkeytable DDL
|
|
4
|
+
@details For storing the maximum retained key information. Used
|
|
5
|
+
by mp_retainedkey.sas
|
|
6
|
+
|
|
7
|
+
**/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
%macro mddl_dc_maxkeytable(libds=WORK.MAXKEYTABLE);
|
|
11
|
+
|
|
12
|
+
proc sql;
|
|
13
|
+
create table &libds(
|
|
14
|
+
keytable varchar(41) label='Base table in libref.dataset format',
|
|
15
|
+
keycolumn char(32) format=$32.
|
|
16
|
+
label='The Retained key field containing the key values.',
|
|
17
|
+
max_key num label=
|
|
18
|
+
'Integer representing current max RK or SK value in the KEYTABLE',
|
|
19
|
+
processed_dttm num format=E8601DT26.6
|
|
20
|
+
label='Datetime this value was last updated',
|
|
21
|
+
constraint pk_mpe_maxkeyvalues
|
|
22
|
+
primary key(keytable));
|
|
23
|
+
|
|
24
|
+
%mend mddl_dc_maxkeytable;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief The CNTLOUT table generated by proc format
|
|
4
|
+
@details This table will actually change format depending on the data values,
|
|
5
|
+
therefore the max possible lengths are described here to enable consistency
|
|
6
|
+
when dealing with format data.
|
|
7
|
+
|
|
8
|
+
**/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
%macro mddl_sas_cntlout(libds=WORK.CNTLOUT);
|
|
12
|
+
|
|
13
|
+
proc sql;
|
|
14
|
+
create table &libds(
|
|
15
|
+
FMTNAME char(32) label='Format name'
|
|
16
|
+
/*
|
|
17
|
+
to accomodate larger START values, mp_loadformat.sas will need the
|
|
18
|
+
SQL dependency removed (proc sql needs to accomodate 3 index values in
|
|
19
|
+
a 32767 ibufsize limit)
|
|
20
|
+
*/
|
|
21
|
+
,START char(10000) label='Starting value for format'
|
|
22
|
+
,END char(32767) label='Ending value for format'
|
|
23
|
+
,LABEL char(32767) label='Format value label'
|
|
24
|
+
,MIN num length=3 label='Minimum length'
|
|
25
|
+
,MAX num length=3 label='Maximum length'
|
|
26
|
+
,DEFAULT num length=3 label='Default length'
|
|
27
|
+
,LENGTH num length=3 label='Format length'
|
|
28
|
+
,FUZZ num label='Fuzz value'
|
|
29
|
+
,PREFIX char(2) label='Prefix characters'
|
|
30
|
+
,MULT num label='Multiplier'
|
|
31
|
+
,FILL char(1) label='Fill character'
|
|
32
|
+
,NOEDIT num length=3 label='Is picture string noedit?'
|
|
33
|
+
,TYPE char(1) label='Type of format'
|
|
34
|
+
,SEXCL char(1) label='Start exclusion'
|
|
35
|
+
,EEXCL char(1) label='End exclusion'
|
|
36
|
+
,HLO char(13) label='Additional information'
|
|
37
|
+
,DECSEP char(1) label='Decimal separator'
|
|
38
|
+
,DIG3SEP char(1) label='Three-digit separator'
|
|
39
|
+
,DATATYPE char(8) label='Date/time/datetime?'
|
|
40
|
+
,LANGUAGE char(8) label='Language for date strings'
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
%mend mddl_sas_cntlout;
|
package/package.json
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Sets the http headers in the SASjs/server response
|
|
4
|
+
@details For GET requests, SASjs server will use the file generated by this
|
|
5
|
+
macro for setting the appropriate http headers in the response.
|
|
6
|
+
|
|
7
|
+
It works by writing a file to the session directory, that is then ingested by
|
|
8
|
+
the server.
|
|
9
|
+
|
|
10
|
+
The location of this file is driven by the global variable
|
|
11
|
+
`sasjs_stpsrv_header_loc` which is made available in the autoexec.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
|
|
15
|
+
%mfs_httpheader(Content-type,application/csv)
|
|
16
|
+
|
|
17
|
+
@param [in] header_name Name of the http header to set
|
|
18
|
+
@param [in] header_value Value of the http header to set
|
|
19
|
+
|
|
20
|
+
<h4> Related Macros </h4>
|
|
21
|
+
@li mcf_stpsrv_header.sas
|
|
22
|
+
|
|
23
|
+
@version 9.3
|
|
24
|
+
@author Allan Bowe
|
|
25
|
+
|
|
26
|
+
**/
|
|
27
|
+
|
|
28
|
+
%macro mfs_httpheader(header_name
|
|
29
|
+
,header_value
|
|
30
|
+
)/*/STORE SOURCE*/;
|
|
31
|
+
%local fref fid i;
|
|
32
|
+
|
|
33
|
+
%if %sysfunc(filename(fref,&sasjs_stpsrv_header_loc)) ne 0 %then %do;
|
|
34
|
+
%put &=fref &=sasjs_stpsrv_header_loc;
|
|
35
|
+
%put %str(ERR)OR: %sysfunc(sysmsg());
|
|
36
|
+
%return;
|
|
37
|
+
%end;
|
|
38
|
+
|
|
39
|
+
%let fid=%sysfunc(fopen(&fref,A));
|
|
40
|
+
|
|
41
|
+
%if &fid=0 %then %do;
|
|
42
|
+
%put %str(ERR)OR: %sysfunc(sysmsg());
|
|
43
|
+
%return;
|
|
44
|
+
%end;
|
|
45
|
+
|
|
46
|
+
%let rc=%sysfunc(fput(&fid,%str(&header_name): %str(&header_value)));
|
|
47
|
+
%let rc=%sysfunc(fwrite(&fid));
|
|
48
|
+
|
|
49
|
+
%let rc=%sysfunc(fclose(&fid));
|
|
50
|
+
%let rc=%sysfunc(filename(&fref));
|
|
51
|
+
|
|
52
|
+
%mend mfs_httpheader;
|