@sasjs/core 2.58.3 → 2.61.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/.sasjslint +1 -1
- package/base/mf_dedup.sas +54 -0
- package/base/mf_getfmtlist.sas +61 -0
- package/base/mf_getfmtname.sas +44 -0
- package/base/mf_getquotedstr.sas +6 -3
- package/base/mf_getvarlist.sas +1 -1
- package/base/mp_getformats.sas +141 -0
- package/base/mp_include.sas +1 -0
- package/base/mp_init.sas +8 -5
- package/base/mp_lockanytable.sas +1 -1
- package/base/mp_mdtablewrite.sas +1 -0
- package/base/mp_sortinplace.sas +11 -4
- package/base/mp_storediffs.sas +237 -0
- package/meta/mm_getdetails.sas +1 -1
- package/meta/mm_getstps.sas +1 -2
- package/meta/mm_gettables.sas +1 -1
- package/package.json +1 -1
package/.sasjslint
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief de-duplicates a macro string
|
|
4
|
+
@details Removes all duplicates from a string of words. A delimeter can be
|
|
5
|
+
chosen. Is inspired heavily by this excellent [macro](
|
|
6
|
+
https://github.com/scottbass/SAS/blob/master/Macro/dedup_mstring.sas) from
|
|
7
|
+
[Scott Base](https://www.linkedin.com/in/scottbass). Case sensitive.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
|
|
11
|
+
%let str=One two one two and through and through;
|
|
12
|
+
%put %mf_dedup(&str);
|
|
13
|
+
%put %mf_dedup(&str,outdlm=%str(,));
|
|
14
|
+
|
|
15
|
+
Which returns:
|
|
16
|
+
|
|
17
|
+
> One two one and through
|
|
18
|
+
> One,two,one,and,through
|
|
19
|
+
|
|
20
|
+
@param [in] str String to be deduplicated
|
|
21
|
+
@param [in] indlm= ( ) Delimeter of the input string
|
|
22
|
+
@param [out] outdlm= ( ) Delimiter of the output string
|
|
23
|
+
|
|
24
|
+
<h4> Related Macros </h4>
|
|
25
|
+
@li mf_trimstr.sas
|
|
26
|
+
@li mf_wordsinstr1butnotstr2.sas
|
|
27
|
+
|
|
28
|
+
@version 9.2
|
|
29
|
+
@author Allan Bowe
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mf_dedup(str
|
|
33
|
+
,indlm=%str( )
|
|
34
|
+
,outdlm=%str( )
|
|
35
|
+
)/*/STORE SOURCE*/;
|
|
36
|
+
|
|
37
|
+
%local num word i pos out;
|
|
38
|
+
|
|
39
|
+
%* loop over each token, searching the target for that token ;
|
|
40
|
+
%let num=%sysfunc(countc(%superq(str),%str(&indlm)));
|
|
41
|
+
%do i=1 %to %eval(&num+1);
|
|
42
|
+
%let word=%scan(%superq(str),&i,%str(&indlm));
|
|
43
|
+
%let pos=%sysfunc(indexw(&out,&word,%str(&outdlm)));
|
|
44
|
+
%if (&pos eq 0) %then %do;
|
|
45
|
+
%if (&i gt 1) %then %let out=&out%str(&outdlm);
|
|
46
|
+
%let out=&out&word;
|
|
47
|
+
%end;
|
|
48
|
+
%end;
|
|
49
|
+
|
|
50
|
+
%unquote(&out)
|
|
51
|
+
|
|
52
|
+
%mend mf_dedup;
|
|
53
|
+
|
|
54
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Returns a distinct list of formats from a table
|
|
4
|
+
@details Reads the dataset header and returns a distinct list of formats
|
|
5
|
+
applied.
|
|
6
|
+
|
|
7
|
+
%put NOTE- %mf_getfmtlist(sashelp.prdsale);
|
|
8
|
+
%put NOTE- %mf_getfmtlist(sashelp.shoes);
|
|
9
|
+
%put NOTE- %mf_getfmtlist(sashelp.demographics);
|
|
10
|
+
|
|
11
|
+
returns:
|
|
12
|
+
|
|
13
|
+
> DOLLAR $CHAR W MONNAME
|
|
14
|
+
> $CHAR BEST DOLLAR
|
|
15
|
+
> BEST Z $CHAR COMMA PERCENTN
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@param [in] libds Two part library.dataset reference.
|
|
19
|
+
|
|
20
|
+
<h4> SAS Macros </h4>
|
|
21
|
+
@li mf_getfmtname.sas
|
|
22
|
+
|
|
23
|
+
@version 9.2
|
|
24
|
+
@author Allan Bowe
|
|
25
|
+
|
|
26
|
+
**/
|
|
27
|
+
|
|
28
|
+
%macro mf_getfmtlist(libds
|
|
29
|
+
)/*/STORE SOURCE*/;
|
|
30
|
+
/* declare local vars */
|
|
31
|
+
%local out dsid nvars x rc fmt;
|
|
32
|
+
|
|
33
|
+
/* open dataset in macro */
|
|
34
|
+
%let dsid=%sysfunc(open(&libds));
|
|
35
|
+
|
|
36
|
+
/* continue if dataset exists */
|
|
37
|
+
%if &dsid %then %do;
|
|
38
|
+
/* loop each variable in the dataset */
|
|
39
|
+
%let nvars=%sysfunc(attrn(&dsid,NVARS));
|
|
40
|
+
%do x=1 %to &nvars;
|
|
41
|
+
/* grab format and check it exists */
|
|
42
|
+
%let fmt=%sysfunc(varfmt(&dsid,&x));
|
|
43
|
+
%if %quote(&fmt) ne %quote() %then %let fmt=%mf_getfmtname(&fmt);
|
|
44
|
+
%else %do;
|
|
45
|
+
/* assign default format depending on variable type */
|
|
46
|
+
%if %sysfunc(vartype(&dsid, &x))=C %then %let fmt=$CHAR;
|
|
47
|
+
%else %let fmt=BEST;
|
|
48
|
+
%end;
|
|
49
|
+
/* concatenate unique list of formats */
|
|
50
|
+
%if %sysfunc(indexw(&out,&fmt,%str( )))=0 %then %let out=&out &fmt;
|
|
51
|
+
%end;
|
|
52
|
+
%let rc=%sysfunc(close(&dsid));
|
|
53
|
+
%end;
|
|
54
|
+
%else %do;
|
|
55
|
+
%put &sysmacroname: Unable to open &libds (rc=&dsid);
|
|
56
|
+
%put &sysmacroname: SYSMSG= %sysfunc(sysmsg());
|
|
57
|
+
%let rc=%sysfunc(close(&dsid));
|
|
58
|
+
%end;
|
|
59
|
+
/* send them out without spaces or quote markers */
|
|
60
|
+
%do;%unquote(&out)%end;
|
|
61
|
+
%mend mf_getfmtlist;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Extracts a format name from a fully defined format
|
|
4
|
+
@details Converts formats in like $thi3. and th13.2 $THI and TH.
|
|
5
|
+
Usage:
|
|
6
|
+
|
|
7
|
+
%put %mf_getfmtname(8.);
|
|
8
|
+
%put %mf_getfmtname($4.);
|
|
9
|
+
%put %mf_getfmtname(comma14.10);
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
|
|
13
|
+
> W
|
|
14
|
+
> $CHAR
|
|
15
|
+
> COMMA
|
|
16
|
+
|
|
17
|
+
Note that system defaults are inferred from the values provided.
|
|
18
|
+
|
|
19
|
+
@param [in] fmt The fully defined format. If left blank, nothing is returned.
|
|
20
|
+
|
|
21
|
+
@returns The name (without width or decimal) of the format.
|
|
22
|
+
|
|
23
|
+
@version 9.2
|
|
24
|
+
@author Allan Bowe
|
|
25
|
+
|
|
26
|
+
**/
|
|
27
|
+
|
|
28
|
+
%macro mf_getfmtname(fmt
|
|
29
|
+
)/*/STORE SOURCE*/ /minoperator mindelimiter=' ';
|
|
30
|
+
|
|
31
|
+
%local out dsid nvars x rc fmt;
|
|
32
|
+
|
|
33
|
+
/* extract actual format name from the format definition */
|
|
34
|
+
%let fmt=%scan(&fmt,1,.);
|
|
35
|
+
%do %while(%substr(&fmt,%length(&fmt),1) in 1 2 3 4 5 6 7 8 9 0);
|
|
36
|
+
%if %length(&fmt)=1 %then %let fmt=W;
|
|
37
|
+
%else %let fmt=%substr(&fmt,1,%length(&fmt)-1);
|
|
38
|
+
%end;
|
|
39
|
+
|
|
40
|
+
%if &fmt=$ %then %let fmt=$CHAR;
|
|
41
|
+
|
|
42
|
+
/* send them out without spaces or quote markers */
|
|
43
|
+
%do;%unquote(%upcase(&fmt))%end;
|
|
44
|
+
%mend mf_getfmtname;
|
package/base/mf_getquotedstr.sas
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
> "these","words","are","double","quoted"
|
|
17
17
|
|
|
18
18
|
@param [in] in_str The unquoted, spaced delimited string to transform
|
|
19
|
-
@param [in] dlm= The delimeter to be applied to the output (default comma)
|
|
20
|
-
@param [in] indlm= (
|
|
19
|
+
@param [in] dlm= (,) The delimeter to be applied to the output (default comma)
|
|
20
|
+
@param [in] indlm= ( ) The delimeter used for the input (default is space)
|
|
21
21
|
@param [in] quote= (S) The quote mark to apply (S=Single, D=Double, N=None).
|
|
22
22
|
If any other value than uppercase S or D is supplied, then that value will
|
|
23
23
|
be used as the quoting character.
|
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
**/
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
%macro mf_getquotedstr(IN_STR
|
|
31
|
+
%macro mf_getquotedstr(IN_STR
|
|
32
|
+
,DLM=%str(,)
|
|
33
|
+
,QUOTE=S
|
|
34
|
+
,indlm=%str( )
|
|
32
35
|
)/*/STORE SOURCE*/;
|
|
33
36
|
/* credit Rowland Hale - byte34 is double quote, 39 is single quote */
|
|
34
37
|
%if "e=S %then %let quote=%qsysfunc(byte(39));
|
package/base/mf_getvarlist.sas
CHANGED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Export format definitions
|
|
4
|
+
@details Formats are exported from the first (if any) catalog entry in the
|
|
5
|
+
FMTSEARCH path.
|
|
6
|
+
|
|
7
|
+
Formats are taken from the library / dataset reference and / or a static
|
|
8
|
+
format list.
|
|
9
|
+
|
|
10
|
+
Example usage:
|
|
11
|
+
|
|
12
|
+
%mp_getformats(lib=sashelp,ds=prdsale,outsummary=work.dictable)
|
|
13
|
+
|
|
14
|
+
@param [in] lib= (0) The libref for which to return formats.
|
|
15
|
+
@todo Enable exporting of formats for an entire library
|
|
16
|
+
@param [in] ds= (0) The dataset from which to obtain format definitions
|
|
17
|
+
@param [in] fmtlist= (0) A list of additional format names
|
|
18
|
+
@param [out] outsummary= (work.mp_getformats_summary) Output dataset
|
|
19
|
+
containing summary definitions - structure taken from dictionary.formats as
|
|
20
|
+
follows:
|
|
21
|
+
|
|
22
|
+
|libname:$8.|memname:$32.|path:$1024.|objname:$32.|fmtname:$32.|fmttype:$1.|source:$1.|minw:best.|mind:best.|maxw:best.|maxd:best.|defw:best.|defd:best.|
|
|
23
|
+
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
24
|
+
| | | | |$|F|B|1|0|32767|0|1|0|
|
|
25
|
+
| | | | |$|I|B|1|0|32767|0|1|0|
|
|
26
|
+
| | |/opt/sas/sas9/SASHome/SASFoundation/9.4/sasexe|UWIANYDT|$ANYDTIF|I|U|1|0|60|0|19|0|
|
|
27
|
+
| | |/opt/sas/sas9/SASHome/SASFoundation/9.4/sasexe|UWFASCII|$ASCII|F|U|1|0|32767|0|1|0|
|
|
28
|
+
| | |/opt/sas/sas9/SASHome/SASFoundation/9.4/sasexe|UWIASCII|$ASCII|I|U|1|0|32767|0|1|0|
|
|
29
|
+
| | |/opt/sas/sas9/SASHome/SASFoundation/9.4/sasexe|UWFBASE6|$BASE64X|F|U|1|0|32767|0|1|0|
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@param [out] outdetail= (0) Provide an output dataset in which to export all
|
|
33
|
+
the custom format definitions (from proc format CNTLOUT). Definitions:
|
|
34
|
+
https://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473477.htm
|
|
35
|
+
Sample data:
|
|
36
|
+
|
|
37
|
+
|FMTNAME:$32.|START:$16.|END:$16.|LABEL:$256.|MIN:best.|MAX:best.|DEFAULT:best.|LENGTH:best.|FUZZ:best.|PREFIX:$2.|MULT:best.|FILL:$1.|NOEDIT:best.|TYPE:$1.|SEXCL:$1.|EEXCL:$1.|HLO:$13.|DECSEP:$1.|DIG3SEP:$1.|DATATYPE:$8.|LANGUAGE:$8.|
|
|
38
|
+
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
39
|
+
|WHICHPATH|0|0|path1|1|40|28|28|1E-12||0||0|N|N|N| | | | | |
|
|
40
|
+
|WHICHPATH|`**OTHER**`|`**OTHER**`|big fat problem if not path1|1|40|28|28|1E-12||0||0|N|N|N|O| | | | |
|
|
41
|
+
|
|
42
|
+
<h4> SAS Macros </h4>
|
|
43
|
+
@li mf_dedup.sas
|
|
44
|
+
@li mf_getfmtlist.sas
|
|
45
|
+
@li mf_getfmtname.sas
|
|
46
|
+
@li mf_getquotedstr.sas
|
|
47
|
+
@li mf_getuniquename.sas
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
<h4> Related Macros </h4>
|
|
51
|
+
@li mp_getformats.test.sas
|
|
52
|
+
|
|
53
|
+
@version 9.2
|
|
54
|
+
@author Allan Bowe
|
|
55
|
+
|
|
56
|
+
**/
|
|
57
|
+
|
|
58
|
+
%macro mp_getformats(lib=0
|
|
59
|
+
,ds=0
|
|
60
|
+
,fmtlist=0
|
|
61
|
+
,outsummary=work.mp_getformats_summary
|
|
62
|
+
,outdetail=0
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
%local i fmt allfmts tempds fmtcnt;
|
|
66
|
+
|
|
67
|
+
%if "&fmtlist" ne "0" %then %do i=1 %to %sysfunc(countw(&fmtlist,,%str( )));
|
|
68
|
+
/* ensure format list contains format _name_ only */
|
|
69
|
+
%let fmt=%scan(&fmtlist,&i,%str( ));
|
|
70
|
+
%let fmt=%mf_getfmtname(&fmt);
|
|
71
|
+
%let allfmts=&allfmts &fmt;
|
|
72
|
+
%end;
|
|
73
|
+
|
|
74
|
+
%if &ds=0 and &lib ne 0 %then %do;
|
|
75
|
+
/* grab formats from library */
|
|
76
|
+
/* to do */
|
|
77
|
+
%end;
|
|
78
|
+
%else %if &ds ne 0 and &lib ne 0 %then %do;
|
|
79
|
+
/* grab formats from dataset */
|
|
80
|
+
%let allfmts=%mf_getfmtlist(&lib..&ds) &allfmts;
|
|
81
|
+
%end;
|
|
82
|
+
|
|
83
|
+
/* ensure list is unique */
|
|
84
|
+
%let allfmts=%mf_dedup(%upcase(&allfmts));
|
|
85
|
+
|
|
86
|
+
/* create summary table */
|
|
87
|
+
%if %index(&outsummary,.)=0 %then %let outsummary=WORK.&outsummary;
|
|
88
|
+
proc sql;
|
|
89
|
+
create table &outsummary as
|
|
90
|
+
select * from dictionary.formats
|
|
91
|
+
where fmtname in (%mf_getquotedstr(&allfmts,quote=D))
|
|
92
|
+
and fmttype='F';
|
|
93
|
+
|
|
94
|
+
%if "&outdetail" ne "0" %then %do;
|
|
95
|
+
/* ensure base table always exists */
|
|
96
|
+
proc sql;
|
|
97
|
+
create table &outdetail(
|
|
98
|
+
FMTNAME char(32) label='Format name'
|
|
99
|
+
,START char(16) label='Starting value for format'
|
|
100
|
+
,END char(16) label='Ending value for format'
|
|
101
|
+
,LABEL char(256) label='Format value label'
|
|
102
|
+
,MIN num length=3 label='Minimum length'
|
|
103
|
+
,MAX num length=3 label='Maximum length'
|
|
104
|
+
,DEFAULT num length=3 label='Default length'
|
|
105
|
+
,LENGTH num length=3 label='Format length'
|
|
106
|
+
,FUZZ num label='Fuzz value'
|
|
107
|
+
,PREFIX char(2) label='Prefix characters'
|
|
108
|
+
,MULT num label='Multiplier'
|
|
109
|
+
,FILL char(1) label='Fill character'
|
|
110
|
+
,NOEDIT num length=3 label='Is picture string noedit?'
|
|
111
|
+
,TYPE char(1) label='Type of format'
|
|
112
|
+
,SEXCL char(1) label='Start exclusion'
|
|
113
|
+
,EEXCL char(1) label='End exclusion'
|
|
114
|
+
,HLO char(13) label='Additional information'
|
|
115
|
+
,DECSEP char(1) label='Decimal separator'
|
|
116
|
+
,DIG3SEP char(1) label='Three-digit separator'
|
|
117
|
+
,DATATYPE char(8) label='Date/time/datetime?'
|
|
118
|
+
,LANGUAGE char(8) label='Language for date strings'
|
|
119
|
+
);
|
|
120
|
+
/* grab the location of each format */
|
|
121
|
+
%let fmtcnt=0;
|
|
122
|
+
data _null_;
|
|
123
|
+
set &outsummary;
|
|
124
|
+
if not missing(libname);
|
|
125
|
+
x+1;
|
|
126
|
+
call symputx(cats('fmtloc',x),cats(libname,'.',memname),'l');
|
|
127
|
+
call symputx(cats('fmtname',x),fmtname,'l');
|
|
128
|
+
call symputx('fmtcnt',x,'l');
|
|
129
|
+
run;
|
|
130
|
+
/* export each format and append to the output table */
|
|
131
|
+
%let tempds=%mf_getuniquename(prefix=mp_getformats);
|
|
132
|
+
%do i=1 %to &fmtcnt;
|
|
133
|
+
proc format library=&&fmtloc&i CNTLOUT=&tempds;
|
|
134
|
+
select &&fmtname&i;
|
|
135
|
+
run;
|
|
136
|
+
proc append base=&outdetail data=&tempds;
|
|
137
|
+
run;
|
|
138
|
+
%end;
|
|
139
|
+
%end;
|
|
140
|
+
|
|
141
|
+
%mend mp_getformats;
|
package/base/mp_include.sas
CHANGED
package/base/mp_init.sas
CHANGED
|
@@ -30,19 +30,21 @@
|
|
|
30
30
|
|
|
31
31
|
**/
|
|
32
32
|
|
|
33
|
-
%macro mp_init(prefix=
|
|
33
|
+
%macro mp_init(prefix=SASJS
|
|
34
34
|
)/*/STORE SOURCE*/;
|
|
35
35
|
|
|
36
36
|
%global
|
|
37
|
-
&prefix._INIT_NUM /* initialisation time as numeric
|
|
38
|
-
&prefix._INIT_DTTM /* initialisation time in E8601DT26.6 format
|
|
37
|
+
&prefix._INIT_NUM /* initialisation time as numeric */
|
|
38
|
+
&prefix._INIT_DTTM /* initialisation time in E8601DT26.6 format */
|
|
39
|
+
&prefix.WORK /* avoid typing %sysfunc(pathname(work)) every time */
|
|
39
40
|
;
|
|
40
41
|
%if %eval(&&&prefix._INIT_NUM>0) %then %return; /* only run once */
|
|
41
42
|
|
|
42
43
|
data _null_;
|
|
43
44
|
dttm=datetime();
|
|
44
|
-
call symputx("&prefix._init_num",dttm);
|
|
45
|
-
call symputx("&prefix._init_dttm",put(dttm,E8601DT26.6));
|
|
45
|
+
call symputx("&prefix._init_num",dttm,'g');
|
|
46
|
+
call symputx("&prefix._init_dttm",put(dttm,E8601DT26.6),'g');
|
|
47
|
+
call symputx("&prefix.work",pathname('WORK'),'g');
|
|
46
48
|
run;
|
|
47
49
|
|
|
48
50
|
options
|
|
@@ -56,6 +58,7 @@
|
|
|
56
58
|
noquotelenmax /* avoid warnings for long strings */
|
|
57
59
|
noreplace /* avoid overwriting permanent datasets */
|
|
58
60
|
ps=max /* reduce log size slightly */
|
|
61
|
+
ls=max /* reduce log even more and avoid word truncation */
|
|
59
62
|
validmemname=COMPATIBLE /* avoid special characters etc in table names */
|
|
60
63
|
validvarname=V7 /* avoid special characters etc in variable names */
|
|
61
64
|
varinitchk=%str(ERR)OR /* avoid data mistakes from variable name typos */
|
package/base/mp_lockanytable.sas
CHANGED
|
@@ -180,7 +180,7 @@ run;
|
|
|
180
180
|
%else %do;
|
|
181
181
|
data _null_;
|
|
182
182
|
putlog 'NOTE-' / 'NOTE-';
|
|
183
|
-
putlog "NOTE- &sysmacroname: Table &lib..&ds locked at "
|
|
183
|
+
putlog "NOTE- &sysmacroname: Table &lib..&ds locked at "@;
|
|
184
184
|
putlog " %sysfunc(datetime(),datetime19.) (iteration &x)"@;
|
|
185
185
|
putlog 'NOTE-' / 'NOTE-';
|
|
186
186
|
run;
|
package/base/mp_mdtablewrite.sas
CHANGED
package/base/mp_sortinplace.sas
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
sort it before performing operations such as merges / joins etc.
|
|
6
6
|
That said, there are a few edge cases where it can be desirable:
|
|
7
7
|
|
|
8
|
-
@li To improve performance for particular scenarios
|
|
9
8
|
@li To allow adjacent records to be viewed directly in the dataset
|
|
10
|
-
@li To
|
|
9
|
+
@li To apply compression, or to remove deleted records
|
|
10
|
+
@li To improve performance for specific queries
|
|
11
11
|
|
|
12
12
|
This macro will only work for BASE (V9) engine libraries. It works by
|
|
13
13
|
creating a copy of the dataset (without data, WITH constraints) in the same
|
|
14
|
-
library, appending a sorted view into it, and finally - renaming it.
|
|
14
|
+
library, appending a sorted view into it, and finally - renaming it. By
|
|
15
|
+
default, COMPRESS=CHAR and REUSE=YES will be applied, this behaviour can
|
|
16
|
+
be adjusted using the `dsoptions=` parameter.
|
|
15
17
|
|
|
16
18
|
Example usage:
|
|
17
19
|
|
|
@@ -29,6 +31,7 @@
|
|
|
29
31
|
@li mf_getengine.sas
|
|
30
32
|
@li mf_getquotedstr.sas
|
|
31
33
|
@li mf_getuniquename.sas
|
|
34
|
+
@li mf_getvarlist.sas
|
|
32
35
|
@li mf_nobs.sas
|
|
33
36
|
@li mp_abort.sas
|
|
34
37
|
@li mp_getpk.sas
|
|
@@ -74,9 +77,13 @@
|
|
|
74
77
|
%return;
|
|
75
78
|
%end;
|
|
76
79
|
|
|
80
|
+
/* fallback sortkey is all fields */
|
|
81
|
+
%let sortkey=%mf_getvarlist(&libds);
|
|
82
|
+
|
|
83
|
+
/* overlay actual sort key if it exists */
|
|
77
84
|
data _null_;
|
|
78
85
|
set work.&tempds1;
|
|
79
|
-
call symputx('sortkey',pk_fields);
|
|
86
|
+
call symputx('sortkey',coalescec(pk_fields,symget('sortkey')));
|
|
80
87
|
run;
|
|
81
88
|
|
|
82
89
|
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Converts deletes/changes/appends into a single audit table.
|
|
4
|
+
@details When tracking changes to data over time, it can be helpful to have
|
|
5
|
+
a single base table to track ALL modifications - enabling audit trail,
|
|
6
|
+
data recovery, and change re-application. This macro is one of many
|
|
7
|
+
data management utilities used in [Data Controller for SAS](
|
|
8
|
+
https:datacontroller.io) - a comprehensive data ingestion solution, which
|
|
9
|
+
works on any SAS platform (Viya, SAS 9, Foundation) and is free for up to 5
|
|
10
|
+
users.
|
|
11
|
+
|
|
12
|
+
NOTE - this macro does not validate the inputs. It is assumed that the
|
|
13
|
+
datasets containing the new / changed / deleted rows are CORRECT, contain
|
|
14
|
+
no additional (or missing columns), and that the originals dataset contains
|
|
15
|
+
all relevant base records (and no additionals).
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
|
|
19
|
+
data work.orig work.deleted work.changed work.appended;
|
|
20
|
+
set sashelp.class;
|
|
21
|
+
if _n_=1 then do;
|
|
22
|
+
output work.orig work.deleted;
|
|
23
|
+
end;
|
|
24
|
+
else if _n_=2 then do;
|
|
25
|
+
output work.orig;
|
|
26
|
+
age=99;
|
|
27
|
+
output work.changed;
|
|
28
|
+
end;
|
|
29
|
+
else do;
|
|
30
|
+
name='Newbie';
|
|
31
|
+
output work.appended;
|
|
32
|
+
stop;
|
|
33
|
+
end;
|
|
34
|
+
run;
|
|
35
|
+
|
|
36
|
+
%mp_storediffs(sashelp.class,work.orig,NAME
|
|
37
|
+
,delds=work.deleted
|
|
38
|
+
,modds=work.changed
|
|
39
|
+
,appds=work.appended
|
|
40
|
+
,outds=work.final
|
|
41
|
+
,mdebug=1
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
@param [in] libds Target table against which the changes were applied
|
|
45
|
+
@param [in] origds Dataset with original (unchanged) records. Can be empty if
|
|
46
|
+
only appending.
|
|
47
|
+
@param [in] key Space seperated list of key variables
|
|
48
|
+
@param [in] delds= (0) Dataset with deleted records
|
|
49
|
+
@param [in] appds= (0) Dataset with appended records
|
|
50
|
+
@param [in] modds= (0) Dataset with modified records
|
|
51
|
+
@param [out] outds= (work.mp_storediffs) Output table containing stored data.
|
|
52
|
+
Has the following format:
|
|
53
|
+
|
|
54
|
+
proc sql;
|
|
55
|
+
create table &outds(
|
|
56
|
+
load_ref char(36) label='unique load reference',
|
|
57
|
+
processed_dttm num format=E8601DT26.6 label='Processed at timestamp',
|
|
58
|
+
libref char(8) label='Library Reference (8 chars)',
|
|
59
|
+
dsn char(32) label='Dataset Name (32 chars)',
|
|
60
|
+
key_hash char(32) label=
|
|
61
|
+
'MD5 Hash of primary key values (pipe seperated)',
|
|
62
|
+
move_type char(1) label='Either (A)ppended, (D)eleted or (M)odified',
|
|
63
|
+
is_pk num label='Is Primary Key Field? (1/0)',
|
|
64
|
+
is_diff num label=
|
|
65
|
+
'Did value change? (1/0/-1). Always -1 for appends and deletes.',
|
|
66
|
+
tgtvar_type char(1) label='Either (C)haracter or (N)umeric',
|
|
67
|
+
tgtvar_nm char(32) label='Target variable name (32 chars)',
|
|
68
|
+
oldval_num num format=best32. label='Old (numeric) value',
|
|
69
|
+
newval_num num format=best32. label='New (numeric) value',
|
|
70
|
+
oldval_char char(32765) label='Old (character) value',
|
|
71
|
+
newval_char char(32765) label='New (character) value',
|
|
72
|
+
constraint pk_mpe_audit
|
|
73
|
+
primary key(load_ref,libref,dsn,key_hash,tgtvar_nm)
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
@param [in] processed_dttm= (0) Provide a datetime constant in relation to
|
|
77
|
+
the actual load time. If not provided, current timestamp is used.
|
|
78
|
+
@param [in] mdebug= set to 1 to enable DEBUG messages and preserve outputs
|
|
79
|
+
@param [out] loadref= (0) Provide a unique key to reference the load,
|
|
80
|
+
otherwise a UUID will be generated.
|
|
81
|
+
|
|
82
|
+
<h4> SAS Macros </h4>
|
|
83
|
+
@li mf_getquotedstr.sas
|
|
84
|
+
@li mf_getuniquename.sas
|
|
85
|
+
@li mf_getvarlist.sas
|
|
86
|
+
|
|
87
|
+
@version 9.2
|
|
88
|
+
@author Allan Bowe
|
|
89
|
+
**/
|
|
90
|
+
/** @cond */
|
|
91
|
+
|
|
92
|
+
%macro mp_storediffs(libds
|
|
93
|
+
,origds
|
|
94
|
+
,key
|
|
95
|
+
,delds=0
|
|
96
|
+
,appds=0
|
|
97
|
+
,modds=0
|
|
98
|
+
,outds=work.mp_storediffs
|
|
99
|
+
,loadref=0
|
|
100
|
+
,processed_dttm=0
|
|
101
|
+
,mdebug=0
|
|
102
|
+
)/*/STORE SOURCE*/;
|
|
103
|
+
%local dbg;
|
|
104
|
+
%if &mdebug=1 %then %do;
|
|
105
|
+
%put &sysmacroname entry vars:;
|
|
106
|
+
%put _local_;
|
|
107
|
+
%end;
|
|
108
|
+
%else %let dbg=*;
|
|
109
|
+
|
|
110
|
+
/* set up unique and temporary vars */
|
|
111
|
+
%local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist;
|
|
112
|
+
%let ds1=%upcase(work.%mf_getuniquename(prefix=mpsd_ds1));
|
|
113
|
+
%let ds2=%upcase(work.%mf_getuniquename(prefix=mpsd_ds2));
|
|
114
|
+
%let ds3=%upcase(work.%mf_getuniquename(prefix=mpsd_ds3));
|
|
115
|
+
%let ds4=%upcase(work.%mf_getuniquename(prefix=mpsd_ds4));
|
|
116
|
+
%let hashkey=%upcase(%mf_getuniquename(prefix=mpsd_hashkey));
|
|
117
|
+
%let inds_auto=%upcase(%mf_getuniquename(prefix=mpsd_inds_auto));
|
|
118
|
+
%let inds_keep=%upcase(%mf_getuniquename(prefix=mpsd_inds_keep));
|
|
119
|
+
|
|
120
|
+
%let dslist=&origds;
|
|
121
|
+
%if &delds ne 0 %then %do;
|
|
122
|
+
%let delds=%upcase(&delds);
|
|
123
|
+
%if %scan(&delds,-1,.)=&delds %then %let delds=WORK.&delds;
|
|
124
|
+
%let dslist=&dslist &delds;
|
|
125
|
+
%end;
|
|
126
|
+
%if &appds ne 0 %then %do;
|
|
127
|
+
%let appds=%upcase(&appds);
|
|
128
|
+
%if %scan(&appds,-1,.)=&appds %then %let appds=WORK.&appds;
|
|
129
|
+
%let dslist=&dslist &appds;
|
|
130
|
+
%end;
|
|
131
|
+
%if &modds ne 0 %then %do;
|
|
132
|
+
%let modds=%upcase(&modds);
|
|
133
|
+
%if %scan(&modds,-1,.)=&modds %then %let modds=WORK.&modds;
|
|
134
|
+
%let dslist=&dslist &modds;
|
|
135
|
+
%end;
|
|
136
|
+
|
|
137
|
+
%let origds=%upcase(&origds);
|
|
138
|
+
%if %scan(&origds,-1,.)=&origds %then %let origds=WORK.&origds;
|
|
139
|
+
|
|
140
|
+
%let key=%upcase(&key);
|
|
141
|
+
|
|
142
|
+
/* hash the key and append all the tables (marking the source) */
|
|
143
|
+
data &ds1;
|
|
144
|
+
set &dslist indsname=&inds_auto;
|
|
145
|
+
&hashkey=put(md5(catx('|',%mf_getquotedstr(&key,quote=N))),$hex32.);
|
|
146
|
+
&inds_keep=&inds_auto;
|
|
147
|
+
proc sort;
|
|
148
|
+
by &inds_keep &hashkey;
|
|
149
|
+
run;
|
|
150
|
+
|
|
151
|
+
/* transpose numeric & char vars */
|
|
152
|
+
proc transpose data=&ds1
|
|
153
|
+
out=&ds2(rename=(&hashkey=key_hash _name_=tgtvar_nm col1=newval_num));
|
|
154
|
+
by &inds_keep &hashkey;
|
|
155
|
+
var _numeric_;
|
|
156
|
+
run;
|
|
157
|
+
proc transpose data=&ds1
|
|
158
|
+
out=&ds3(
|
|
159
|
+
rename=(&hashkey=key_hash _name_=tgtvar_nm col1=newval_char)
|
|
160
|
+
where=(tgtvar_nm not in ("&hashkey","&inds_keep"))
|
|
161
|
+
);
|
|
162
|
+
by &inds_keep &hashkey;
|
|
163
|
+
var _character_;
|
|
164
|
+
run;
|
|
165
|
+
data &ds4;
|
|
166
|
+
length &inds_keep $41 tgtvar_nm $32;
|
|
167
|
+
set &ds2 &ds3 indsname=&inds_auto;
|
|
168
|
+
|
|
169
|
+
tgtvar_nm=upcase(tgtvar_nm);
|
|
170
|
+
if tgtvar_nm in (%upcase(%mf_getvarlist(&libds,dlm=%str(,),quote=DOUBLE)));
|
|
171
|
+
|
|
172
|
+
if &inds_auto="&ds2" then tgtvar_type='N';
|
|
173
|
+
else if &inds_auto="&ds3" then tgtvar_type='C';
|
|
174
|
+
else do;
|
|
175
|
+
putlog "%str(ERR)OR: unidentified vartype input!" &inds_auto;
|
|
176
|
+
call symputx('syscc',98);
|
|
177
|
+
end;
|
|
178
|
+
|
|
179
|
+
if &inds_keep="&appds" then move_type='A';
|
|
180
|
+
else if &inds_keep="&delds" then move_type='D';
|
|
181
|
+
else if &inds_keep="&modds" then move_type='M';
|
|
182
|
+
else if &inds_keep="&origds" then move_type='O';
|
|
183
|
+
else do;
|
|
184
|
+
putlog "%str(ERR)OR: unidentified movetype input!" &inds_keep;
|
|
185
|
+
call symputx('syscc',99);
|
|
186
|
+
end;
|
|
187
|
+
tgtvar_nm=upcase(tgtvar_nm);
|
|
188
|
+
if tgtvar_nm in (%mf_getquotedstr(&key)) then is_pk=1;
|
|
189
|
+
else is_pk=0;
|
|
190
|
+
drop &inds_keep;
|
|
191
|
+
run;
|
|
192
|
+
|
|
193
|
+
%if "&loadref"="0" %then %let loadref=%sysfunc(uuidgen());
|
|
194
|
+
%if &processed_dttm=0 %then %let processed_dttm=%sysfunc(datetime());
|
|
195
|
+
%let libds=%upcase(&libds);
|
|
196
|
+
|
|
197
|
+
/* join orig vals for modified & deleted */
|
|
198
|
+
proc sql;
|
|
199
|
+
create table &outds as
|
|
200
|
+
select "&loadref" as load_ref length=36
|
|
201
|
+
,&processed_dttm as processed_dttm format=E8601DT26.6
|
|
202
|
+
,"%scan(&libds,1,.)" as libref length=8
|
|
203
|
+
,"%scan(&libds,2,.)" as dsn length=32
|
|
204
|
+
,b.key_hash length=32
|
|
205
|
+
,b.move_type length=1
|
|
206
|
+
,b.tgtvar_nm length=32
|
|
207
|
+
,b.is_pk
|
|
208
|
+
,case when b.move_type ne 'M' then -1
|
|
209
|
+
when a.newval_num=b.newval_num and a.newval_char=b.newval_char then 0
|
|
210
|
+
else 1
|
|
211
|
+
end as is_diff
|
|
212
|
+
,b.tgtvar_type length=1
|
|
213
|
+
,case when b.move_type='D' then b.newval_num
|
|
214
|
+
else a.newval_num
|
|
215
|
+
end as oldval_num format=best32.
|
|
216
|
+
,case when b.move_type='D' then .
|
|
217
|
+
else b.newval_num
|
|
218
|
+
end as newval_num format=best32.
|
|
219
|
+
,case when b.move_type='D' then b.newval_char
|
|
220
|
+
else a.newval_char
|
|
221
|
+
end as oldval_char length=32765
|
|
222
|
+
,case when b.move_type='D' then ''
|
|
223
|
+
else b.newval_char
|
|
224
|
+
end as newval_char length=32765
|
|
225
|
+
from &ds4(where=(move_type='O')) as a
|
|
226
|
+
right join &ds4(where=(move_type ne 'O')) as b
|
|
227
|
+
on a.tgtvar_nm=b.tgtvar_nm
|
|
228
|
+
and a.key_hash=b.key_hash
|
|
229
|
+
order by move_type, key_hash,is_pk desc, tgtvar_nm;
|
|
230
|
+
|
|
231
|
+
%if &mdebug=0 %then %do;
|
|
232
|
+
proc sql;
|
|
233
|
+
drop table &ds1, &ds2, &ds3, &ds4;
|
|
234
|
+
%end;
|
|
235
|
+
|
|
236
|
+
%mend mp_storediffs;
|
|
237
|
+
/** @endcond */
|
package/meta/mm_getdetails.sas
CHANGED
package/meta/mm_getstps.sas
CHANGED
|
@@ -63,14 +63,13 @@ run;
|
|
|
63
63
|
%if %length(&tree)>0 %then %do;
|
|
64
64
|
/* get tree info */
|
|
65
65
|
%mm_gettree(tree=&tree,inds=&outds, outds=&outds, mDebug=&mDebug)
|
|
66
|
-
|
|
66
|
+
%if %mf_nobs(&outds)=0 %then %do;
|
|
67
67
|
%put NOTE: Tree &tree did not exist!!;
|
|
68
68
|
%return;
|
|
69
69
|
%end;
|
|
70
70
|
%end;
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
|
|
74
73
|
data &outds ;
|
|
75
74
|
set &outds(rename=(treeuri=treeuri_compare));
|
|
76
75
|
length treeuri query stpuri $256;
|
package/meta/mm_gettables.sas
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
data &outds;
|
|
40
40
|
length uri serveruri conn_uri domainuri libname ServerContext AuthDomain
|
|
41
41
|
path_schema usingpkguri type tableuri $256 id $17
|
|
42
|
-
libdesc $200 libref engine $8 IsDBMSLibname $1
|
|
42
|
+
libdesc $200 libref engine $8 IsDBMSLibname IsPreassigned $1
|
|
43
43
|
tablename $50 /* metadata table names can be longer than $32 */
|
|
44
44
|
;
|
|
45
45
|
keep libname libdesc libref engine ServerContext path_schema AuthDomain
|
package/package.json
CHANGED