@sasjs/core 2.59.1 → 3.0.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/{mp_mdtablewrite.sas → mp_ds2md.sas} +18 -18
- package/base/mp_getformats.sas +141 -0
- package/base/mp_init.sas +8 -5
- package/base/mp_makedata.sas +2 -2
- package/base/mp_sortinplace.sas +11 -4
- package/base/mp_storediffs.sas +9 -9
- package/meta/mm_getstps.sas +1 -2
- 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));
|
|
@@ -29,44 +29,44 @@
|
|
|
29
29
|
|
|
30
30
|
Usage:
|
|
31
31
|
|
|
32
|
-
%
|
|
32
|
+
%mp_ds2md(sashelp.class)
|
|
33
33
|
|
|
34
|
+
@param [in] libds the library / dataset to create or read from.
|
|
35
|
+
@param [out] outref= (mdtable) Fileref to contain the markdown
|
|
36
|
+
@param [out] showlog= (YES) Set to NO to avoid printing markdown to the log
|
|
34
37
|
|
|
35
38
|
<h4> SAS Macros </h4>
|
|
36
39
|
@li mf_getvarlist.sas
|
|
37
40
|
@li mf_getvarformat.sas
|
|
38
41
|
|
|
39
|
-
@param [in] libds= the library / dataset to create or read from.
|
|
40
|
-
@param [out] fref= Fileref to contain the markdown. Default=mdtable.
|
|
41
|
-
@param [out] showlog= set to YES to show the markdown in the log. Default=NO.
|
|
42
|
-
|
|
43
42
|
@version 9.3
|
|
44
43
|
@author Allan Bowe
|
|
45
44
|
**/
|
|
46
45
|
|
|
47
|
-
%macro
|
|
48
|
-
libds
|
|
49
|
-
|
|
50
|
-
showlog=
|
|
46
|
+
%macro mp_ds2md(
|
|
47
|
+
libds,
|
|
48
|
+
outref=mdtable,
|
|
49
|
+
showlog=YES
|
|
51
50
|
)/*/STORE SOURCE*/;
|
|
52
51
|
|
|
53
52
|
/* check fileref is assigned */
|
|
54
|
-
%if %sysfunc(fileref(&
|
|
55
|
-
filename &
|
|
53
|
+
%if %sysfunc(fileref(&outref)) > 0 %then %do;
|
|
54
|
+
filename &outref temp;
|
|
56
55
|
%end;
|
|
57
56
|
|
|
58
57
|
%local vars;
|
|
59
|
-
%let vars=%mf_getvarlist(&libds);
|
|
58
|
+
%let vars=%upcase(%mf_getvarlist(&libds));
|
|
60
59
|
|
|
61
60
|
/* create the header row */
|
|
62
61
|
data _null_;
|
|
63
|
-
file &
|
|
62
|
+
file &outref;
|
|
64
63
|
length line $32767;
|
|
64
|
+
call missing(line);
|
|
65
65
|
put '|'
|
|
66
66
|
%local i var fmt;
|
|
67
67
|
%do i=1 %to %sysfunc(countw(&vars));
|
|
68
68
|
%let var=%scan(&vars,&i);
|
|
69
|
-
%let fmt=%mf_getvarformat(&libds,&var,force=1);
|
|
69
|
+
%let fmt=%lowcase(%mf_getvarformat(&libds,&var,force=1));
|
|
70
70
|
"&var:&fmt|"
|
|
71
71
|
%end;
|
|
72
72
|
;
|
|
@@ -79,20 +79,20 @@ run;
|
|
|
79
79
|
|
|
80
80
|
/* write out the data */
|
|
81
81
|
data _null_;
|
|
82
|
-
file &
|
|
82
|
+
file &outref mod dlm='|' lrecl=32767;
|
|
83
83
|
set &libds ;
|
|
84
84
|
length line $32767;
|
|
85
|
-
line=cats(
|
|
85
|
+
line='|`'!!cats(%mf_getvarlist(&libds,dlm=%str(%)!!' `|`'!!cats%()))!!' `|';
|
|
86
86
|
put line;
|
|
87
87
|
run;
|
|
88
88
|
|
|
89
89
|
%if %upcase(&showlog)=YES %then %do;
|
|
90
90
|
options ps=max;
|
|
91
91
|
data _null_;
|
|
92
|
-
infile &
|
|
92
|
+
infile &outref;
|
|
93
93
|
input;
|
|
94
94
|
putlog _infile_;
|
|
95
95
|
run;
|
|
96
96
|
%end;
|
|
97
97
|
|
|
98
|
-
%mend
|
|
98
|
+
%mend mp_ds2md;
|
|
@@ -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_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_makedata.sas
CHANGED
|
@@ -64,13 +64,13 @@ data &ds1;
|
|
|
64
64
|
&n1=ranuni(1)*5000000;
|
|
65
65
|
drop &c1 &n1;
|
|
66
66
|
%let charvars=%mf_getvarlist(&libds,typefilter=C);
|
|
67
|
-
%do i=1 %to %sysfunc(countw(&charvars));
|
|
67
|
+
%if &charvars ^= %then %do i=1 %to %sysfunc(countw(&charvars));
|
|
68
68
|
%let col=%scan(&charvars,&i);
|
|
69
69
|
&col=subpad(&c1,1,%mf_getvarlen(&libds,&col));
|
|
70
70
|
%end;
|
|
71
71
|
|
|
72
72
|
%let numvars=%mf_getvarlist(&libds,typefilter=N);
|
|
73
|
-
%do i=1 %to %sysfunc(countw(&numvars));
|
|
73
|
+
%if &numvars ^= %then %do i=1 %to %sysfunc(countw(&numvars));
|
|
74
74
|
%let col=%scan(&numvars,&i);
|
|
75
75
|
&col=&n1;
|
|
76
76
|
%end;
|
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
|
|
package/base/mp_storediffs.sas
CHANGED
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
'Did value change? (1/0/-1). Always -1 for appends and deletes.',
|
|
66
66
|
tgtvar_type char(1) label='Either (C)haracter or (N)umeric',
|
|
67
67
|
tgtvar_nm char(32) label='Target variable name (32 chars)',
|
|
68
|
-
oldval_num num label='Old (numeric) value',
|
|
69
|
-
newval_num num label='New (numeric) value',
|
|
70
|
-
oldval_char char(
|
|
71
|
-
newval_char char(
|
|
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
72
|
constraint pk_mpe_audit
|
|
73
73
|
primary key(load_ref,libref,dsn,key_hash,tgtvar_nm)
|
|
74
74
|
);
|
|
@@ -212,18 +212,18 @@ create table &outds as
|
|
|
212
212
|
,b.tgtvar_type length=1
|
|
213
213
|
,case when b.move_type='D' then b.newval_num
|
|
214
214
|
else a.newval_num
|
|
215
|
-
end as oldval_num
|
|
215
|
+
end as oldval_num format=best32.
|
|
216
216
|
,case when b.move_type='D' then .
|
|
217
217
|
else b.newval_num
|
|
218
|
-
end as newval_num
|
|
218
|
+
end as newval_num format=best32.
|
|
219
219
|
,case when b.move_type='D' then b.newval_char
|
|
220
220
|
else a.newval_char
|
|
221
|
-
end as oldval_char length=
|
|
221
|
+
end as oldval_char length=32765
|
|
222
222
|
,case when b.move_type='D' then ''
|
|
223
223
|
else b.newval_char
|
|
224
|
-
end as newval_char length=
|
|
224
|
+
end as newval_char length=32765
|
|
225
225
|
from &ds4(where=(move_type='O')) as a
|
|
226
|
-
|
|
226
|
+
right join &ds4(where=(move_type ne 'O')) as b
|
|
227
227
|
on a.tgtvar_nm=b.tgtvar_nm
|
|
228
228
|
and a.key_hash=b.key_hash
|
|
229
229
|
order by move_type, key_hash,is_pk desc, tgtvar_nm;
|
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/package.json
CHANGED