@sasjs/core 6.1.1 → 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 (168) hide show
  1. package/.sasjslint +29 -3
  2. package/README.md +4 -2
  3. package/base/mf_dttmfmts.sas +1 -1
  4. package/base/mf_existds.sas +1 -1
  5. package/base/mf_existfeature.sas +1 -0
  6. package/base/mf_existfunction.sas +2 -1
  7. package/base/mf_existvar.sas +1 -1
  8. package/base/mf_existvarlist.sas +1 -1
  9. package/base/mf_getapploc.sas +1 -1
  10. package/base/mf_getattrc.sas +2 -1
  11. package/base/mf_getattrn.sas +2 -1
  12. package/base/mf_getengine.sas +2 -2
  13. package/base/mf_getfilesize.sas +1 -1
  14. package/base/mf_getfmtlist.sas +1 -1
  15. package/base/mf_getfmtname.sas +1 -1
  16. package/base/mf_getkeyvalue.sas +1 -1
  17. package/base/mf_getquotedstr.sas +1 -1
  18. package/base/mf_getschema.sas +1 -1
  19. package/base/mf_getuniquefileref.sas +2 -1
  20. package/base/mf_getuniquelibref.sas +1 -1
  21. package/base/mf_getuniquename.sas +1 -1
  22. package/base/mf_getvarcount.sas +1 -1
  23. package/base/mf_getvarformat.sas +1 -1
  24. package/base/mf_getvarlen.sas +1 -1
  25. package/base/mf_getvarlist.sas +1 -1
  26. package/base/mf_getvarnum.sas +1 -1
  27. package/base/mf_getvartype.sas +1 -1
  28. package/base/mf_isblank.sas +1 -1
  29. package/base/mf_isdir.sas +1 -1
  30. package/base/mf_islibds.sas +1 -1
  31. package/base/mf_mimetype.sas +2 -1
  32. package/base/mf_nobs.sas +1 -1
  33. package/base/mf_trimstr.sas +1 -1
  34. package/base/mf_uid.sas +1 -1
  35. package/base/mf_verifymacvars.sas +3 -3
  36. package/base/mf_wordsinstr1andstr2.sas +1 -1
  37. package/base/mf_writefile.sas +1 -1
  38. package/base/mp_abort.sas +3 -3
  39. package/base/mp_appendfile.sas +1 -1
  40. package/base/mp_applyformats.sas +3 -4
  41. package/base/mp_assert.sas +1 -1
  42. package/base/mp_assertcols.sas +1 -1
  43. package/base/mp_assertcolvals.sas +1 -1
  44. package/base/mp_assertdsobs.sas +1 -1
  45. package/base/mp_base64copy.sas +1 -1
  46. package/base/mp_cleancsv.sas +1 -1
  47. package/base/mp_cntlout.sas +1 -1
  48. package/base/mp_csv2ds.sas +1 -1
  49. package/base/mp_deleteconstraints.sas +1 -1
  50. package/base/mp_deletefolder.sas +1 -1
  51. package/base/mp_derivedvarcheck.sas +200 -0
  52. package/base/mp_derivedvars.sas +113 -62
  53. package/base/mp_dictionary.sas +1 -0
  54. package/base/mp_dirlist.sas +2 -3
  55. package/base/mp_distinctfmtvalues.sas +1 -1
  56. package/base/mp_dropmembers.sas +1 -1
  57. package/base/mp_ds2csv.sas +1 -1
  58. package/base/mp_ds2ddl.sas +3 -1
  59. package/base/mp_ds2fmtds.sas +1 -1
  60. package/base/mp_ds2inserts.sas +1 -1
  61. package/base/mp_ds2squeeze.sas +1 -1
  62. package/base/mp_dsmeta.sas +1 -0
  63. package/base/mp_filtercheck.sas +1 -0
  64. package/base/mp_filtergenerate.sas +1 -0
  65. package/base/mp_filterstore.sas +2 -1
  66. package/base/mp_filtervalidate.sas +1 -2
  67. package/base/mp_getcols.sas +2 -1
  68. package/base/mp_getconstraints.sas +2 -1
  69. package/base/mp_getdbml.sas +1 -1
  70. package/base/mp_getformats.sas +2 -1
  71. package/base/mp_getmaxvarlengths.sas +1 -1
  72. package/base/mp_getpk.sas +1 -0
  73. package/base/mp_gitlog.sas +1 -0
  74. package/base/mp_gitstatus.sas +1 -0
  75. package/base/mp_guesspk.sas +2 -1
  76. package/base/mp_include.sas +2 -1
  77. package/base/mp_lib2cards.sas +2 -1
  78. package/base/mp_lib2inserts.sas +1 -1
  79. package/base/mp_lockfilecheck.sas +1 -1
  80. package/base/mp_makedata.sas +1 -1
  81. package/base/mp_perflog.sas +1 -1
  82. package/base/mp_prevobs.sas +1 -1
  83. package/base/mp_reseterror.sas +1 -1
  84. package/base/mp_resetoption.sas +2 -1
  85. package/base/mp_runddl.sas +1 -1
  86. package/base/mp_searchcols.sas +1 -1
  87. package/base/mp_setkeyvalue.sas +1 -1
  88. package/base/mp_sortinplace.sas +1 -1
  89. package/base/mp_stackdiffs.sas +2 -1
  90. package/base/mp_storediffs.sas +1 -1
  91. package/base/mp_stprequests.sas +1 -1
  92. package/base/mp_stripdiffs.sas +1 -1
  93. package/base/mp_testjob.sas +1 -1
  94. package/base/mp_testwritespeedlibrary.sas +1 -1
  95. package/base/mp_tree.sas +2 -1
  96. package/base/mp_unzip.sas +1 -0
  97. package/base/mp_wait4file.sas +2 -1
  98. package/base/mp_webin.sas +1 -1
  99. package/base/mp_zip.sas +1 -1
  100. package/ddl/mddl_dc_difftable.sas +1 -1
  101. package/ddl/mddl_dc_filterdetail.sas +1 -1
  102. package/ddl/mddl_dc_filtersummary.sas +1 -1
  103. package/ddl/mddl_dc_locktable.sas +1 -1
  104. package/ddl/mddl_dc_maxkeytable.sas +1 -1
  105. package/fcmp/mcf_getfmttype.sas +1 -1
  106. package/fcmp/mcf_length.sas +1 -1
  107. package/fcmp/mcf_string2file.sas +2 -3
  108. package/lua/ml_json.sas +1 -0
  109. package/meta/mm_adduser2group.sas +1 -0
  110. package/meta/mm_assigndirectlib.sas +0 -1
  111. package/meta/mm_assignlib.sas +1 -0
  112. package/meta/mm_createapplication.sas +2 -4
  113. package/meta/mm_createdataset.sas +2 -1
  114. package/meta/mm_createdocument.sas +1 -1
  115. package/meta/mm_createfolder.sas +2 -1
  116. package/meta/mm_createstp.sas +1 -1
  117. package/meta/mm_createwebservice.sas +1 -0
  118. package/meta/mm_getauthinfo.sas +2 -1
  119. package/meta/mm_getcols.sas +1 -1
  120. package/meta/mm_getdetails.sas +1 -1
  121. package/meta/mm_getgroups.sas +1 -1
  122. package/meta/mm_getlibmetadiffs.sas +1 -0
  123. package/meta/mm_getlibs.sas +2 -3
  124. package/meta/mm_getobjects.sas +2 -3
  125. package/meta/mm_getpublictypes.sas +2 -1
  126. package/meta/mm_getrepos.sas +2 -3
  127. package/meta/mm_getroles.sas +1 -1
  128. package/meta/mm_getservercontexts.sas +2 -2
  129. package/meta/mm_getstpinfo.sas +1 -0
  130. package/meta/mm_gettableid.sas +1 -1
  131. package/meta/mm_gettables.sas +1 -1
  132. package/meta/mm_gettree.sas +1 -1
  133. package/meta/mm_gettypes.sas +2 -3
  134. package/meta/mm_getwebappsrvprops.sas +2 -2
  135. package/meta/mm_updateappextension.sas +1 -1
  136. package/meta/mm_updatedocument.sas +1 -1
  137. package/metax/mmx_deletemetafolder.sas +1 -0
  138. package/metax/mmx_spkexport.sas +1 -1
  139. package/package.json +1 -1
  140. package/server/ms_createwebservice.sas +1 -0
  141. package/server/ms_getfile.sas +1 -1
  142. package/server/ms_testservice.sas +2 -2
  143. package/server/ms_triggerstp.sas +2 -1
  144. package/viya/mfv_existfile.sas +1 -1
  145. package/viya/mfv_existfolder.sas +1 -1
  146. package/viya/mfv_getfolderpath.sas +1 -1
  147. package/viya/mfv_getpathuri.sas +1 -1
  148. package/viya/mv_createfile.sas +1 -1
  149. package/viya/mv_createfolder.sas +1 -1
  150. package/viya/mv_createjob.sas +1 -0
  151. package/viya/mv_createwebservice.sas +1 -0
  152. package/viya/mv_deletefoldermember.sas +2 -1
  153. package/viya/mv_deletejes.sas +2 -1
  154. package/viya/mv_getclients.sas +2 -1
  155. package/viya/mv_getfoldermembers.sas +2 -1
  156. package/viya/mv_getgroupmembers.sas +1 -1
  157. package/viya/mv_getjoblog.sas +4 -6
  158. package/viya/mv_getjobstate.sas +1 -0
  159. package/viya/mv_getusergroups.sas +1 -1
  160. package/viya/mv_getusers.sas +1 -1
  161. package/viya/mv_jobexecute.sas +1 -1
  162. package/viya/mv_jobflow.sas +1 -0
  163. package/viya/mv_jobwaitfor.sas +8 -8
  164. package/viya/mv_registerclient.sas +1 -0
  165. package/viya/mv_tokenauth.sas +1 -1
  166. package/viya/mv_tokenrefresh.sas +1 -1
  167. package/xplatform/mx_execute.sas +1 -0
  168. package/xplatform/mx_getgroups.sas +1 -1
@@ -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,6 +58,7 @@
60
58
  @li mp_dirlist.test.sas
61
59
 
62
60
  @version 9.2
61
+ @sasjslint {"maxLineLength": 128}
63
62
  **/
64
63
 
65
64
  %macro mp_dirlist(path=%sysfunc(pathname(work))
@@ -51,4 +51,4 @@
51
51
  %end;
52
52
  as &outvar length=&varlen
53
53
  from &libds;
54
- %mend mp_distinctfmtvalues;
54
+ %mend mp_distinctfmtvalues;
@@ -43,4 +43,4 @@
43
43
  delete &list;
44
44
  delete &list /mtype=view;
45
45
  run;
46
- %mend mp_dropmembers;
46
+ %mend mp_dropmembers;
@@ -218,4 +218,4 @@ data _null_;
218
218
  %end;
219
219
  run;
220
220
 
221
- %mend mp_ds2csv;
221
+ %mend mp_ds2csv;
@@ -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=
@@ -403,4 +405,4 @@ run;
403
405
  run;
404
406
  %end;
405
407
 
406
- %mend mp_ds2ddl;
408
+ %mend mp_ds2ddl;
@@ -102,4 +102,4 @@ data &outds;
102
102
  if _error_ then call symputx('syscc',1012);
103
103
  run;
104
104
 
105
- %mend mp_ds2fmtds;
105
+ %mend mp_ds2fmtds;
@@ -177,4 +177,4 @@ data _null_;
177
177
  if _n_=&nobs then put /;
178
178
  run;
179
179
 
180
- %mend mp_ds2inserts;
180
+ %mend mp_ds2inserts;
@@ -117,4 +117,4 @@ options varlenchk=&optval;
117
117
  %put &sysmacroname: &libds was &startsize;
118
118
  %put &sysmacroname: &outds is %mf_getfilesize(libds=&outds,format=yes);
119
119
 
120
- %mend mp_ds2squeeze;
120
+ %mend mp_ds2squeeze;
@@ -61,6 +61,7 @@
61
61
  @li mp_getpk.sas
62
62
  @li mp_guesspk.sas
63
63
 
64
+ @sasjslint {"maxLineLength": 95}
64
65
  **/
65
66
 
66
67
  %macro mp_dsmeta(libds,outds=work.dsmeta);
@@ -62,6 +62,7 @@
62
62
  @author Allan Bowe
63
63
 
64
64
  @todo Support hex / name literals and exponents in RAW_VALUE field
65
+ @sasjslint {"maxLineLength": 99}
65
66
  **/
66
67
 
67
68
  %macro mp_filtercheck(inds,targetds=,outds=work.badrecords,abort=YES);
@@ -65,6 +65,7 @@
65
65
  @version 9.3
66
66
  @author Allan Bowe
67
67
 
68
+ @sasjslint {"maxLineLength": 99}
68
69
  **/
69
70
 
70
71
  %macro mp_filtergenerate(inds,outref=filter);
@@ -76,6 +76,7 @@
76
76
  @version 9.2
77
77
  @author [Allan Bowe](https://www.linkedin.com/in/allanbowe)
78
78
 
79
+ @sasjslint {"maxLineLength": 167}
79
80
  **/
80
81
 
81
82
  %macro mp_filterstore(libds=,
@@ -265,4 +266,4 @@ run;
265
266
  ,msg=%str(syscc=&syscc on macro exit)
266
267
  )
267
268
 
268
- %mend mp_filterstore;
269
+ %mend mp_filterstore;
@@ -25,7 +25,6 @@
25
25
 
26
26
  %mp_filtervalidate(myfilter,sashelp.class)
27
27
 
28
-
29
28
  @returns The SYSCC value will be 1008 if there are validation issues.
30
29
 
31
30
  @param [in] inref The input fileref to validate (generated by
@@ -33,7 +32,7 @@
33
32
  @param [in] targetds The target dataset against which to verify the query
34
33
  @param [out] abort= (YES) If YES will call mp_abort.sas on any exceptions
35
34
  @param [out] outds= (work.mp_filtervalidate) Output dataset containing the
36
- err / warning message, if one exists. If this table contains any rows,
35
+ diagnostic message, if one exists. If this table contains any rows,
37
36
  there are problems!
38
37
 
39
38
  <h4> SAS Macros </h4>
@@ -32,6 +32,7 @@
32
32
  @version 9.2
33
33
  @author Allan Bowe
34
34
 
35
+ @sasjslint {"maxLineLength": 94}
35
36
  **/
36
37
 
37
38
  %macro mp_getcols(ds, outds=work.cols);
@@ -66,4 +67,4 @@ data &outds(keep=name type length varnum format label ddtype fmtname);
66
67
  run;
67
68
  proc sql;
68
69
  drop table &dropds;
69
- %mend mp_getcols;
70
+ %mend mp_getcols;
@@ -29,6 +29,7 @@
29
29
  @version 9.2
30
30
  @author Allan Bowe
31
31
 
32
+ @sasjslint {"maxLineLength": 123}
32
33
  **/
33
34
 
34
35
  %macro mp_getconstraints(lib=WORK
@@ -112,4 +113,4 @@ create table &outds as
112
113
  iftrue=(&mdebug=0)
113
114
  )
114
115
 
115
- %mend mp_getconstraints;
116
+ %mend mp_getconstraints;
@@ -332,4 +332,4 @@ run;
332
332
  run;
333
333
  %end;
334
334
 
335
- %mend mp_getdbml;
335
+ %mend mp_getdbml;
@@ -62,6 +62,7 @@ https://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#
62
62
  @version 9.2
63
63
  @author Allan Bowe
64
64
 
65
+ @sasjslint {"maxLineLength": 237}
65
66
  **/
66
67
 
67
68
  %macro mp_getformats(lib=0
@@ -131,4 +132,4 @@ create table &outsummary as
131
132
  %end;
132
133
  %end;
133
134
 
134
- %mend mp_getformats;
135
+ %mend mp_getformats;
@@ -127,4 +127,4 @@ create table &outds (rename=(
127
127
  out=&outds(rename=(_name_=NAME COL1=MAXLEN));
128
128
  run;
129
129
 
130
- %mend mp_getmaxvarlengths;
130
+ %mend mp_getmaxvarlengths;
package/base/mp_getpk.sas CHANGED
@@ -47,6 +47,7 @@
47
47
 
48
48
  @version 9.3
49
49
  @author Macro People Ltd
50
+ @sasjslint {"maxLineLength": 118}
50
51
  **/
51
52
 
52
53
  %macro mp_getpk(
@@ -49,6 +49,7 @@ https://documentation.sas.com/doc/ko/pgmsascdc/v_033/lefunctionsref/n1qo5miyvry1
49
49
  @li mp_gitreleaseinfo.sas
50
50
  @li mp_gitstatus.sas
51
51
 
52
+ @sasjslint {"maxLineLength": 100}
52
53
  **/
53
54
 
54
55
  %macro mp_gitlog(gitdir,outds=work.mp_gitlog,mdebug=0,filter=BRANCHONLY,nobs=0);