@sasjs/core 3.11.1 → 4.2.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 +7 -5
- package/base/mf_abort.sas +1 -1
- package/base/mf_dedup.sas +0 -1
- package/base/mf_existvar.sas +4 -4
- package/base/mf_getfilesize.sas +31 -14
- package/base/mf_wordsinstr1andstr2.sas +0 -1
- package/base/mf_wordsinstr1butnotstr2.sas +5 -5
- package/base/mp_abort.sas +3 -2
- package/base/mp_assertdsobs.sas +8 -9
- package/base/mp_assertscope.sas +39 -14
- package/base/mp_coretable.sas +27 -1
- package/base/mp_createwebservice.sas +10 -8
- package/base/mp_csv2ds.sas +0 -4
- package/base/mp_deletefolder.sas +1 -0
- package/base/mp_dirlist.sas +9 -2
- package/base/mp_ds2csv.sas +119 -14
- package/base/mp_ds2squeeze.sas +120 -0
- package/base/mp_getmaxvarlengths.sas +51 -18
- package/base/mp_guesspk.sas +245 -225
- package/base/mp_init.sas +39 -32
- package/base/mp_jsonout.sas +6 -2
- package/base/mp_stackdiffs.sas +592 -0
- package/base/mp_storediffs.sas +11 -29
- package/base/mp_testservice.sas +25 -11
- package/fcmp/mcf_init.sas +44 -0
- package/fcmp/mcf_length.sas +83 -0
- package/fcmp/mcf_stpsrv_header.sas +6 -2
- package/fcmp/mcf_string2file.sas +9 -0
- package/meta/mm_createstp.sas +1 -0
- package/meta/mm_createwebservice.sas +7 -3
- package/meta/mm_getgroupmembers.sas +15 -8
- package/meta/mm_getservercontexts.sas +11 -4
- package/meta/mm_updatestpsourcecode.sas +0 -11
- package/meta/mm_webout.sas +1 -1
- package/package.json +1 -1
- package/server/ms_webout.sas +1 -1
- package/viya/mv_createwebservice.sas +7 -3
- package/viya/mv_deletefoldermember.sas +1 -0
- package/viya/mv_deletejes.sas +1 -0
- package/viya/mv_webout.sas +1 -1
- package/viya/mv_getaccesstoken.sas +0 -32
- package/viya/mv_getapptoken.sas +0 -23
- package/viya/mv_getrefreshtoken.sas +0 -33
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Create a smaller version of a dataset, without data loss
|
|
4
|
+
@details This macro will scan the input dataset and create a new one, that
|
|
5
|
+
has the minimum variable lengths needed to store the data without data loss.
|
|
6
|
+
|
|
7
|
+
Inspiration was taken from [How to Reduce the Disk Space Required by a
|
|
8
|
+
SAS® Data Set](https://www.lexjansen.com/nesug/nesug06/io/io18.pdf) by
|
|
9
|
+
Selvaratnam Sridharma. The end of the referenced paper presents a macro named
|
|
10
|
+
"squeeze", hence the nomenclature.
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
|
|
14
|
+
data big;
|
|
15
|
+
length my big $32000;
|
|
16
|
+
do i=1 to 1e4;
|
|
17
|
+
my=repeat('oh my',100);
|
|
18
|
+
big='dawg';
|
|
19
|
+
special=._;
|
|
20
|
+
output;
|
|
21
|
+
end;
|
|
22
|
+
run;
|
|
23
|
+
|
|
24
|
+
%mp_ds2squeeze(work.big,outds=work.smaller)
|
|
25
|
+
|
|
26
|
+
The following will also be printed to the log (exact values may differ
|
|
27
|
+
depending on your OS and COMPRESS settings):
|
|
28
|
+
|
|
29
|
+
> MP_DS2SQUEEZE: work.big was 625MB
|
|
30
|
+
|
|
31
|
+
> MP_DS2SQUEEZE: work.smaller is 5MB
|
|
32
|
+
|
|
33
|
+
@param [in] libds The library.dataset to be squeezed
|
|
34
|
+
@param [out] outds= (work.mp_ds2squeeze) The squeezed dataset to create
|
|
35
|
+
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
|
36
|
+
|
|
37
|
+
<h4> SAS Macros </h4>
|
|
38
|
+
@li mf_getfilesize.sas
|
|
39
|
+
@li mf_getuniquefileref.sas
|
|
40
|
+
@li mf_getuniquename.sas
|
|
41
|
+
@li mp_getmaxvarlengths.sas
|
|
42
|
+
|
|
43
|
+
<h4> Related Programs </h4>
|
|
44
|
+
@li mp_ds2squeeze.test.sas
|
|
45
|
+
|
|
46
|
+
@version 9.3
|
|
47
|
+
@author Allan Bowe
|
|
48
|
+
**/
|
|
49
|
+
|
|
50
|
+
%macro mp_ds2squeeze(
|
|
51
|
+
libds,
|
|
52
|
+
outds=work.mp_ds2squeeze,
|
|
53
|
+
mdebug=0
|
|
54
|
+
)/*/STORE SOURCE*/;
|
|
55
|
+
%local dbg source;
|
|
56
|
+
%if &mdebug=1 %then %do;
|
|
57
|
+
%put &sysmacroname entry vars:;
|
|
58
|
+
%put _local_;
|
|
59
|
+
%end;
|
|
60
|
+
%else %do;
|
|
61
|
+
%let dbg=*;
|
|
62
|
+
%let source=/source2;
|
|
63
|
+
%end;
|
|
64
|
+
|
|
65
|
+
%local optval ds fref startsize;
|
|
66
|
+
%let ds=%mf_getuniquename();
|
|
67
|
+
%let fref=%mf_getuniquefileref();
|
|
68
|
+
%let startsize=%mf_getfilesize(libds=&libds,format=yes);
|
|
69
|
+
|
|
70
|
+
%mp_getmaxvarlengths(&libds,outds=&ds)
|
|
71
|
+
|
|
72
|
+
data _null_;
|
|
73
|
+
set &ds end=last;
|
|
74
|
+
file &fref;
|
|
75
|
+
/* grab the types */
|
|
76
|
+
retain dsid;
|
|
77
|
+
if _n_=1 then dsid=open("&libds",'is');
|
|
78
|
+
if dsid le 0 then do;
|
|
79
|
+
msg=sysmsg();
|
|
80
|
+
put msg=;
|
|
81
|
+
stop;
|
|
82
|
+
end;
|
|
83
|
+
type=vartype(dsid,varnum(dsid, name));
|
|
84
|
+
if last then rc=close(dsid);
|
|
85
|
+
/* write out the length statement */
|
|
86
|
+
if _n_=1 then put 'length ';
|
|
87
|
+
length len $6;
|
|
88
|
+
if type='C' then do;
|
|
89
|
+
if maxlen=0 then len='$1';
|
|
90
|
+
else len=cats('$',maxlen);
|
|
91
|
+
end;
|
|
92
|
+
else do;
|
|
93
|
+
if maxlen=0 then len='3';
|
|
94
|
+
else len=cats(maxlen);
|
|
95
|
+
end;
|
|
96
|
+
put ' ' name ' ' len;
|
|
97
|
+
if last then put ';';
|
|
98
|
+
run;
|
|
99
|
+
|
|
100
|
+
/* configure varlenchk - as we are explicitly shortening the variables */
|
|
101
|
+
%let optval=%sysfunc(getoption(varlenchk));
|
|
102
|
+
options varlenchk=NOWARN;
|
|
103
|
+
|
|
104
|
+
data &outds;
|
|
105
|
+
%inc &fref &source;
|
|
106
|
+
set &libds;
|
|
107
|
+
run;
|
|
108
|
+
|
|
109
|
+
options varlenchk=&optval;
|
|
110
|
+
|
|
111
|
+
%if &mdebug=0 %then %do;
|
|
112
|
+
proc sql;
|
|
113
|
+
drop table &ds;
|
|
114
|
+
filename &fref clear;
|
|
115
|
+
%end;
|
|
116
|
+
|
|
117
|
+
%put &sysmacroname: &libds was &startsize;
|
|
118
|
+
%put &sysmacroname: &outds is %mf_getfilesize(libds=&outds,format=yes);
|
|
119
|
+
|
|
120
|
+
%mend mp_ds2squeeze;
|
|
@@ -1,28 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
@file
|
|
2
|
+
@file
|
|
3
3
|
@brief Scans a dataset to find the max length of the variable values
|
|
4
4
|
@details
|
|
5
5
|
This macro will scan a base dataset and produce an output dataset with two
|
|
6
6
|
columns:
|
|
7
7
|
|
|
8
8
|
- NAME Name of the base dataset column
|
|
9
|
-
- MAXLEN
|
|
9
|
+
- MAXLEN Maximum length of the data contained therein.
|
|
10
10
|
|
|
11
|
-
Character fields
|
|
12
|
-
maximum value is likely to be much narrower.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
Character fields are often allocated very large widths (eg 32000) of which the
|
|
12
|
+
maximum value is likely to be much narrower. Identifying such cases can be
|
|
13
|
+
helpful in the following scenarios:
|
|
14
|
+
|
|
15
|
+
@li Enabling a HTML table to be appropriately sized (`num2char=YES`)
|
|
16
|
+
@li Reducing the size of a dataset to save on storage (mp_ds2squeeze.sas)
|
|
17
|
+
@li Identifying columns containing nothing but missing values (`MAXLEN=0` in
|
|
18
|
+
the output table)
|
|
19
|
+
|
|
20
|
+
If the entire column is made up of (non-special) missing values then a value
|
|
21
|
+
of 0 is returned.
|
|
16
22
|
|
|
17
|
-
Numeric fields are converted using the relevant format to determine the width.
|
|
18
23
|
Usage:
|
|
19
24
|
|
|
20
25
|
%mp_getmaxvarlengths(sashelp.class,outds=work.myds)
|
|
21
26
|
|
|
22
|
-
@param libds Two part dataset (or view) reference.
|
|
23
|
-
@param
|
|
27
|
+
@param [in] libds Two part dataset (or view) reference.
|
|
28
|
+
@param [in] num2char= (NO) When set to NO, numeric fields are sized according
|
|
29
|
+
to the number of bytes used (or set to zero in the case of non-special
|
|
30
|
+
missings). When YES, the numeric field is converted to character (using the
|
|
31
|
+
format, if available), and that is sized instead, using `lengthn()`.
|
|
32
|
+
@param [out] outds= The output dataset to create, eg:
|
|
33
|
+
|NAME:$8.|MAXLEN:best.|
|
|
34
|
+
|---|---|
|
|
35
|
+
|`Name `|`7 `|
|
|
36
|
+
|`Sex `|`1 `|
|
|
37
|
+
|`Age `|`3 `|
|
|
38
|
+
|`Height `|`8 `|
|
|
39
|
+
|`Weight `|`3 `|
|
|
24
40
|
|
|
25
41
|
<h4> SAS Macros </h4>
|
|
42
|
+
@li mcf_length.sas
|
|
43
|
+
@li mf_getuniquename.sas
|
|
26
44
|
@li mf_getvarlist.sas
|
|
27
45
|
@li mf_getvartype.sas
|
|
28
46
|
@li mf_getvarformat.sas
|
|
@@ -30,20 +48,32 @@
|
|
|
30
48
|
@version 9.2
|
|
31
49
|
@author Allan Bowe
|
|
32
50
|
|
|
51
|
+
<h4> Related Macros </h4>
|
|
52
|
+
@li mp_ds2squeeze.sas
|
|
53
|
+
@li mp_getmaxvarlengths.test.sas
|
|
54
|
+
|
|
33
55
|
**/
|
|
34
56
|
|
|
35
57
|
%macro mp_getmaxvarlengths(
|
|
36
|
-
|
|
37
|
-
|
|
58
|
+
libds
|
|
59
|
+
,num2char=NO
|
|
60
|
+
,outds=work.mp_getmaxvarlengths
|
|
38
61
|
)/*/STORE SOURCE*/;
|
|
39
62
|
|
|
40
|
-
%local vars x var fmt;
|
|
63
|
+
%local vars prefix x var fmt;
|
|
41
64
|
%let vars=%mf_getvarlist(libds=&libds);
|
|
65
|
+
%let prefix=%substr(%mf_getuniquename(),1,25);
|
|
66
|
+
%let num2char=%upcase(&num2char);
|
|
67
|
+
|
|
68
|
+
%if &num2char=NO %then %do;
|
|
69
|
+
/* compile length function for numeric fields */
|
|
70
|
+
%mcf_length(wrap=YES, insert_cmplib=YES)
|
|
71
|
+
%end;
|
|
42
72
|
|
|
43
73
|
proc sql;
|
|
44
74
|
create table &outds (rename=(
|
|
45
75
|
%do x=1 %to %sysfunc(countw(&vars,%str( )));
|
|
46
|
-
|
|
76
|
+
&prefix.&x=%scan(&vars,&x)
|
|
47
77
|
%end;
|
|
48
78
|
))
|
|
49
79
|
as select
|
|
@@ -51,18 +81,21 @@ create table &outds (rename=(
|
|
|
51
81
|
%let var=%scan(&vars,&x);
|
|
52
82
|
%if &x>1 %then ,;
|
|
53
83
|
%if %mf_getvartype(&libds,&var)=C %then %do;
|
|
54
|
-
max(
|
|
84
|
+
max(lengthn(&var)) as &prefix.&x
|
|
55
85
|
%end;
|
|
56
|
-
%else %do;
|
|
86
|
+
%else %if &num2char=YES %then %do;
|
|
57
87
|
%let fmt=%mf_getvarformat(&libds,&var);
|
|
58
88
|
%put fmt=&fmt;
|
|
59
89
|
%if %str(&fmt)=%str() %then %do;
|
|
60
|
-
max(
|
|
90
|
+
max(lengthn(cats(&var))) as &prefix.&x
|
|
61
91
|
%end;
|
|
62
92
|
%else %do;
|
|
63
|
-
max(
|
|
93
|
+
max(lengthn(put(&var,&fmt))) as &prefix.&x
|
|
64
94
|
%end;
|
|
65
95
|
%end;
|
|
96
|
+
%else %do;
|
|
97
|
+
max(mcf_length(&var)) as &prefix.&x
|
|
98
|
+
%end;
|
|
66
99
|
%end;
|
|
67
100
|
from &libds;
|
|
68
101
|
|