@sasjs/core 4.11.0 → 4.13.1

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 CHANGED
@@ -47,7 +47,7 @@ Documentation: https://core.sasjs.io
47
47
 
48
48
  This library will not be used for storing data entries (such as formats or datalines). Where this becomes necessary in the future, a new repo will be created, in order to keep the NPM bundle size down (for the benefit of those looking to embed purely macros in their applications).
49
49
 
50
- #### FCMP library (All Platforms)
50
+ ### FCMP library (All Platforms)
51
51
 
52
52
  - Function and macro names are identical, except for special cases
53
53
  - Prefixes: _mcf_
@@ -204,6 +204,7 @@ When contributing to this library, it is therefore important to ensure that all
204
204
 
205
205
  We are currently on major release v4. Breaking changes should be marked with the [deprecated](https://www.doxygen.nl/manual/commands.html#cmddeprecated) doxygen tag. The following changes are planned when the next major/breaking release (v5) becomes necessary:
206
206
 
207
+ * mf_getuniquelibref.sas to have the deprecated maxtried parameter removed (no longer needed)
207
208
  * mp_testservice.sas to be renamed as mp_execute.sas (as it doesn't actually test anything)
208
209
  * `insert_cmplib` option of mcf_xxx macros will be deprecated (the option is now checked automatically with value inserted only if needed)
209
210
  * mcf_xxx macros to have `wrap=` option defaulted to YES for convenience. Set this option explicitly to avoid issues.
@@ -217,10 +218,9 @@ If you find this library useful, please leave a [star](https://github.com/sasjs/
217
218
  ![](https://starchart.cc/sasjs/core.svg)
218
219
 
219
220
 
220
-
221
221
  ## Contributors ✨
222
222
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
223
- [![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors-)
223
+ [![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors-)
224
224
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
225
225
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
226
226
 
@@ -241,6 +241,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
241
241
  <td align="center"><a href="https://github.com/kkchandok"><img src="https://avatars.githubusercontent.com/u/46090627?v=4?s=100" width="100px;" alt=""/><br /><sub><b>kkchandok</b></sub></a><br /><a href="#ideas-kkchandok" title="Ideas, Planning, & Feedback">🤔</a></td>
242
242
  <td align="center"><a href="https://github.com/VladislavParhomchik"><img src="https://avatars.githubusercontent.com/u/83717836?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vladislav Parhomchik</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=VladislavParhomchik" title="Tests">⚠️</a> <a href="https://github.com/sasjs/core/pulls?q=is%3Apr+reviewed-by%3AVladislavParhomchik" title="Reviewed Pull Requests">👀</a></td>
243
243
  <td align="center"><a href="https://github.com/vznesh"><img src="https://avatars.githubusercontent.com/u/28916792?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vignesh T.</b></sub></a><br /><a href="https://github.com/sasjs/core/issues?q=author%3Avznesh" title="Bug reports">🐛</a></td>
244
+ <td align="center"><a href="https://github.com/yabwon"><img src="https://avatars.githubusercontent.com/u/9314894?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bart Jablonski</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=yabwon" title="Code">💻</a></td>
244
245
  </tr>
245
246
  </table>
246
247
 
@@ -14,27 +14,44 @@
14
14
 
15
15
  > mclib3
16
16
 
17
- @param prefix= first part of libref. Remember that librefs can only be 8 characters,
18
- so a 7 letter prefix would mean that maxtries should be 10.
19
- @param maxtries= the last part of the libref. Provide an integer value.
17
+ A blank value is returned if no usable libname is determined.
18
+
19
+ @param [in] prefix= (mclib) first part of the returned libref. As librefs can
20
+ be as long as 8 characters, a maximum length of 7 characters is premitted
21
+ for this prefix.
22
+ @param [in] maxtries= Deprecated parameter. Remains here to ensure a
23
+ non-breaking change. Will be removed in v5.
20
24
 
21
25
  @version 9.2
22
26
  @author Allan Bowe
23
27
  **/
24
28
 
25
-
26
29
  %macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
27
- %local x libref;
28
- %let x=0;
29
- %do x=0 %to &maxtries;
30
- %if %sysfunc(libref(&prefix&x)) ne 0 %then %do;
31
- %let libref=&prefix&x;
32
- %let rc=%sysfunc(libname(&libref,%sysfunc(pathname(work))));
33
- %if &rc %then %put %sysfunc(sysmsg());
34
- &prefix&x
35
- %*put &sysmacroname: Libref &libref assigned as WORK and returned;
30
+ %local x;
31
+
32
+ %if ( %length(&prefix) gt 7 ) %then %do;
33
+ %put %str(ERR)OR: The prefix parameter cannot exceed 7 characters.;
34
+ 0
35
+ %return;
36
+ %end;
37
+ %else %if (%sysfunc(NVALID(&prefix,v7))=0) %then %do;
38
+ %put %str(ERR)OR: Invalid prefix (&prefix);
39
+ 0
36
40
  %return;
37
41
  %end;
42
+
43
+ /* Set maxtries equal to '10 to the power of [# unused characters] - 1' */
44
+ %let maxtries=%eval(10**(8-%length(&prefix))-1);
45
+
46
+ %do x = 0 %to &maxtries;
47
+ %if %sysfunc(libref(&prefix&x)) ne 0 %then %do;
48
+ &prefix&x
49
+ %return;
50
+ %end;
51
+ %let x = %eval(&x + 1);
38
52
  %end;
39
- %put unable to find available libref in range &prefix.0-&maxtries;
53
+
54
+ %put %str(ERR)OR: No usable libref in range &prefix.0-&maxtries;
55
+ %put %str(ERR)OR- Try reducing the prefix or deleting some libraries!;
56
+ 0
40
57
  %mend mf_getuniquelibref;
@@ -74,7 +74,8 @@
74
74
  outds=work.test_results
75
75
  )/*/STORE SOURCE*/;
76
76
  %local ds test_result test_comments del add mod ilist;
77
- %let ilist=%upcase(&sasjs_prefix._FUNCTIONS &ignorelist);
77
+ %let ilist=%upcase(&sasjs_prefix._FUNCTIONS SYS_PROCHTTP_STATUS_CODE
78
+ SYS_PROCHTTP_STATUS_CODE SYS_PROCHTTP_STATUS_PHRASE &ignorelist);
78
79
 
79
80
  /**
80
81
  * this sets up the global vars, it will also enter STRICT mode. If this
@@ -89,7 +90,7 @@
89
90
  create table &scopeds as
90
91
  select name,offset,value
91
92
  from dictionary.macros
92
- where scope="&scope" and name not in (%mf_getquotedstr(&ilist))
93
+ where scope="&scope" and upcase(name) not in (%mf_getquotedstr(&ilist))
93
94
  order by name,offset;
94
95
  %end;
95
96
  %else %if &action=COMPARE %then %do;
@@ -103,7 +104,9 @@
103
104
 
104
105
  %let ds=&syslast;
105
106
 
106
- proc compare base=&scopeds compare=&ds;
107
+ proc compare
108
+ base=&scopeds(where=(upcase(name) not in (%mf_getquotedstr(&ilist))))
109
+ compare=&ds;
107
110
  run;
108
111
 
109
112
  %if &sysinfo=0 %then %do;
@@ -141,4 +144,4 @@
141
144
  drop table &ds;
142
145
  %end;
143
146
 
144
- %mend mp_assertscope;
147
+ %mend mp_assertscope;
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  @file
3
3
  @brief Mechanism for locking tables to prevent parallel modifications
4
- @details Uses a control table to enable ANY table to be locked for updates.
4
+ @details Uses a control table to enable ANY table to be locked for updates
5
+ (not just SAS datasets).
5
6
  Only useful if every update uses the macro! Used heavily within
6
7
  [Data Controller for SAS](https://datacontroller.io).
7
8
 
@@ -15,7 +16,7 @@
15
16
  length is 200 characters.
16
17
  @param [out] ctl_ds= (0) The control table which controls the actual locking.
17
18
  Should already be assigned and available. The definition is available by
18
- running mp_coretable.sas as follows: `%mp_coretable(LOCKTABLE)`.
19
+ running the mddl_dc_locktable.sas macro.
19
20
 
20
21
  @param [in] loops= (25) Number of times to check for a lock.
21
22
  @param [in] loop_secs= (1) Seconds to wait between each lock attempt
@@ -0,0 +1,149 @@
1
+ /**
2
+ @file
3
+ @brief Performs a text substitution on a file
4
+ @details Performs a find and replace on a file, either in place or to a new
5
+ file. Can be used on files where lines are longer than 32767.
6
+
7
+ Works by reading in the file byte by byte, then marking the beginning and end
8
+ of each matched string, before finally doing the replace.
9
+
10
+ Full credit for this highly efficient and syntactically satisfying SAS logic
11
+ goes to [Bartosz Jabłoński](https://www.linkedin.com/in/yabwon), founder of
12
+ the [SAS Packages](https://github.com/yabwon/SAS_PACKAGES) framework.
13
+
14
+ Usage:
15
+
16
+ %let file="%sysfunc(pathname(work))/file.txt";
17
+ %let str=replace/me;
18
+ %let rep=with/this;
19
+ data _null_;
20
+ file &file;
21
+ put 'blahblah';
22
+ put "blahblah&str.blah";
23
+ put 'blahblahblah';
24
+ run;
25
+ %mp_replace(&file, findvar=str, replacevar=rep)
26
+ data _null_;
27
+ infile &file;
28
+ input;
29
+ list;
30
+ run;
31
+
32
+ Note - if you are running a version of SAS that will allow the io package in
33
+ LUA, you can also use this macro: mp_gsubfile.sas
34
+
35
+ @param infile The QUOTED path to the file on which to perform the substitution
36
+ @param findvar= Macro variable NAME containing the string to search for
37
+ @param replacevar= Macro variable NAME containing the replacement string
38
+ @param outfile= (0) Optional QUOTED path to an the adjusted output file (to
39
+ avoid overwriting the first file).
40
+
41
+ <h4> SAS Macros </h4>
42
+ @li mf_getuniquefileref.sas
43
+ @li mf_getuniquename.sas
44
+
45
+ <h4> Related Macros </h4>
46
+ @li mp_gsubfile.test.sas
47
+
48
+ @version 9.4
49
+ @author Bartosz Jabłoński
50
+ @author Allan Bowe
51
+ **/
52
+
53
+ %macro mp_replace(infile,
54
+ findvar=,
55
+ replacevar=,
56
+ outfile=0
57
+ )/*/STORE SOURCE*/;
58
+
59
+ %local inref dttm ds1;
60
+ %let inref=%mf_getuniquefileref();
61
+ %let outref=%mf_getuniquefileref();
62
+ %if &outfile=0 %then %let outfile=&infile;
63
+ %let ds1=%mf_getuniquename(prefix=allchars);
64
+ %let ds2=%mf_getuniquename(prefix=startmark);
65
+
66
+ /* START */
67
+ %let dttm=%sysfunc(datetime());
68
+
69
+ filename &inref &infile lrecl=1 recfm=n;
70
+
71
+ data &ds1;
72
+ infile &inref;
73
+ input sourcechar $ 1. @@;
74
+ format sourcechar hex2.;
75
+ run;
76
+
77
+ data &ds2;
78
+ /* set find string to length in bytes to cover trailing spaces */
79
+ length string $ %length(%superq(&findvar));
80
+ string =symget("&findvar");
81
+ drop string;
82
+
83
+ firstchar=char(string,1);
84
+ findlen=lengthm(string); /* <- for trailing bytes */
85
+
86
+ do _N_=1 to nobs;
87
+ set &ds1 nobs=nobs point=_N_;
88
+ if sourcechar=firstchar then do;
89
+ pos=1;
90
+ s=0;
91
+ do point=_N_ to min(_N_ + findlen -1,nobs);
92
+ set &ds1 point=point;
93
+ if sourcechar=char(string, pos) then s + 1;
94
+ else goto _leave_;
95
+ pos+1;
96
+ end;
97
+ _leave_:
98
+ if s=findlen then do;
99
+ START =_N_;
100
+ _N_ =_N_+ s - 1;
101
+ STOP =_N_;
102
+ output;
103
+ end;
104
+ end;
105
+ end;
106
+ stop;
107
+ keep START STOP;
108
+ run;
109
+
110
+ data &ds1;
111
+ declare hash HS(dataset:"&ds2(keep=start)");
112
+ HS.defineKey("start");
113
+ HS.defineDone();
114
+ declare hash HE(dataset:"&ds2(keep=stop)");
115
+ HE.defineKey("stop");
116
+ HE.defineDone();
117
+ do until(eof);
118
+ set &ds1 end=eof curobs =n;
119
+ start = ^HS.check(key:n);
120
+ stop = ^HE.check(key:n);
121
+ length strt $ 1;
122
+ strt =put(start,best. -L);
123
+ retain out 1;
124
+ if out then output;
125
+ if start then out=0;
126
+ if stop then out=1;
127
+ end;
128
+ stop;
129
+ keep sourcechar strt;
130
+ run;
131
+
132
+ filename &outref &outfile recfm=n;
133
+
134
+ data _null_;
135
+ length replace $ %length(%superq(&replacevar));
136
+ replace=symget("&replacevar");
137
+ file &outref;
138
+ do until(eof);
139
+ set &ds1 end=eof;
140
+ if strt ="1" then put replace char.;
141
+ else put sourcechar char1.;
142
+ end;
143
+ stop;
144
+ run;
145
+
146
+ /* END */
147
+ %put &sysmacroname took %sysevalf(%sysfunc(datetime())-&dttm) seconds to run;
148
+
149
+ %mend mp_replace;
@@ -12,7 +12,7 @@
12
12
 
13
13
  %mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt)
14
14
 
15
- @param [in] contenttype= (TEXTS) Either TEXT, ZIP, CSV, EXCEL
15
+ @param [in] contenttype= (TEXT) Either TEXT, ZIP, CSV, EXCEL
16
16
  @param [in] inloc= /path/to/file.ext to be sent
17
17
  @param [in] inref= fileref of file to be sent (if provided, overrides `inloc`)
18
18
  @param [in] iftrue= (1=1) Provide a condition under which to execute.
@@ -40,6 +40,12 @@
40
40
  /* now try and assign it */
41
41
  if libname("&libref",,'meta',cats('liburi="',liburi,'";')) ne 0 then do;
42
42
  putlog "&libref could not be assigned";
43
+ putlog liburi=;
44
+ /**
45
+ * Fetch the system message for display in the abort modal. This is
46
+ * not always helpful though. One example, previously received:
47
+ * NOTE: Libref XX refers to the same library metadata as libref XX.
48
+ */
43
49
  call symputx('msg',sysmsg(),'l');
44
50
  if "&mabort"='HARD' then call symputx('mp_abort',1,'l');
45
51
  end;
@@ -61,7 +67,7 @@
61
67
 
62
68
  %if &mp_abort=1 %then %do;
63
69
  %mp_abort(iftrue= (&mp_abort=1)
64
- ,mac=&sysmacroname
70
+ ,mac=mm_assignlib.sas
65
71
  ,msg=&msg
66
72
  )
67
73
  %return;
package/package.json CHANGED
@@ -36,5 +36,5 @@
36
36
  "@sasjs/cli": "3.6.0",
37
37
  "@sasjs/core": "4.4.7"
38
38
  },
39
- "version": "4.11.0"
39
+ "version": "4.13.1"
40
40
  }
@@ -0,0 +1,89 @@
1
+ /**
2
+ @file
3
+ @brief Creates a file on SASjs Drive
4
+ @details Creates a file on SASjs Drive. To use the file as a Stored Program,
5
+ it must have a ".sas" extension.
6
+
7
+ Example:
8
+
9
+ filename stpcode temp;
10
+ data _null_;
11
+ file stpcode;
12
+ put '%put hello world;';
13
+ run;
14
+ %ms_createfile(/some/stored/program.sas, inref=stpcode)
15
+
16
+ @param [in] driveloc The full path to the file in SASjs Drive
17
+ @param [in] inref= (0) The fileref containing the file to create.
18
+ @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
19
+
20
+ <h4> SAS Macros </h4>
21
+ @li mf_getuniquefileref.sas
22
+ @li mf_getuniquename.sas
23
+ @li mp_abort.sas
24
+
25
+ **/
26
+
27
+ %macro ms_createfile(driveloc
28
+ ,inref=0
29
+ ,mdebug=0
30
+ );
31
+
32
+ %local fname0 fname1 boundary fname statcd msg;
33
+ %let fname0=%mf_getuniquefileref();
34
+ %let fname1=%mf_getuniquefileref();
35
+ %let boundary=%mf_getuniquename();
36
+
37
+ data _null_;
38
+ file &fname0 termstr=crlf;
39
+ infile &inref end=eof;
40
+ if _n_ = 1 then do;
41
+ put "--&boundary.";
42
+ put 'Content-Disposition: form-data; name="filePath"';
43
+ put ;
44
+ put "&driveloc";
45
+ put "--&boundary";
46
+ put 'Content-Disposition: form-data; name="file"; filename="ignore.sas"';
47
+ put "Content-Type: text/plain";
48
+ put ;
49
+ end;
50
+ input;
51
+ put _infile_; /* add the actual file to be sent */
52
+ if eof then do;
53
+ put ;
54
+ put "--&boundary--";
55
+ end;
56
+ run;
57
+
58
+ %if &mdebug=1 %then %do;
59
+ data _null_;
60
+ infile &fname0;
61
+ input;
62
+ put _infile_;
63
+ run;
64
+ %end;
65
+
66
+ proc http method='POST' in=&fname0 out=&fname1
67
+ url="&_sasjs_apiserverurl/SASjsApi/drive/file";
68
+ headers "Content-Type"="multipart/form-data; boundary=&boundary";
69
+ %if &mdebug=1 %then %do;
70
+ debug level=1;
71
+ %end;
72
+ run;
73
+
74
+ %let statcd=0;
75
+ data _null_;
76
+ infile &fname1;
77
+ input;
78
+ putlog _infile_;
79
+ if _infile_='{"status":"success"}' then call symputx('statcd',1,'l');
80
+ else call symputx('msg',_infile_,'l');
81
+ run;
82
+
83
+ %mp_abort(
84
+ iftrue=(&statcd=0)
85
+ ,mac=ms_createfile.sas
86
+ ,msg=%superq(msg)
87
+ )
88
+
89
+ %mend ms_createfile;
@@ -0,0 +1,77 @@
1
+ /**
2
+ @file
3
+ @brief Executes a SASjs Server Stored Program
4
+ @details Runs a Stored Program (using POST method) and extracts the webout and
5
+ log from the response JSON.
6
+
7
+ Example:
8
+
9
+ %ms_runstp(/some/stored/program
10
+ ,debug=131
11
+ ,outref=weboot
12
+ )
13
+
14
+ @param [in] pgm The full path to the Stored Program in SASjs Drive (_program
15
+ parameter)
16
+ @param [in] debug= (131) The value to supply to the _debug URL parameter
17
+ @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
18
+ @param [out] outref= (outweb) The output fileref to contain the response JSON
19
+ (will be created using temp engine)
20
+
21
+ <h4> SAS Macros </h4>
22
+ @li mf_getuniquefileref.sas
23
+ @li mp_abort.sas
24
+
25
+ **/
26
+
27
+ %macro ms_runstp(pgm
28
+ ,debug=131
29
+ ,outref=outweb
30
+ ,mdebug=0
31
+ );
32
+ %local dbg fname1;
33
+ %if &mdebug=1 %then %do;
34
+ %put &sysmacroname entry vars:;
35
+ %put _local_;
36
+ %end;
37
+ %else %let dbg=*;
38
+ %let fname1=%mf_getuniquefileref();
39
+
40
+ %mp_abort(iftrue=("&pgm"="")
41
+ ,mac=&sysmacroname
42
+ ,msg=%str(Program not provided)
43
+ )
44
+
45
+ data _null_;
46
+ file &fname1;
47
+ infile "&_sasjs_tokenfile";
48
+ input;
49
+ put 'Authorization: Bearer' _infile_;
50
+ run;
51
+
52
+ filename &outref temp;
53
+
54
+ /* prepare request*/
55
+ proc http method='POST' headerin=&fname1 out=&outref
56
+ url="&_sasjs_apiserverurl.&_sasjs_apipath?_program=&pgm%str(&)_debug=131";
57
+ run;
58
+ %if (&SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201)
59
+ or &mdebug=1 %then %do;
60
+ data _null_;infile &outref;input;putlog _infile_;run;
61
+ %end;
62
+ %mp_abort(
63
+ iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201)
64
+ ,mac=&sysmacroname
65
+ ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
66
+ )
67
+
68
+
69
+ %if &mdebug=1 %then %do;
70
+ %put &sysmacroname exit vars:;
71
+ %put _local_;
72
+ %end;
73
+ %else %do;
74
+ /* clear refs */
75
+ filename &fname1 clear;
76
+ %end;
77
+ %mend ms_runstp;
@@ -81,6 +81,7 @@
81
81
  @li mf_loc.sas
82
82
  @li mf_getquotedstr.sas
83
83
  @li mf_getuser.sas
84
+ @li mp_abort.sas
84
85
 
85
86
  **/
86
87
 
@@ -98,7 +99,7 @@
98
99
  ,refresh_token_validity=DEFAULT
99
100
  ,outjson=_null_
100
101
  );
101
- %local fname1 fname2 fname3 libref access_token url tokloc;
102
+ %local fname1 fname2 fname3 libref access_token url tokloc msg;
102
103
 
103
104
  %if client_name=DEFAULT %then %let client_name=
104
105
  Generated by %mf_getuser() (&sysuserid) on %sysfunc(datetime(),datetime19.
@@ -112,10 +113,11 @@ options noquotelenmax;
112
113
  %let tokloc=%mf_loc(VIYACONFIG)&tokloc/client.token;
113
114
 
114
115
  %if %sysfunc(fileexist(&tokloc))=0 %then %do;
115
- %put &sysmacroname: unable to access the consul token at &tokloc;
116
+ %let msg=Unable to access the consul token at &tokloc;
117
+ %put &sysmacroname: &msg;
116
118
  %put Try passing the value in the consul= macro parameter;
117
119
  %put See docs: https://core.sasjs.io/mv__registerclient_8sas.html;
118
- %abort;
120
+ %mp_abort(mac=mv_registerclient,msg=%str(&msg))
119
121
  %end;
120
122
 
121
123
  data _null_;