@sasjs/core 2.48.6 → 2.51.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 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
- [![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
192
+ [![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#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
 
@@ -3,20 +3,13 @@
3
3
  @brief Returns all files and subdirectories within a specified parent
4
4
  @details When used with getattrs=NO, is not OS specific (uses dopen / dread).
5
5
 
6
- If getattrs=YES then the doptname / foptname functions are used to scan all
7
- properties - any characters that are not valid in a SAS name (v7) are simply
8
- stripped, and the table is transposed so theat each property is a column
9
- and there is one file per row. An attempt is made to get all properties
10
- whether a file or folder, but some files/folders cannot be accessed, and so
11
- not all properties can / will be populated.
12
-
13
6
  Credit for the rename approach:
14
7
  https://communities.sas.com/t5/SAS-Programming/SAS-Function-to-convert-string-to-Legal-SAS-Name/m-p/27375/highlight/true#M5003
15
8
 
16
9
 
17
10
  usage:
18
11
 
19
- %mp_dirlist(path=/some/location,outds=myTable)
12
+ %mp_dirlist(path=/some/location, outds=myTable, maxdepth=MAX)
20
13
 
21
14
  %mp_dirlist(outds=cwdfileprops, getattrs=YES)
22
15
 
@@ -30,11 +23,19 @@
30
23
  X CMD) do please raise an issue!
31
24
 
32
25
 
33
- @param path= for which to return contents
34
- @param fref= Provide a DISK engine fileref as an alternative to PATH
35
- @param outds= the output dataset to create
36
- @param getattrs= YES/NO (default=NO). Uses doptname and foptname to return
37
- all attributes for each file / folder.
26
+ @param [in] path= for which to return contents
27
+ @param [in] fref= Provide a DISK engine fileref as an alternative to PATH
28
+ @param [in] maxdepth= (0) Set to a positive integer to indicate the level of
29
+ subdirectory scan recursion - eg 3, to go `./3/levels/deep`. For unlimited
30
+ recursion, set to MAX.
31
+ @param [out] outds= the output dataset to create
32
+ @param [out] getattrs= (NO) If getattrs=YES then the doptname / foptname
33
+ functions are used to scan all properties - any characters that are not
34
+ valid in a SAS name (v7) are simply stripped, and the table is transposed
35
+ so theat each property is a column and there is one file per row. An
36
+ attempt is made to get all properties whether a file or folder, but some
37
+ files/folders cannot be accessed, and so not all properties can / will be
38
+ populated.
38
39
 
39
40
 
40
41
  @returns outds contains the following variables:
@@ -44,8 +45,12 @@
44
45
  - filename (just the file name)
45
46
  - ext (.extension)
46
47
  - msg (system message if any issues)
48
+ - level (depth of folder)
47
49
  - OS SPECIFIC variables, if <code>getattrs=</code> is used.
48
50
 
51
+ <h4> SAS Macros </h4>
52
+ @li mp_dropmembers.sas
53
+
49
54
  @version 9.2
50
55
  @author Allan Bowe
51
56
  **/
@@ -54,14 +59,27 @@
54
59
  , fref=0
55
60
  , outds=work.mp_dirlist
56
61
  , getattrs=NO
62
+ , maxdepth=0
63
+ , level=0 /* The level of recursion to perform. For internal use only. */
57
64
  )/*/STORE SOURCE*/;
58
65
  %let getattrs=%upcase(&getattrs)XX;
59
66
 
60
- data &outds(compress=no
61
- keep=file_or_folder filepath filename ext msg directory
67
+ /* temp table */
68
+ %local out_ds;
69
+ data;run;
70
+ %let out_ds=%str(&syslast);
71
+
72
+ /* drop main (top) table if it exists */
73
+ %if &level=0 %then %do;
74
+ %mp_dropmembers(&outds, libref=WORK)
75
+ %end;
76
+
77
+ data &out_ds(compress=no
78
+ keep=file_or_folder filepath filename ext msg directory level
62
79
  );
63
80
  length directory filepath $500 fref fref2 $8 file_or_folder $6 filename $80
64
81
  ext $20 msg $200;
82
+ retain level &level;
65
83
  %if &fref=0 %then %do;
66
84
  rc = filename(fref, "&path");
67
85
  %end;
@@ -119,8 +137,8 @@ data &outds(compress=no
119
137
  run;
120
138
 
121
139
  %if %substr(&getattrs,1,1)=Y %then %do;
122
- data &outds;
123
- set &outds;
140
+ data &out_ds;
141
+ set &out_ds;
124
142
  length infoname infoval $60 fref $8;
125
143
  rc=filename(fref,filepath);
126
144
  drop rc infoname fid i close fref;
@@ -161,10 +179,35 @@ run;
161
179
  run;
162
180
  proc sort;
163
181
  by filepath sasname;
164
- proc transpose data=&outds out=&outds(drop=_:);
182
+ proc transpose data=&out_ds out=&out_ds(drop=_:);
165
183
  id sasname;
166
184
  var infoval;
167
185
  by filepath file_or_folder filename ext ;
168
186
  run;
169
187
  %end;
188
+
189
+ data &out_ds;
190
+ set &out_ds(where=(filepath ne ''));
191
+ run;
192
+
193
+ /* update main table */
194
+ proc append base=&outds data=&out_ds;
195
+ run;
196
+
197
+ /* recursive call */
198
+ %if &maxdepth>&level or &maxdepth=MAX %then %do;
199
+ data _null_;
200
+ set &out_ds;
201
+ where file_or_folder='folder';
202
+ code=cats('%nrstr(%mp_dirlist(path=',filepath,",outds=&outds"
203
+ ,",getattrs=&getattrs,level=%eval(&level+1),maxdepth=&maxdepth))");
204
+ put code=;
205
+ call execute(code);
206
+ run;
207
+ %end;
208
+
209
+ /* tidy up */
210
+ proc sql;
211
+ drop table &out_ds;
212
+
170
213
  %mend mp_dirlist;
@@ -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
- It is not possible to retain permissions / timestamps, also the BOF marker
6
- is lost so it cannot extract binary files.
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
- Usage:
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= fileref or quoted full path to zip file ("/path/to/file.zip")
20
- @param outdir= directory in which to write the outputs (created if non existant)
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
- filename &fname1 ZIP &ziploc; * Macro variable &datazip would be read from the file*;
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= FILE, DATASET, DIRECTORY. (FILE / DATASET not ready yet)
20
- @param outname= output file to create, without .zip extension
21
- @param outpath= location for output zip file
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
- command=cats('ods package add file="',filepath
61
+ __command=cats('ods package add file="',filepath
55
62
  ,'" mimetype="application/x-compress";');
56
- call execute(command);
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 &in;
66
73
  length __command $4000;
67
- command=cats('ods package add file="',&incol
74
+ __command=cats('ods package add file="',&incol
68
75
  ,'" mimetype="application/x-compress";');
69
- call execute(command);
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
@@ -33,7 +33,7 @@
33
33
  "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
34
34
  },
35
35
  "devDependencies": {
36
- "@sasjs/cli": "^2.38.8"
36
+ "@sasjs/cli": "^2.39.0"
37
37
  },
38
- "version": "2.48.6"
38
+ "version": "2.51.0"
39
39
  }
@@ -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
- }