@sasjs/core 6.1.2 → 6.1.3

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.
Files changed (70) hide show
  1. package/.sasjslint +11 -4
  2. package/base/mf_existds.sas +1 -2
  3. package/base/mf_existfeature.sas +1 -0
  4. package/base/mf_existfunction.sas +1 -0
  5. package/base/mf_getattrc.sas +1 -0
  6. package/base/mf_getattrn.sas +1 -0
  7. package/base/mf_getengine.sas +1 -2
  8. package/base/mf_getschema.sas +1 -2
  9. package/base/mf_mimetype.sas +1 -0
  10. package/base/mf_verifymacvars.sas +3 -4
  11. package/base/mf_wordsinstr1andstr2.sas +1 -2
  12. package/base/mp_applyformats.sas +2 -4
  13. package/base/mp_derivedvarcheck.sas +200 -0
  14. package/base/mp_derivedvars.sas +113 -62
  15. package/base/mp_dictionary.sas +1 -0
  16. package/base/mp_dirlist.sas +2 -4
  17. package/base/mp_ds2ddl.sas +2 -0
  18. package/base/mp_dsmeta.sas +1 -0
  19. package/base/mp_filtercheck.sas +1 -0
  20. package/base/mp_filtergenerate.sas +1 -0
  21. package/base/mp_filterstore.sas +1 -0
  22. package/base/mp_filtervalidate.sas +1 -3
  23. package/base/mp_getcols.sas +1 -0
  24. package/base/mp_getconstraints.sas +1 -0
  25. package/base/mp_getformats.sas +1 -0
  26. package/base/mp_getpk.sas +1 -0
  27. package/base/mp_gitlog.sas +1 -0
  28. package/base/mp_gitstatus.sas +1 -0
  29. package/base/mp_guesspk.sas +1 -0
  30. package/base/mp_include.sas +1 -0
  31. package/base/mp_lib2cards.sas +1 -0
  32. package/base/mp_resetoption.sas +1 -0
  33. package/base/mp_stackdiffs.sas +1 -0
  34. package/base/mp_tree.sas +1 -0
  35. package/base/mp_unzip.sas +1 -0
  36. package/base/mp_wait4file.sas +1 -0
  37. package/fcmp/mcf_string2file.sas +1 -3
  38. package/lua/ml_json.sas +1 -0
  39. package/meta/mm_adduser2group.sas +1 -0
  40. package/meta/mm_createapplication.sas +1 -4
  41. package/meta/mm_createdataset.sas +1 -0
  42. package/meta/mm_createfolder.sas +1 -0
  43. package/meta/mm_createwebservice.sas +1 -0
  44. package/meta/mm_getauthinfo.sas +1 -0
  45. package/meta/mm_getlibmetadiffs.sas +1 -0
  46. package/meta/mm_getlibs.sas +1 -3
  47. package/meta/mm_getobjects.sas +1 -3
  48. package/meta/mm_getpublictypes.sas +1 -0
  49. package/meta/mm_getrepos.sas +1 -3
  50. package/meta/mm_getroles.sas +1 -2
  51. package/meta/mm_getservercontexts.sas +1 -2
  52. package/meta/mm_getstpinfo.sas +1 -0
  53. package/meta/mm_gettypes.sas +1 -3
  54. package/meta/mm_getwebappsrvprops.sas +1 -2
  55. package/metax/mmx_deletemetafolder.sas +1 -0
  56. package/package.json +1 -1
  57. package/server/ms_createwebservice.sas +1 -0
  58. package/server/ms_triggerstp.sas +1 -0
  59. package/viya/mv_createjob.sas +1 -0
  60. package/viya/mv_createwebservice.sas +1 -0
  61. package/viya/mv_deletefoldermember.sas +1 -0
  62. package/viya/mv_deletejes.sas +1 -0
  63. package/viya/mv_getclients.sas +1 -0
  64. package/viya/mv_getfoldermembers.sas +1 -0
  65. package/viya/mv_getjoblog.sas +4 -7
  66. package/viya/mv_getjobstate.sas +1 -0
  67. package/viya/mv_jobflow.sas +1 -0
  68. package/viya/mv_jobwaitfor.sas +2 -3
  69. package/viya/mv_registerclient.sas +1 -0
  70. package/xplatform/mx_execute.sas +1 -0
package/.sasjslint CHANGED
@@ -6,9 +6,9 @@
6
6
  "hasMacroParentheses": true,
7
7
  "lineEndings": "lf",
8
8
  "noGremlins": true,
9
- "noNestedMacros": false,
9
+ "noNestedMacros": true,
10
10
  "noSpacesInFileNames": true,
11
- "maxLineLength": 300,
11
+ "maxLineLength": 80,
12
12
  "lowerCaseFileNames": true,
13
13
  "noTabs": true,
14
14
  "indentationMultiple": 2,
@@ -29,6 +29,13 @@
29
29
  "noTrailingSpaces": "error",
30
30
  "noUndeclaredMacros": "error",
31
31
  "noUnusedMacros": "error",
32
- "strictMacroDefinition": "error"
33
- }
32
+ "strictMacroDefinition": "error",
33
+ "noBannedStrings": "error",
34
+ "noSingleAsteriskComments": "error",
35
+ "noUnusedLibnames": "error",
36
+ "hasRequiredMacroOptions": "error"
37
+ },
38
+ "ignoreList": [
39
+ "all.sas"
40
+ ]
34
41
  }
@@ -16,10 +16,9 @@
16
16
  <h4> Related Macros </h4>
17
17
  @li mf_existds.test.sas
18
18
 
19
- @warning Untested on tables registered in metadata but not physically present
19
+ @note Untested on tables registered in metadata but not physically present
20
20
  @version 9.2
21
21
  @author Allan Bowe
22
- @sasjslint {"noBannedStrings": false}
23
22
  **/
24
23
 
25
24
  %macro mf_existds(libds
@@ -18,6 +18,7 @@
18
18
 
19
19
  @version 8
20
20
  @author Allan Bowe
21
+ @sasjslint {"maxLineLength": 94}
21
22
  **/
22
23
  /** @cond */
23
24
  %macro mf_existfeature(feature
@@ -19,6 +19,7 @@ https://github.com/yabwon/SAS_PACKAGES/blob/main/packages/baseplus.md#functionex
19
19
  @param [in] name function name
20
20
 
21
21
  @author Allan Bowe
22
+ @sasjslint {"maxLineLength": 90}
22
23
  **/
23
24
  /** @cond */
24
25
  %macro mf_existfunction(name
@@ -14,6 +14,7 @@
14
14
 
15
15
  @version 9.2
16
16
  @author Allan Bowe
17
+ @sasjslint {"maxLineLength": 101}
17
18
  **/
18
19
 
19
20
  %macro mf_getattrc(
@@ -14,6 +14,7 @@
14
14
 
15
15
  @version 9.2
16
16
  @author Allan Bowe
17
+ @sasjslint {"maxLineLength": 98}
17
18
  **/
18
19
 
19
20
  %macro mf_getattrn(
@@ -17,7 +17,7 @@
17
17
  @return output returns the library engine (uppercase) for the FIRST library
18
18
  encountered.
19
19
 
20
- @warning will only return the FIRST library engine - for concatenated
20
+ @note will only return the FIRST library engine - for concatenated
21
21
  libraries, with different engines, inconsistent results may be encountered.
22
22
 
23
23
  @version 9.2
@@ -26,7 +26,6 @@
26
26
  <h4> Related Macros </h4>
27
27
  @li mf_getxengine.sas
28
28
 
29
- @sasjslint {"noBannedStrings": false}
30
29
  **/
31
30
  /** @cond */
32
31
 
@@ -12,13 +12,12 @@
12
12
 
13
13
  @return output returns the library schema for the FIRST library encountered
14
14
 
15
- @warning will only return the FIRST library schema - for concatenated
15
+ @note will only return the FIRST library schema - for concatenated
16
16
  libraries, with different schemas, inconsistent results may be encountered.
17
17
 
18
18
  @version 9.2
19
19
  @author Allan Bowe
20
20
  @cond
21
- @sasjslint {"noBannedStrings": false}
22
21
  **/
23
22
 
24
23
  %macro mf_getschema(libref
@@ -12,6 +12,7 @@
12
12
 
13
13
  @version 9.2
14
14
  @author Allan Bowe
15
+ @sasjslint {"maxLineLength": 82}
15
16
  **/
16
17
 
17
18
  %macro mf_mimetype(
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  @file
3
3
  @brief Checks if a set of macro variables exist AND contain values.
4
- @details Writes ERROR to log if abortType is SOFT, else will call %mf_abort.
4
+ @details Reports a failure in the log if abortType is SOFT, else calls
5
+ %mf_abort.
5
6
  Usage:
6
7
 
7
8
  %let var1=x;
@@ -22,7 +23,7 @@
22
23
  Set to any other value to call mf_abort (which can be configured to abort in
23
24
  various fashions according to context).
24
25
 
25
- @warning will not be able to verify the following variables due to
26
+ @note will not be able to verify the following variables due to
26
27
  naming clash!
27
28
  - verifyVars
28
29
  - verifyVar
@@ -32,10 +33,8 @@
32
33
  @version 9.2
33
34
  @author Allan Bowe
34
35
 
35
- @sasjslint {"noBannedStrings": false}
36
36
  **/
37
37
 
38
-
39
38
  %macro mf_verifymacvars(
40
39
  verifyVars /* list of macro variable NAMES */
41
40
  ,makeUpcase=NO /* set to YES to make all the variable VALUES uppercase */
@@ -19,12 +19,11 @@
19
19
  @param [in] str1= () string containing words to extract
20
20
  @param [in] str2= () used to compare with the extract string
21
21
 
22
- @warning CASE SENSITIVE!
22
+ @note CASE SENSITIVE!
23
23
 
24
24
  @version 9.2
25
25
  @author Allan Bowe
26
26
 
27
- @sasjslint {"noBannedStrings": false}
28
27
  **/
29
28
 
30
29
  %macro mf_wordsinstr1andstr2(
@@ -53,8 +53,8 @@
53
53
  |`WORK `|`EXAMPLE `|`YEAR `|`8. `|
54
54
 
55
55
  @param [out] errds= (0) Provide a libds reference here to export the
56
- error messages to a table. In this case, they will not be printed to the
57
- log.
56
+ diagnostic messages to a table. In this case, they will not be printed
57
+ to the log.
58
58
 
59
59
  <h4> SAS Macros </h4>
60
60
  @li mf_getengine.sas
@@ -63,14 +63,12 @@
63
63
  @li mf_nobs.sas
64
64
  @li mp_validatecol.sas
65
65
 
66
-
67
66
  <h4> Related Macros </h4>
68
67
  @li mp_getformats.sas
69
68
 
70
69
  @version 9.2
71
70
  @author Allan Bowe
72
71
 
73
- @sasjslint {"noBannedStrings": false}
74
72
  **/
75
73
 
76
74
  %macro mp_applyformats(inds,errds=0
@@ -0,0 +1,200 @@
1
+ /**
2
+ @file
3
+ @brief Validates derived variable definitions, one row per rule
4
+ @details Reads a table of derived variable definitions and writes one row per
5
+ definition that breaks a rule, with the reason in REASON. Nothing is
6
+ executed, no view is built and no target table is needed: the macro is a
7
+ scan of definitions, so it can run at submit time - or against any table of
8
+ expressions in a code scanning tool - long before the definitions are used.
9
+
10
+ The input is the shape a control table carries, which is the shape
11
+ mddl_derivedvars.sas creates:
12
+
13
+ @li VAR_NM - the name of the variable to create
14
+ @li VAR_TYPE - C or N
15
+ @li VAR_LEN - a positive integer, at most 32767 for character and 8 for
16
+ numeric
17
+ @li VAR_FMT - an optional format name
18
+ @li VAR_LOGIC - the expression, which must be a single expression with no
19
+ macro triggers and no comments, at most 4000 characters - the limit of the
20
+ statement buffer and of the control table, so a longer value would be cut
21
+ down silently
22
+ @li VAR_LABEL - optional, plain text of at most 256 characters. A line
23
+ break is allowed and becomes a space when the label is used
24
+
25
+ Extra columns are ignored, so a caller can scan the control table itself, a
26
+ staged submission, or a table of expressions assembled from a program.
27
+
28
+ <h4>Why a function name is refused and a character is not</h4>
29
+
30
+ VAR_LOGIC is concatenated into a generated assignment, so an expression that
31
+ can submit a program of its own (DOSUBL) or reach the file system, the
32
+ environment or the macro symbol table is a way into the session. Blocked
33
+ characters cannot cover that: BYTE(59) builds the semicolon at run time, so
34
+ a payload carries no blocked character in its source text - while the name of
35
+ the function it calls is part of the expression this scan reads, and cannot
36
+ be constructed. Quoted literals are removed before the check, so a refused
37
+ word that is only data is not read as a call.
38
+
39
+ The refused names are DOSUBL, JAVAOBJ, JAVAMETA, SYMGET, SYMPUT, SYMPUTX,
40
+ SYSGET, GETOPTION, PATHNAME, FILEEXIST, FOPEN, FREAD, FGET, FCLOSE, DOPEN,
41
+ DREAD, DNUM, MOPEN, SLEEP, FILENAME, FDELETE, FCOPY, DCREATE and DLCREATE.
42
+ Add your own with denyfuncs=.
43
+
44
+ <h4> SAS Macros </h4>
45
+ @li mf_existds.sas
46
+ @li mf_existvar.sas
47
+ @li mp_abort.sas
48
+
49
+ <h4> Related Macros </h4>
50
+ @li mp_derivedvars.sas
51
+ @li mddl_derivedvars.sas
52
+
53
+ @param [in] inds= The definitions to check
54
+ @param [out] outds= (work.dv_check) One row per definition that breaks a
55
+ rule: NAME (the upcased VAR_NM) and REASON. Empty when every row is valid
56
+ @param [in] physlist= (0) Space separated list of the columns of the target
57
+ table, unquoted and case insensitive - what %mf_getvarlist(&libds) returns.
58
+ Supplied, a VAR_NM that collides with one of them is refused; when the
59
+ target is not at hand, leave it at 0 and that rule is not applied
60
+ @param [in] reserved= (0) Space separated list of names that may not be used
61
+ @param [in] denyfuncs= (0) Space separated list of further function names
62
+ to refuse, for a site that allows more of the SAS vocabulary than the
63
+ default. Each entry must be a function name - letters, digits and
64
+ underscores - so the pattern the check builds stays a pattern of names
65
+
66
+ @version 1.0
67
+ @author 4GL Apps Ltd
68
+
69
+ **/
70
+
71
+ %macro mp_derivedvarcheck(inds=,
72
+ outds=work.dv_check,
73
+ physlist=0,
74
+ reserved=0,
75
+ denyfuncs=0
76
+ );
77
+
78
+ %local deny denycnt physcnt resv_list phys_list i w bad_deny denyrx w_ok;
79
+
80
+ %mp_abort(iftrue= (%length(&inds)=0)
81
+ ,mac=&sysmacroname
82
+ ,msg=%str(Please provide the definitions to check in inds)
83
+ )
84
+ %mp_abort(iftrue= (%mf_existds(libds=&inds) ne 1)
85
+ ,mac=&sysmacroname
86
+ ,msg=%str(Definitions not found: &inds)
87
+ )
88
+
89
+ /* the capabilities that are refused - a function name cannot be assembled at
90
+ run time, so naming them is a control the expression cannot evade. The
91
+ file system is covered in both directions: the read vocabulary (FOPEN,
92
+ FREAD, FGET, FCLOSE) and the write, copy and delete vocabulary
93
+ (FILENAME, FDELETE, FCOPY, DCREATE, DLCREATE) */
94
+ %let deny=DOSUBL|JAVAOBJ|JAVAMETA|SYMGET|SYMPUTX?|SYSGET|GETOPTION;
95
+ %let deny=&deny.|PATHNAME|FILEEXIST|FOPEN|FREAD|FGET|FCLOSE;
96
+ %let deny=&deny.|DOPEN|DREAD|DNUM|MOPEN|SLEEP;
97
+ %let deny=&deny.|FILENAME|FDELETE|FCOPY|DCREATE|DLCREATE;
98
+ %let bad_deny=0;
99
+ /* a token has to be a function name: a pattern metacharacter here would make
100
+ the PRXMATCH below fail, and a failed match passes every row */
101
+ %let denyrx=%str(/^[A-Z][A-Z0-9_]*$/);
102
+ %let denycnt=%sysfunc(countw(&denyfuncs,%str( )));
103
+ %if "%upcase(&denyfuncs)" ne "0" %then %do i=1 %to &denycnt;
104
+ %let w=%upcase(%scan(&denyfuncs,&i,%str( )));
105
+ %let w_ok=%sysfunc(prxmatch(&denyrx,&w));
106
+ %if &w_ok=0 %then %let bad_deny=1;
107
+ %else %let deny=&deny.|&w;
108
+ %end;
109
+ %mp_abort(iftrue= (&bad_deny=1)
110
+ ,mac=&sysmacroname
111
+ ,msg=%str(denyfuncs must be a space separated list of function names)
112
+ )
113
+
114
+ /* the target columns, as a quoted list - supplied only when the caller has the
115
+ table to hand */
116
+ %let phys_list=;
117
+ %let physcnt=%sysfunc(countw(&physlist,%str( )));
118
+ %if %length(&physlist)>0 and "%upcase(&physlist)" ne "0"
119
+ %then %do i=1 %to &physcnt;
120
+ %let w=%scan(&physlist,&i,%str( ));
121
+ %let phys_list=&phys_list.%str(,)%str(%")%upcase(&w)%str(%");
122
+ %end;
123
+ %if %length(&phys_list)>0 %then %let phys_list=%substr(&phys_list,2);
124
+
125
+ /* build a quoted list of reserved names, or an empty list */
126
+ %let resv_list=;
127
+ %if "&reserved" ne "0" %then %do i=1 %to %sysfunc(countw(&reserved,%str( )));
128
+ %let w=%scan(&reserved,&i,%str( ));
129
+ %let resv_list=&resv_list.%str(,)%str(%")%upcase(&w)%str(%");
130
+ %end;
131
+ %if %length(&resv_list)>0 %then %let resv_list=%substr(&resv_list,2);
132
+
133
+ data &outds(keep=name reason);
134
+ set &inds;
135
+ length name $32 reason $200 l $4000;
136
+ call missing(reason);
137
+ name=upcase(strip(var_nm));
138
+
139
+ /* quoted literals are data, not calls - strip them before the vocabulary
140
+ check so a label or a value that names a refused function is allowed */
141
+ l=prxchange("s/'([^']|'')*'//",-1,var_logic);
142
+ l=prxchange('s/\"([^\"]|\"\")*\"//',-1,l);
143
+
144
+ if name='' then reason='VAR_NM is required';
145
+ else if verify(strip(name),'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_')>0
146
+ then reason='VAR_NM must be a valid SAS name';
147
+ else if verify(substr(name,1,1),'0123456789')=0
148
+ then reason='VAR_NM must not start with a digit';
149
+ else if name in ('_N_','_ERROR_','_IORC_')
150
+ then reason='VAR_NM is an automatic variable of the data step';
151
+ %if %length(&phys_list)>0 %then %do;
152
+ else if name in (%unquote(&phys_list))
153
+ then reason='VAR_NM collides with a column in the target table';
154
+ %end;
155
+ %if %length(&resv_list)>0 %then %do;
156
+ else if name in (%unquote(&resv_list))
157
+ then reason='VAR_NM is reserved';
158
+ %end;
159
+ else if upcase(strip(var_type)) not in ('C','N')
160
+ then reason='VAR_TYPE must be C or N';
161
+ else if missing(var_len) or var_len ne int(var_len) or var_len<1
162
+ then reason='VAR_LEN must be a positive integer';
163
+ else if upcase(strip(var_type))='C' and var_len>32767
164
+ then reason='VAR_LEN exceeds 32767 for a character variable';
165
+ else if upcase(strip(var_type))='N' and var_len>8
166
+ then reason='VAR_LEN exceeds 8 for a numeric variable';
167
+ else if index(var_fmt,';')>0 or indexc(var_fmt,'&%')>0
168
+ or index(var_fmt,'/*')>0 or index(var_fmt,'*/')>0
169
+ then reason='VAR_FMT must be a format name, without ; & % or /* */';
170
+ else if verify(strip(upcase(var_fmt))
171
+ ,'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$.')>0
172
+ then reason='VAR_FMT must be a format name';
173
+ %if %mf_existvar(&inds,VAR_LABEL) gt 0 %then %do;
174
+ /* VAR_LABEL is free text - any script, any character - because the quotes
175
+ in it are escaped when the attrib statement is built. A line break is
176
+ flattened to a space, which is what a label has always become, so only
177
+ the remaining control characters are refused */
178
+ else if anycntrl(translate(var_label,' ','0D0A'x))>0
179
+ then reason='VAR_LABEL must be plain text - no control characters';
180
+ else if klength(var_label)>256
181
+ then reason='VAR_LABEL exceeds 256 characters';
182
+ %end;
183
+ else if missing(var_logic)
184
+ then reason='VAR_LOGIC is required';
185
+ else if klength(var_logic)>4000
186
+ then reason='VAR_LOGIC exceeds 4000 characters';
187
+ else if index(var_logic,';')>0
188
+ then reason='VAR_LOGIC must be a single expression - remove the ;';
189
+ else if indexc(var_logic,'&%')>0
190
+ then reason='VAR_LOGIC must not contain macro triggers';
191
+ else if index(var_logic,'/*')>0 or index(var_logic,'*/')>0
192
+ then reason='VAR_LOGIC must not contain comments';
193
+ else if prxmatch("/\b(&deny)\s*\(/",upcase(l))>0
194
+ then reason='VAR_LOGIC may not call a function that submits code or'
195
+ ||' reaches the file system, the environment or the macro symbol table';
196
+
197
+ if missing(reason)=0 then output;
198
+ run;
199
+
200
+ %mend mp_derivedvarcheck;
@@ -40,7 +40,14 @@
40
40
  is referenced must be declared, a declared name that is not referenced is an
41
41
  error, and a declared name must be a column of the target table or a derived
42
42
  variable defined for it. Semicolons, macro triggers and comments are
43
- rejected, so a row can only ever be an expression. A derived variable may
43
+ rejected, so a row can only ever be an expression.
44
+
45
+ The field level rules are not here - they are in mp_derivedvarcheck, which
46
+ reads the same control table and writes one row per definition that breaks
47
+ one. This macro adds the two checks that need the target table, and the
48
+ dependency graph, then generates the statements.
49
+
50
+ A derived variable may
44
51
  not reuse the name of a physical column, and may not reference itself: an
45
52
  intra-row calculation would imply a retained value, which depends on the
46
53
  order rows happen to arrive in.
@@ -65,6 +72,7 @@
65
72
  @li mf_getvarlist.sas
66
73
  @li mf_nobs.sas
67
74
  @li mp_abort.sas
75
+ @li mp_derivedvarcheck.sas
68
76
 
69
77
  <h4> Related Macros </h4>
70
78
  @li mddl_derivedvars.sas
@@ -76,8 +84,17 @@
76
84
  @param [out] outvars= (work.derived_varlist) Dataset of derived variable names
77
85
  @param [in] outview= (0) Optional two-level name for the derived view
78
86
  @param [in] reserved= (0) Space separated list of names that may not be used
79
-
80
- @version 5.6
87
+ @param [in] abort= (YES) Set to NO to return the validation failures in
88
+ errds= instead of aborting - for tests, and for a caller that wants to
89
+ report every failure rather than the first. No statement is generated
90
+ when any row is returned
91
+ @param [out] errds= (work.dv_errors) The validation failures when abort=NO:
92
+ one row per offending VAR_NM per rule broken, so a definition that breaks
93
+ two rules appears twice, with the rule in REASON. Empty, not absent, when
94
+ the configuration is valid. The cycle in VAR_DEPS is reported as a single
95
+ row, because one member identifies the cycle
96
+
97
+ @version 5.7
81
98
  @author 4GL Apps Ltd
82
99
 
83
100
  **/
@@ -88,13 +105,15 @@
88
105
  outref=0,
89
106
  outvars=work.derived_varlist,
90
107
  outview=0,
91
- reserved=0
108
+ reserved=0,
109
+ abort=YES,
110
+ errds=work.dv_errors
92
111
  );
93
112
 
94
- %local physlist derived_err resv_list i w left nready nplaced
113
+ %local physlist phys_sp derived_err left nready nplaced
95
114
  cyc_start cyc_cur cyc_next cyc_path cyc_seen cyc_i
96
115
  ds_cfg ds_byname ds_bad ds_baddep ds_dup ds_dep ds_ref ds_stale
97
- ds_undecl ds_self ds_edge ds_todo ds_ready ds_placed ds_srt;
116
+ ds_undecl ds_self ds_edge ds_todo ds_ready ds_placed ds_srt ds_errpart;
98
117
 
99
118
  /* every working table gets its own name, so a caller with tables of the same
100
119
  name in WORK cannot collide with this macro's intermediates */
@@ -113,6 +132,7 @@
113
132
  %let ds_ready=%mf_getuniquename(prefix=dvrdy);
114
133
  %let ds_placed=%mf_getuniquename(prefix=dvpld);
115
134
  %let ds_srt=%mf_getuniquename(prefix=dvsrt);
135
+ %let ds_errpart=%mf_getuniquename(prefix=dverr);
116
136
 
117
137
  %mp_abort(iftrue= (%length(&libds)=0 or %length(&control)=0)
118
138
  ,mac=&sysmacroname
@@ -141,6 +161,15 @@ data &outvars(keep=name);
141
161
  if 0;
142
162
  run;
143
163
 
164
+ /* the failures dataset exists even when the configuration is valid, so a
165
+ caller can test it without checking for existence first */
166
+ data &errds(keep=name reason);
167
+ length name $32 reason $200;
168
+ name='';
169
+ reason='';
170
+ if 0;
171
+ run;
172
+
144
173
  %if %mf_existds(libds=&control) ne 1 %then %do;
145
174
  %put &sysmacroname: &control not found - no derived variables;
146
175
  %return;
@@ -179,64 +208,23 @@ proc sort data=work.&ds_cfg. out=work.&ds_byname.;
179
208
  by name;
180
209
  run;
181
210
 
211
+ /* the columns of the target, twice - as an in-list for the SQL below, and as
212
+ the space separated form mp_derivedvarcheck takes */
182
213
  %let physlist=%upcase(%mf_getvarlist(&libds,dlm=%str(,),quote=SINGLE));
214
+ %let phys_sp=%upcase(%mf_getvarlist(&libds));
215
+
216
+ /* the field level rules live in mp_derivedvarcheck, so the same scan can be
217
+ run before a definition is ever used - at submit time, or over a table of
218
+ expressions in a code scanning tool. The engine supplies what only it can
219
+ know: the columns of the target table, which is what the collision and the
220
+ dependency checks are compared against. */
221
+ %mp_derivedvarcheck(inds=work.&ds_byname.
222
+ ,outds=work.&ds_bad.
223
+ ,physlist=&phys_sp
224
+ ,reserved=&reserved
225
+ )
183
226
 
184
- /* build a quoted list of reserved names, or an empty list */
185
- %let resv_list=;
186
- %if "&reserved" ne "0" %then %do i=1 %to %sysfunc(countw(&reserved,%str( )));
187
- %let w=%scan(&reserved,&i,%str( ));
188
- %let resv_list=&resv_list.%str(,)%str(%")%upcase(&w)%str(%");
189
- %end;
190
- %if %length(&resv_list)>0 %then %let resv_list=%substr(&resv_list,2);
191
-
192
- /**
193
- * Reject anything that could break the generated data step, or that would
194
- * produce a variable we cannot describe to the caller
195
- */
196
- data work.&ds_bad.;
197
- set work.&ds_byname.;
198
- length reason $200;
199
- call missing(reason);
200
-
201
- if name='' then reason='VAR_NM is required';
202
- else if verify(strip(name),'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_')>0
203
- then reason='VAR_NM must be a valid SAS name';
204
- else if verify(substr(name,1,1),'0123456789')=0
205
- then reason='VAR_NM must not start with a digit';
206
- %if %length(&physlist)>0 %then %do;
207
- else if name in (%unquote(&physlist))
208
- then reason='VAR_NM collides with a column in the target table';
209
- %end;
210
- %if %length(&resv_list)>0 %then %do;
211
- else if name in (%unquote(&resv_list))
212
- then reason='VAR_NM is reserved';
213
- %end;
214
- else if type not in ('C','N')
215
- then reason='VAR_TYPE must be C or N';
216
- else if missing(len) or len ne int(len) or len<1
217
- then reason='VAR_LEN must be a positive integer';
218
- else if type='C' and len>32767
219
- then reason='VAR_LEN exceeds 32767 for a character variable';
220
- else if type='N' and len>8
221
- then reason='VAR_LEN exceeds 8 for a numeric variable';
222
- else if index(fmt,';')>0 or indexc(fmt,'&%')>0
223
- or index(fmt,'/*')>0 or index(fmt,'*/')>0
224
- then reason='VAR_FMT must be a format name, without ; & % or //*';
225
- else if verify(strip(fmt),'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$.')>0
226
- then reason='VAR_FMT must be a format name';
227
- else if missing(logic)
228
- then reason='VAR_LOGIC is required';
229
- else if index(logic,';')>0
230
- then reason='VAR_LOGIC must be a single expression - remove the ;';
231
- else if indexc(logic,'&%')>0
232
- then reason='VAR_LOGIC must not contain macro triggers';
233
- else if index(logic,'/*')>0 or index(logic,'*/')>0
234
- then reason='VAR_LOGIC must not contain comments';
235
-
236
- if missing(reason)=0 then output;
237
- run;
238
-
239
- data work.&ds_dup.;
227
+ data work.&ds_dup.(keep=name reason);
240
228
  set work.&ds_byname.;
241
229
  by name;
242
230
  length reason $200;
@@ -318,6 +306,59 @@ create table work.&ds_self. as
318
306
  where name=dep_nm;
319
307
  quit;
320
308
 
309
+ /* abort=NO reports every failure rather than the first: one row per offending
310
+ definition per rule broken. Every rule has been evaluated by this point, so
311
+ the whole set is assembled here and nothing is generated while it is not
312
+ empty - the dependency graph below only runs on a configuration whose edges
313
+ resolve */
314
+ %if "%upcase(&abort)"="NO" %then %do;
315
+ data work.&ds_errpart.;
316
+ set work.&ds_baddep.;
317
+ length reason $200;
318
+ reason=cats('VAR_DEPS lists ',dep_nm
319
+ ,', which is not a column of the table or a derived variable');
320
+ keep name reason;
321
+ run;
322
+ proc append base=&errds data=work.&ds_errpart. force;
323
+ run;
324
+
325
+ data work.&ds_errpart.;
326
+ set work.&ds_self.;
327
+ length reason $200;
328
+ reason='VAR_DEPS may not list itself';
329
+ keep name reason;
330
+ run;
331
+ proc append base=&errds data=work.&ds_errpart. force;
332
+ run;
333
+
334
+ data work.&ds_errpart.;
335
+ set work.&ds_undecl.;
336
+ length reason $200;
337
+ reason=cats('VAR_LOGIC references ',dep_nm,', which is not in VAR_DEPS');
338
+ keep name reason;
339
+ run;
340
+ proc append base=&errds data=work.&ds_errpart. force;
341
+ run;
342
+
343
+ data work.&ds_errpart.;
344
+ set work.&ds_stale.;
345
+ length reason $200;
346
+ reason=cats('VAR_DEPS lists ',dep_nm,', which VAR_LOGIC does not'
347
+ ,' reference');
348
+ keep name reason;
349
+ run;
350
+ proc append base=&errds data=work.&ds_errpart. force;
351
+ run;
352
+
353
+ data work.&ds_errpart.(keep=name reason);
354
+ set work.&ds_bad.;
355
+ run;
356
+ proc append base=&errds data=work.&ds_errpart. force;
357
+ run;
358
+ %end;
359
+
360
+ %if "%upcase(&abort)"="NO" and %mf_nobs(&errds)>0 %then %return;
361
+
321
362
  data _null_;
322
363
  set work.&ds_baddep.(obs=1);
323
364
  call symputx('derived_err'
@@ -473,6 +514,16 @@ run;
473
514
  %end;
474
515
  %end;
475
516
 
517
+ %if "%upcase(&abort)"="NO" and &cyc_found=1 %then %do;
518
+ data &errds;
519
+ length name $32 reason $200;
520
+ name="&cyc_start";
521
+ reason='VAR_DEPS contains a cycle';
522
+ keep name reason;
523
+ run;
524
+ %return;
525
+ %end;
526
+
476
527
  %mp_abort(iftrue= (&cyc_found=1)
477
528
  ,mac=&sysmacroname
478
529
  ,msg=%str(VAR_DEPS contains a cycle: &cyc_path)
@@ -37,6 +37,7 @@
37
37
  @version 9.2
38
38
  @author Allan Bowe
39
39
 
40
+ @sasjslint {"maxLineLength": 107}
40
41
  **/
41
42
 
42
43
  %macro mp_dictionary(lib=WORK)/*/STORE SOURCE*/;
@@ -14,14 +14,13 @@
14
14
 
15
15
  %mp_dirlist(fref=MYFREF)
16
16
 
17
- @warning In a Unix environment, the existence of a named pipe will cause this
17
+ @note In a Unix environment, the existence of a named pipe will cause this
18
18
  macro to hang. Therefore this tool should be used with caution in a SAS 9 web
19
19
  application, as it can use up all available multibridge sessions if requests
20
20
  are resubmitted.
21
21
  If anyone finds a way to positively identify a named pipe using SAS (without
22
22
  X CMD) do please raise an issue!
23
23
 
24
-
25
24
  @param [in] path= (%sysfunc(pathname(work))) Path for which to return contents
26
25
  @param [in] fref= (0) Provide a DISK engine fileref as an alternative to PATH
27
26
  @param [in] maxdepth= (0) Set to a positive integer to indicate the level of
@@ -39,7 +38,6 @@
39
38
  files/folders cannot be accessed, and so not all properties can / will be
40
39
  populated.
41
40
 
42
-
43
41
  @returns outds contains the following variables:
44
42
  - directory (containing folder)
45
43
  - file_or_folder (file / folder)
@@ -60,7 +58,7 @@
60
58
  @li mp_dirlist.test.sas
61
59
 
62
60
  @version 9.2
63
- @sasjslint {"noBannedStrings": false}
61
+ @sasjslint {"maxLineLength": 128}
64
62
  **/
65
63
 
66
64
  %macro mp_dirlist(path=%sysfunc(pathname(work))
@@ -40,6 +40,8 @@
40
40
 
41
41
  @version 9.3
42
42
  @author Allan Bowe
43
+ @sasjslint {"noNestedMacros": false}
44
+
43
45
  **/
44
46
 
45
47
  %macro mp_ds2ddl(libref,ds,fref=getddl,flavour=SAS,showlog=YES,schema=