@sasjs/core 4.6.0 → 4.9.1
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/base/mf_getplatform.sas +6 -0
- package/base/mp_assertscope.sas +1 -1
- package/base/mp_cntlout.sas +85 -0
- package/base/mp_getformats.sas +2 -2
- 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_sas_cntlout.sas +22 -17
- package/package.json +1 -1
- package/server/mfs_httpheader.sas +52 -0
- package/server/ms_webout.sas +0 -6
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_getformats.sas
CHANGED
|
@@ -113,10 +113,10 @@ create table &outsummary as
|
|
|
113
113
|
select &&fmtname&i;
|
|
114
114
|
run;
|
|
115
115
|
data &tempds;
|
|
116
|
-
|
|
116
|
+
if 0 then set &outdetail;
|
|
117
117
|
set &tempds;
|
|
118
118
|
run;
|
|
119
|
-
proc append base=&outdetail data=&tempds;
|
|
119
|
+
proc append base=&outdetail data=&tempds ;
|
|
120
120
|
run;
|
|
121
121
|
%end;
|
|
122
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
|
|
package/ddl/mddl_sas_cntlout.sas
CHANGED
|
@@ -12,25 +12,30 @@
|
|
|
12
12
|
|
|
13
13
|
proc sql;
|
|
14
14
|
create table &libds(
|
|
15
|
-
FMTNAME char(32)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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'
|
|
19
24
|
,MIN num length=3 label='Minimum length'
|
|
20
25
|
,MAX num length=3 label='Maximum length'
|
|
21
|
-
,DEFAULT num length=3
|
|
22
|
-
,LENGTH num length=3
|
|
23
|
-
,FUZZ num
|
|
24
|
-
,PREFIX char(2)
|
|
25
|
-
,MULT num
|
|
26
|
-
,FILL char(1)
|
|
27
|
-
,NOEDIT num length=3
|
|
28
|
-
,TYPE char(1)
|
|
29
|
-
,SEXCL char(1)
|
|
30
|
-
,EEXCL char(1)
|
|
31
|
-
,HLO char(13)
|
|
32
|
-
,DECSEP char(1)
|
|
33
|
-
,DIG3SEP char(1)
|
|
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'
|
|
34
39
|
,DATATYPE char(8) label='Date/time/datetime?'
|
|
35
40
|
,LANGUAGE char(8) label='Language for date strings'
|
|
36
41
|
);
|
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;
|
package/server/ms_webout.sas
CHANGED
|
@@ -88,9 +88,6 @@
|
|
|
88
88
|
|
|
89
89
|
/* setup json */
|
|
90
90
|
data _null_;file &fref encoding='utf-8' termstr=lf;
|
|
91
|
-
%if %str(&_debug) ge 131 %then %do;
|
|
92
|
-
put '>>weboutBEGIN<<';
|
|
93
|
-
%end;
|
|
94
91
|
put '{"SYSDATE" : "' "&SYSDATE" '"';
|
|
95
92
|
put ',"SYSTIME" : "' "&SYSTIME" '"';
|
|
96
93
|
run;
|
|
@@ -170,9 +167,6 @@
|
|
|
170
167
|
memsize=quote(cats(memsize));
|
|
171
168
|
put ',"MEMSIZE" : ' memsize;
|
|
172
169
|
put "}" @;
|
|
173
|
-
%if %str(&_debug) ge 131 %then %do;
|
|
174
|
-
put '>>weboutEND<<';
|
|
175
|
-
%end;
|
|
176
170
|
run;
|
|
177
171
|
%end;
|
|
178
172
|
|