@sasjs/core 4.12.0 → 4.13.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 +2 -1
- package/base/mp_replace.sas +149 -0
- package/package.json +1 -1
- package/viya/mv_registerclient.sas +5 -3
package/README.md
CHANGED
|
@@ -219,7 +219,7 @@ If you find this library useful, please leave a [star](https://github.com/sasjs/
|
|
|
219
219
|
|
|
220
220
|
## Contributors ✨
|
|
221
221
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
222
|
-
[](#contributors-)
|
|
223
223
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
224
224
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
225
225
|
|
|
@@ -240,6 +240,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
240
240
|
<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>
|
|
241
241
|
<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>
|
|
242
242
|
<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>
|
|
243
|
+
<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>
|
|
243
244
|
</tr>
|
|
244
245
|
</table>
|
|
245
246
|
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -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
|
-
%
|
|
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
|
-
%
|
|
120
|
+
%mp_abort(mac=mv_registerclient,msg=%str(&msg))
|
|
119
121
|
%end;
|
|
120
122
|
|
|
121
123
|
data _null_;
|