@sasjs/core 2.48.5 → 2.50.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 +3 -1
- package/base/mp_getconstraints.sas +5 -2
- package/base/mp_lockanytable.sas +255 -0
- package/base/mp_lockfilecheck.sas +97 -0
- package/base/mp_unzip.sas +8 -6
- package/base/mp_wait4file.sas +37 -0
- package/base/mp_zip.sas +14 -8
- package/package.json +2 -2
- package/.all-contributorsrc +0 -104
package/README.md
CHANGED
|
@@ -189,7 +189,7 @@ If you find this library useful, please leave a [star](https://github.com/sasjs/
|
|
|
189
189
|
|
|
190
190
|
## Contributors ✨
|
|
191
191
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
192
|
-
[](#contributors-)
|
|
193
193
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
194
194
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
195
195
|
|
|
@@ -208,6 +208,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
208
208
|
</tr>
|
|
209
209
|
<tr>
|
|
210
210
|
<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>
|
|
211
|
+
<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>
|
|
212
|
+
<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>
|
|
211
213
|
</tr>
|
|
212
214
|
</table>
|
|
213
215
|
|
|
@@ -49,8 +49,11 @@ create table &outds as
|
|
|
49
49
|
on upcase(a.TABLE_CATALOG)=upcase(b.TABLE_CATALOG)
|
|
50
50
|
and upcase(a.TABLE_NAME)=upcase(b.TABLE_NAME)
|
|
51
51
|
and a.constraint_name=b.constraint_name
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
/**
|
|
53
|
+
* We cannot apply this clause to the underlying dictionary table. See:
|
|
54
|
+
* https://communities.sas.com/t5/SAS-Programming/Unexpected-Where-Clause-behaviour-in-dictionary-TABLE/m-p/771554#M244867
|
|
55
|
+
*/
|
|
56
|
+
where calculated libref="&lib"
|
|
54
57
|
%if "&ds" ne "" %then %do;
|
|
55
58
|
and upcase(a.TABLE_NAME)="&ds"
|
|
56
59
|
and upcase(b.TABLE_NAME)="&ds"
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
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.
|
|
5
|
+
Only useful if every update uses the macro! Used heavily within
|
|
6
|
+
[Data Controller for SAS](https://datacontroller.io).
|
|
7
|
+
|
|
8
|
+
The underlying table is structured as per the MAKETABLE action.
|
|
9
|
+
|
|
10
|
+
@param [in] action The action to be performed. Valid values:
|
|
11
|
+
@li LOCK - Sets the lock flag, also confirms if a SAS lock is available
|
|
12
|
+
@li UNLOCK - Unlocks the table
|
|
13
|
+
@li MAKETABLE - creates the control table (ctl_ds)
|
|
14
|
+
@param [in] lib= (WORK) The libref of the table to lock. Should already be
|
|
15
|
+
assigned.
|
|
16
|
+
@param [in] ds= The dataset to lock
|
|
17
|
+
@param [in] ref= A meaningful reference to enable the lock to be traced. Max
|
|
18
|
+
length is 200 characters.
|
|
19
|
+
@param [out] ctl_ds= (0) The control table which controls the actual locking.
|
|
20
|
+
Should already be assigned and available.
|
|
21
|
+
@param [in] loops= (25) Number of times to check for a lock.
|
|
22
|
+
@param [in] loop_secs= (1) Seconds to wait between each lock attempt
|
|
23
|
+
|
|
24
|
+
<h4> SAS Macros </h4>
|
|
25
|
+
@li mp_abort.sas
|
|
26
|
+
@li mp_lockfilecheck.sas
|
|
27
|
+
@li mf_getuser.sas
|
|
28
|
+
|
|
29
|
+
<h4> Related Macros </h4>
|
|
30
|
+
@li mp_lockanytable.test.sas
|
|
31
|
+
|
|
32
|
+
@version 9.2
|
|
33
|
+
|
|
34
|
+
**/
|
|
35
|
+
|
|
36
|
+
%macro mp_lockanytable(
|
|
37
|
+
action
|
|
38
|
+
,lib= WORK
|
|
39
|
+
,ds=0
|
|
40
|
+
,ref=
|
|
41
|
+
,ctl_ds=0
|
|
42
|
+
,loops=25
|
|
43
|
+
,loop_secs=1
|
|
44
|
+
);
|
|
45
|
+
data _null_;
|
|
46
|
+
if _n_=1 then putlog "&sysmacroname entry vars:";
|
|
47
|
+
set sashelp.vmacro;
|
|
48
|
+
where scope="&sysmacroname";
|
|
49
|
+
put name '=' value;
|
|
50
|
+
run;
|
|
51
|
+
|
|
52
|
+
%mp_abort(iftrue= (&ds=0 and &action ne MAKETABLE)
|
|
53
|
+
,mac=&sysmacroname
|
|
54
|
+
,msg=%str(dataset was not provided)
|
|
55
|
+
)
|
|
56
|
+
%mp_abort(iftrue= (&ctl_ds=0)
|
|
57
|
+
,mac=&sysmacroname
|
|
58
|
+
,msg=%str(Control dataset was not provided)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
/* set up lib & mac vars */
|
|
62
|
+
%let lib=%upcase(&lib);
|
|
63
|
+
%let ds=%upcase(&ds);
|
|
64
|
+
%let action=%upcase(&action);
|
|
65
|
+
%local user x trans msg abortme;
|
|
66
|
+
%let user=%mf_getuser();
|
|
67
|
+
%let abortme=0;
|
|
68
|
+
|
|
69
|
+
%mp_abort(iftrue= (&action ne LOCK & &action ne UNLOCK & &action ne MAKETABLE)
|
|
70
|
+
,mac=&sysmacroname
|
|
71
|
+
,msg=%str(Invalid action (&action) provided)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
/* if an err condition exists, exit before we even begin */
|
|
75
|
+
%mp_abort(iftrue= (&syscc>0 and &action=LOCK)
|
|
76
|
+
,mac=&sysmacroname
|
|
77
|
+
,msg=%str(aborting due to syscc=&syscc on LOCK entry)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
/* do not bother locking work tables (else may affect all WORK libraries) */
|
|
81
|
+
%if (%upcase(&lib)=WORK or %str(&lib)=%str()) & &action ne MAKETABLE %then %do;
|
|
82
|
+
%put NOTE: WORK libraries will not be registered in the locking system.;
|
|
83
|
+
%return;
|
|
84
|
+
%end;
|
|
85
|
+
|
|
86
|
+
/* do not proceed if no observations can be processed */
|
|
87
|
+
%mp_abort(iftrue= (%sysfunc(getoption(OBS))=0)
|
|
88
|
+
,mac=&sysmacroname
|
|
89
|
+
,msg=%str(options obs = 0. syserrortext=&syserrortext)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
%if &ACTION=LOCK %then %do;
|
|
93
|
+
|
|
94
|
+
/* abort if a SAS lock is already in place, or cannot be applied */
|
|
95
|
+
%mp_lockfilecheck(&lib..&ds)
|
|
96
|
+
|
|
97
|
+
/* next, check there is a record for this table */
|
|
98
|
+
%local record_exists_check;
|
|
99
|
+
proc sql noprint;
|
|
100
|
+
select count(*) into: record_exists_check from &ctl_ds
|
|
101
|
+
where LOCK_LIB ="&lib" and LOCK_DS="&ds";
|
|
102
|
+
quit;
|
|
103
|
+
%if &syscc>0 %then %put syscc=&syscc sqlrc=&sqlrc;
|
|
104
|
+
%if &record_exists_check=0 %then %do;
|
|
105
|
+
data _null_;
|
|
106
|
+
putlog "&sysmacroname: adding record to lock table..";
|
|
107
|
+
run;
|
|
108
|
+
|
|
109
|
+
data ;
|
|
110
|
+
if 0 then set &ctl_ds;
|
|
111
|
+
LOCK_LIB ="&lib";
|
|
112
|
+
LOCK_DS="&ds";
|
|
113
|
+
LOCK_STATUS_CD='LOCKED';
|
|
114
|
+
LOCK_START_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt;
|
|
115
|
+
LOCK_USER_NM="&user";
|
|
116
|
+
LOCK_PID="&sysjobid";
|
|
117
|
+
LOCK_REF="&ref";
|
|
118
|
+
output;stop;
|
|
119
|
+
run;
|
|
120
|
+
%let trans=&syslast;
|
|
121
|
+
proc append base=&ctl_ds data=&trans;
|
|
122
|
+
run;
|
|
123
|
+
%end;
|
|
124
|
+
/* if record does exist, perform lock attempts */
|
|
125
|
+
%else %do x=1 %to &loops;
|
|
126
|
+
data _null_;
|
|
127
|
+
putlog "&sysmacroname: attempting lock (iteration &x) "@;
|
|
128
|
+
putlog "at %sysfunc(datetime(),datetime19.) ..";
|
|
129
|
+
run;
|
|
130
|
+
|
|
131
|
+
proc sql;
|
|
132
|
+
update &ctl_ds
|
|
133
|
+
set LOCK_STATUS_CD='LOCKED'
|
|
134
|
+
, LOCK_START_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt
|
|
135
|
+
, LOCK_USER_NM="&user"
|
|
136
|
+
, LOCK_PID="&sysjobid"
|
|
137
|
+
, LOCK_REF="&ref"
|
|
138
|
+
where LOCK_LIB ="&lib" and LOCK_DS="&ds";
|
|
139
|
+
quit;
|
|
140
|
+
/**
|
|
141
|
+
* NOTE - occasionally SQL server will return an err code (deadlocked
|
|
142
|
+
* transaction). If so, ignore it, keep calm, and carry on..
|
|
143
|
+
*/
|
|
144
|
+
%if &syscc>0 %then %do;
|
|
145
|
+
data _null_;
|
|
146
|
+
putlog 'NOTE-' / 'NOTE-';
|
|
147
|
+
putlog "NOTE- &sysmacroname: Update failed. "@;
|
|
148
|
+
putlog "Resetting err conditions and re-attempting.";
|
|
149
|
+
putlog "NOTE- syscc=&syscc syserr=&syserr sqlrc=&sqlrc";
|
|
150
|
+
putlog 'NOTE-' / 'NOTE-';
|
|
151
|
+
run;
|
|
152
|
+
%let syscc=0;
|
|
153
|
+
%let sqlrc=0;
|
|
154
|
+
%end;
|
|
155
|
+
|
|
156
|
+
/* now check if the record was successfully updated */
|
|
157
|
+
%local success_check;
|
|
158
|
+
proc sql noprint;
|
|
159
|
+
select count(*) into: success_check from &ctl_ds
|
|
160
|
+
where LOCK_LIB ="&lib" and LOCK_DS="&ds"
|
|
161
|
+
and LOCK_PID="&sysjobid" and LOCK_STATUS_CD='LOCKED';
|
|
162
|
+
quit;
|
|
163
|
+
%if &success_check=0 %then %do;
|
|
164
|
+
%if &x < &loops %then %do;
|
|
165
|
+
/* pause before next check */
|
|
166
|
+
data _null_;
|
|
167
|
+
putlog 'NOTE-' / 'NOTE-';
|
|
168
|
+
putlog "NOTE- &sysmacroname: table locked, waiting "@;
|
|
169
|
+
putlog "%sysfunc(sleep(&loop_inc)) seconds.. ";
|
|
170
|
+
putlog "NOTE- (iteration &x of &loops)";
|
|
171
|
+
putlog 'NOTE-' / 'NOTE-';
|
|
172
|
+
run;
|
|
173
|
+
%end;
|
|
174
|
+
%else %do;
|
|
175
|
+
%let msg=Unable to lock &lib..&ds via &ctl_ds after &loops attempts.\n
|
|
176
|
+
Please ask your administrator to investigate!;
|
|
177
|
+
%let abortme=1;
|
|
178
|
+
%end;
|
|
179
|
+
%end;
|
|
180
|
+
%else %do;
|
|
181
|
+
data _null_;
|
|
182
|
+
putlog 'NOTE-' / 'NOTE-';
|
|
183
|
+
putlog "NOTE- &sysmacroname: Table &lib..&ds locked at "@
|
|
184
|
+
putlog " %sysfunc(datetime(),datetime19.) (iteration &x)"@;
|
|
185
|
+
putlog 'NOTE-' / 'NOTE-';
|
|
186
|
+
run;
|
|
187
|
+
%if &syscc>0 %then %do;
|
|
188
|
+
%put setting syscc(&syscc) back to 0;
|
|
189
|
+
%let syscc=0;
|
|
190
|
+
%end;
|
|
191
|
+
%let x=&loops; /* no more iterations needed */
|
|
192
|
+
%end;
|
|
193
|
+
%end;
|
|
194
|
+
%end;
|
|
195
|
+
%else %if &ACTION=UNLOCK %then %do;
|
|
196
|
+
%local status;
|
|
197
|
+
proc sql noprint;
|
|
198
|
+
select LOCK_STATUS_CD into: status from &ctl_ds
|
|
199
|
+
where LOCK_LIB ="&lib" and LOCK_DS="&ds";
|
|
200
|
+
quit;
|
|
201
|
+
%if &syscc>0 %then %put syscc=&syscc sqlrc=&sqlrc;
|
|
202
|
+
%if &status=LOCKED %then %do;
|
|
203
|
+
data _null_;
|
|
204
|
+
putlog "&sysmacroname: unlocking &lib..&ds:";
|
|
205
|
+
run;
|
|
206
|
+
proc sql;
|
|
207
|
+
update &ctl_ds
|
|
208
|
+
set LOCK_STATUS_CD='UNLOCKED'
|
|
209
|
+
, LOCK_END_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt
|
|
210
|
+
, LOCK_USER_NM="&user"
|
|
211
|
+
, LOCK_PID="&sysjobid"
|
|
212
|
+
, LOCK_REF="&ref"
|
|
213
|
+
where LOCK_LIB ="&lib" and LOCK_DS="&ds";
|
|
214
|
+
quit;
|
|
215
|
+
%end;
|
|
216
|
+
%else %if &status=UNLOCKED %then %do;
|
|
217
|
+
%put %str(WAR)NING: &lib..&ds is already unlocked!;
|
|
218
|
+
%end;
|
|
219
|
+
%else %do;
|
|
220
|
+
%put NOTE: Unrecognised STATUS_CD (&status) in &ctl_ds;
|
|
221
|
+
%let abortme=1;
|
|
222
|
+
%end;
|
|
223
|
+
%end;
|
|
224
|
+
%else %if &action=MAKETABLE %then %do;
|
|
225
|
+
proc sql;
|
|
226
|
+
create table &ctl_ds(
|
|
227
|
+
lock_lib char(8),
|
|
228
|
+
lock_ds char(32),
|
|
229
|
+
lock_status_cd char(10) not null,
|
|
230
|
+
lock_user_nm char(100) not null ,
|
|
231
|
+
lock_ref char(200),
|
|
232
|
+
lock_pid char(10),
|
|
233
|
+
lock_start_dttm num format=E8601DT26.6,
|
|
234
|
+
lock_end_dttm num format=E8601DT26.6,
|
|
235
|
+
constraint pk_mp_lockanytable primary key(lock_lib,lock_ds));
|
|
236
|
+
%end;
|
|
237
|
+
%else %do;
|
|
238
|
+
%let msg=lock_anytable given unsupported action (&action);
|
|
239
|
+
%let abortme=1;
|
|
240
|
+
%end;
|
|
241
|
+
|
|
242
|
+
/* catch errors - mp_abort must be called outside of a logic block */
|
|
243
|
+
%mp_abort(iftrue=(&abortme=1),
|
|
244
|
+
msg=%superq(msg),
|
|
245
|
+
mac=&sysmacroname
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
%exit_macro:
|
|
249
|
+
data _null_;
|
|
250
|
+
put "&sysmacroname: Exit vars: action=&action lib=&lib ds=&ds";
|
|
251
|
+
put " syscc=&syscc sqlrc=&sqlrc syserr=&syserr";
|
|
252
|
+
run;
|
|
253
|
+
%mend mp_lockanytable;
|
|
254
|
+
|
|
255
|
+
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Aborts if a SAS lock file is in place, or if one cannot be applied.
|
|
4
|
+
@details Used in conjuction with the mp_lockanytable macro.
|
|
5
|
+
More info here: https://sasensei.com/flash/24
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
|
|
9
|
+
data work.test; a=1;run;
|
|
10
|
+
%mp_lockfilecheck(work.test)
|
|
11
|
+
|
|
12
|
+
@param [in] libds The libref.dataset for which to check the lock status
|
|
13
|
+
|
|
14
|
+
<h4> SAS Macros </h4>
|
|
15
|
+
@li mp_abort.sas
|
|
16
|
+
@li mf_getattrc.sas
|
|
17
|
+
|
|
18
|
+
<h4> Related Macros </h4>
|
|
19
|
+
@li mp_lockanytable.sas
|
|
20
|
+
@li mp_lockfilecheck.test.sas
|
|
21
|
+
|
|
22
|
+
@version 9.2
|
|
23
|
+
**/
|
|
24
|
+
|
|
25
|
+
%macro mp_lockfilecheck(
|
|
26
|
+
libds
|
|
27
|
+
)/*/STORE SOURCE*/;
|
|
28
|
+
|
|
29
|
+
data _null_;
|
|
30
|
+
if _n_=1 then putlog "&sysmacroname entry vars:";
|
|
31
|
+
set sashelp.vmacro;
|
|
32
|
+
where scope="&sysmacroname";
|
|
33
|
+
put name '=' value;
|
|
34
|
+
run;
|
|
35
|
+
|
|
36
|
+
%mp_abort(iftrue= (&syscc>0)
|
|
37
|
+
,mac=checklock.sas
|
|
38
|
+
,msg=Aborting with syscc=&syscc on entry.
|
|
39
|
+
)
|
|
40
|
+
%mp_abort(iftrue= (&libds=0)
|
|
41
|
+
,mac=&sysmacroname
|
|
42
|
+
,msg=%str(libds not provided)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
%local msg lib ds;
|
|
46
|
+
%let lib=%upcase(%scan(&libds,1,.));
|
|
47
|
+
%let ds=%upcase(%scan(&libds,2,.));
|
|
48
|
+
|
|
49
|
+
/* do not proceed if no observations can be processed */
|
|
50
|
+
%let msg=options obs = 0. syserrortext=%superq(syserrortext);
|
|
51
|
+
%mp_abort(iftrue= (%sysfunc(getoption(OBS))=0)
|
|
52
|
+
,mac=checklock.sas
|
|
53
|
+
,msg=%superq(msg)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
data _null_;
|
|
57
|
+
putlog "Checking engine & member type";
|
|
58
|
+
run;
|
|
59
|
+
%local engine memtype;
|
|
60
|
+
%let memtype=%mf_getattrc(&libds,MTYPE);
|
|
61
|
+
%let engine=%mf_getattrc(&libds,ENGINE);
|
|
62
|
+
|
|
63
|
+
%if &engine ne V9 and &engine ne BASE %then %do;
|
|
64
|
+
data _null_;
|
|
65
|
+
putlog "Lib &lib is not assigned using BASE engine - uses &engine instead";
|
|
66
|
+
putlog "SAS lock check will not be performed";
|
|
67
|
+
run;
|
|
68
|
+
%return;
|
|
69
|
+
%end;
|
|
70
|
+
%else %if &memtype ne DATA %then %do;
|
|
71
|
+
%put NOTE: Cannot lock a VIEW!! Memtype=&memtype;
|
|
72
|
+
%return;
|
|
73
|
+
%end;
|
|
74
|
+
|
|
75
|
+
data _null_;
|
|
76
|
+
putlog "Engine = &engine, memtype=&memtype";
|
|
77
|
+
putlog "Attempting lock statement";
|
|
78
|
+
run;
|
|
79
|
+
|
|
80
|
+
lock &libds;
|
|
81
|
+
|
|
82
|
+
%local abortme;
|
|
83
|
+
%let abortme=0;
|
|
84
|
+
%if &syscc>0 or &SYSLCKRC ne 0 %then %do;
|
|
85
|
+
%let msg=Unable to apply lock on &libds (SYSLCKRC=&SYSLCKRC syscc=&syscc);
|
|
86
|
+
%put %str(ERR)OR: &sysmacroname: &msg;
|
|
87
|
+
%let abortme=1;
|
|
88
|
+
%end;
|
|
89
|
+
|
|
90
|
+
lock &libds clear;
|
|
91
|
+
|
|
92
|
+
%mp_abort(iftrue= (&abortme=1)
|
|
93
|
+
,mac=&sysmacroname
|
|
94
|
+
,msg=%superq(msg)
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
%mend mp_lockfilecheck;
|
package/base/mp_unzip.sas
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
@file mp_unzip.sas
|
|
3
3
|
@brief Unzips a zip file
|
|
4
4
|
@details Opens the zip file and copies all the contents to another directory.
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
It is not possible to retain permissions / timestamps, also the BOF marker
|
|
6
|
+
is lost so it cannot extract binary files.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Usage:
|
|
9
9
|
|
|
10
10
|
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
|
11
11
|
%inc mc;
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
@li mf_mkdir.sas
|
|
17
17
|
@li mf_getuniquefileref.sas
|
|
18
18
|
|
|
19
|
-
@param ziploc=
|
|
20
|
-
@param outdir=
|
|
19
|
+
@param ziploc= Fileref or quoted full path to zip file ("/path/to/file.zip")
|
|
20
|
+
@param outdir= (%sysfunc(pathname(work))) Directory in which to write the
|
|
21
|
+
outputs (created if non existant)
|
|
21
22
|
|
|
22
23
|
@version 9.4
|
|
23
24
|
@author Allan Bowe
|
|
@@ -35,7 +36,8 @@
|
|
|
35
36
|
%let fname2=%mf_getuniquefileref();
|
|
36
37
|
%let fname3=%mf_getuniquefileref();
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
/* Macro variable &datazip would be read from the file */
|
|
40
|
+
filename &fname1 ZIP &ziploc;
|
|
39
41
|
|
|
40
42
|
/* Read the "members" (files) from the ZIP file */
|
|
41
43
|
data _data_(keep=memname isFolder);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Wait until a file arrives before continuing execution
|
|
4
|
+
@details Loops with a `sleep()` command until a file arrives or the max wait
|
|
5
|
+
period expires.
|
|
6
|
+
|
|
7
|
+
@example
|
|
8
|
+
|
|
9
|
+
Wait 3 minutes OR for /tmp/flag.txt to appear
|
|
10
|
+
|
|
11
|
+
%mp_wait4file(/tmp/flag.txt , maxwait=60*3)
|
|
12
|
+
|
|
13
|
+
@param [in] file The file to wait for. Must be provided.
|
|
14
|
+
@param [in] maxwait= (0) Number of seconds to wait. If set to zero, will
|
|
15
|
+
loop indefinitely (to a maximum of 46 days, per SAS [documentation](
|
|
16
|
+
https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001418809.htm
|
|
17
|
+
)). Otherwise, execution will proceed upon sleep expiry.
|
|
18
|
+
@param [in] interval= (1) The wait period between sleeps, in seconds
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
**/
|
|
22
|
+
|
|
23
|
+
%macro mp_wait4file(file, maxwait=0, interval=1);
|
|
24
|
+
|
|
25
|
+
%if %str(&file)=%str() %then %do;
|
|
26
|
+
%put %str(ERR)OR: file not provided;
|
|
27
|
+
%end;
|
|
28
|
+
|
|
29
|
+
data _null_;
|
|
30
|
+
maxwait=&maxwait;
|
|
31
|
+
if maxwait=0 then maxwait=60*60*24*46;
|
|
32
|
+
do until (fileexist("&file") or slept>maxwait );
|
|
33
|
+
slept=sum(slept,sleep(&interval,1));
|
|
34
|
+
end;
|
|
35
|
+
run;
|
|
36
|
+
|
|
37
|
+
%mend mp_wait4file;
|
package/base/mp_zip.sas
CHANGED
|
@@ -16,11 +16,18 @@
|
|
|
16
16
|
@li mp_dirlist.sas
|
|
17
17
|
|
|
18
18
|
@param in= unquoted filepath, dataset of files or directory to zip
|
|
19
|
-
@param type=
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
@param type= (FILE) Valid values:
|
|
20
|
+
@li FILE - /full/path/and/filename.extension to a particular file
|
|
21
|
+
@li DATASET - a dataset containing a list of files to zip (see `incol`)
|
|
22
|
+
@li DIRECTORY - a directory to zip
|
|
23
|
+
@param outname= (FILE) Output file to create, _without_ .zip extension
|
|
24
|
+
@param outpath= (%sysfunc(pathname(WORK))) Parent folder for output zip file
|
|
22
25
|
@param incol= if DATASET input, say which column contains the filepath
|
|
23
26
|
|
|
27
|
+
<h4> Related Macros </h4>
|
|
28
|
+
@li mp_unzip.sas
|
|
29
|
+
@li mp_zip.test.sas
|
|
30
|
+
|
|
24
31
|
@version 9.2
|
|
25
32
|
@author Allan Bowe
|
|
26
33
|
@source https://github.com/sasjs/core
|
|
@@ -51,9 +58,9 @@ ods package open nopf;
|
|
|
51
58
|
set &ds;
|
|
52
59
|
length __command $4000;
|
|
53
60
|
if file_or_folder='file';
|
|
54
|
-
|
|
61
|
+
__command=cats('ods package add file="',filepath
|
|
55
62
|
,'" mimetype="application/x-compress";');
|
|
56
|
-
call execute(
|
|
63
|
+
call execute(__command);
|
|
57
64
|
run;
|
|
58
65
|
/* tidy up */
|
|
59
66
|
%if &debug=NO %then %do;
|
|
@@ -64,11 +71,10 @@ ods package open nopf;
|
|
|
64
71
|
data _null_;
|
|
65
72
|
set ∈
|
|
66
73
|
length __command $4000;
|
|
67
|
-
|
|
74
|
+
__command=cats('ods package add file="',&incol
|
|
68
75
|
,'" mimetype="application/x-compress";');
|
|
69
|
-
call execute(
|
|
76
|
+
call execute(__command);
|
|
70
77
|
run;
|
|
71
|
-
ods package add file="&in" mimetype="application/x-compress";
|
|
72
78
|
%end;
|
|
73
79
|
|
|
74
80
|
|
package/package.json
CHANGED
package/.all-contributorsrc
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"projectName": "core",
|
|
3
|
-
"projectOwner": "sasjs",
|
|
4
|
-
"repoType": "github",
|
|
5
|
-
"repoHost": "https://github.com",
|
|
6
|
-
"files": [
|
|
7
|
-
"README.md"
|
|
8
|
-
],
|
|
9
|
-
"imageSize": 100,
|
|
10
|
-
"commit": false,
|
|
11
|
-
"commitConvention": "angular",
|
|
12
|
-
"contributors": [
|
|
13
|
-
{
|
|
14
|
-
"login": "allanbowe",
|
|
15
|
-
"name": "Allan Bowe",
|
|
16
|
-
"avatar_url": "https://avatars.githubusercontent.com/u/4420615?v=4",
|
|
17
|
-
"profile": "https://github.com/allanbowe",
|
|
18
|
-
"contributions": [
|
|
19
|
-
"business",
|
|
20
|
-
"code",
|
|
21
|
-
"content",
|
|
22
|
-
"doc",
|
|
23
|
-
"infra",
|
|
24
|
-
"maintenance",
|
|
25
|
-
"mentoring",
|
|
26
|
-
"question",
|
|
27
|
-
"review",
|
|
28
|
-
"test"
|
|
29
|
-
]
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"login": "rafgag",
|
|
33
|
-
"name": "rafgag",
|
|
34
|
-
"avatar_url": "https://avatars.githubusercontent.com/u/69139928?v=4",
|
|
35
|
-
"profile": "https://github.com/rafgag",
|
|
36
|
-
"contributions": [
|
|
37
|
-
"code"
|
|
38
|
-
]
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"login": "tmoody",
|
|
42
|
-
"name": "Trevor Moody",
|
|
43
|
-
"avatar_url": "https://avatars.githubusercontent.com/u/79837106?v=4",
|
|
44
|
-
"profile": "https://github.com/tmoody",
|
|
45
|
-
"contributions": [
|
|
46
|
-
"code"
|
|
47
|
-
]
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"login": "krishna-acondy",
|
|
51
|
-
"name": "Krishna Acondy",
|
|
52
|
-
"avatar_url": "https://avatars.githubusercontent.com/u/2980428?v=4",
|
|
53
|
-
"profile": "https://krishna-acondy.io/",
|
|
54
|
-
"contributions": [
|
|
55
|
-
"code",
|
|
56
|
-
"infra",
|
|
57
|
-
"blog",
|
|
58
|
-
"content",
|
|
59
|
-
"ideas",
|
|
60
|
-
"video"
|
|
61
|
-
]
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"login": "saadjutt01",
|
|
65
|
-
"name": "Muhammad Saad ",
|
|
66
|
-
"avatar_url": "https://avatars.githubusercontent.com/u/8914650?v=4",
|
|
67
|
-
"profile": "https://github.com/saadjutt01",
|
|
68
|
-
"contributions": [
|
|
69
|
-
"code",
|
|
70
|
-
"ideas"
|
|
71
|
-
]
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
"login": "YuryShkoda",
|
|
75
|
-
"name": "Yury Shkoda",
|
|
76
|
-
"avatar_url": "https://avatars.githubusercontent.com/u/25773492?v=4",
|
|
77
|
-
"profile": "https://www.erudicat.com/",
|
|
78
|
-
"contributions": [
|
|
79
|
-
"code",
|
|
80
|
-
"infra",
|
|
81
|
-
"video"
|
|
82
|
-
]
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
"login": "medjedovicm",
|
|
86
|
-
"name": "Mihajlo Medjedovic",
|
|
87
|
-
"avatar_url": "https://avatars.githubusercontent.com/u/18329105?v=4",
|
|
88
|
-
"profile": "https://github.com/medjedovicm",
|
|
89
|
-
"contributions": [
|
|
90
|
-
"infra"
|
|
91
|
-
]
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
"login": "kkchandok",
|
|
95
|
-
"name": "kkchandok",
|
|
96
|
-
"avatar_url": "https://avatars.githubusercontent.com/u/46090627?v=4",
|
|
97
|
-
"profile": "https://github.com/kkchandok",
|
|
98
|
-
"contributions": [
|
|
99
|
-
"ideas"
|
|
100
|
-
]
|
|
101
|
-
}
|
|
102
|
-
],
|
|
103
|
-
"contributorsPerLine": 7
|
|
104
|
-
}
|