@sasjs/core 7.0.3 → 7.1.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/base/mp_dirlist.sas +255 -134
- package/base/mp_ds2pdf.sas +157 -0
- package/base/mp_hashdirectory.sas +3 -1
- package/base/mp_streamfile.sas +18 -0
- package/base/mp_validatecol.sas +35 -0
- package/package.json +1 -1
- package/viya/mv_getgroupmembers.sas +15 -5
package/base/mp_dirlist.sas
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
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
|
-
Credit for the rename approach:
|
|
7
|
-
https://communities.sas.com/t5/SAS-Programming/SAS-Function-to-convert-string-to-Legal-SAS-Name/m-p/27375/highlight/true#M5003
|
|
8
|
-
|
|
9
6
|
Usage:
|
|
10
7
|
|
|
11
8
|
%mp_dirlist(path=/some/location, outds=myTable, maxdepth=MAX)
|
|
@@ -14,18 +11,26 @@
|
|
|
14
11
|
|
|
15
12
|
%mp_dirlist(fref=MYFREF)
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
are
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
Entries are classified with the dopen function alone. The previous
|
|
15
|
+
implementation also used fopen - which blocks when the entry is a named pipe
|
|
16
|
+
(fifo), so a single fifo in a folder was enough to hang the whole session.
|
|
17
|
+
With getattrs=NO that hazard is gone; with getattrs=YES entries are opened to
|
|
18
|
+
read their attributes, so a fifo can still block that mode.
|
|
19
|
+
|
|
20
|
+
@note Symlinks are followed. A symlink that points at one of its own parents
|
|
21
|
+
produces an endless path (a/b/link/b/link/...), so a browse service must
|
|
22
|
+
always pass a finite <code>maxdepth=</code>.
|
|
23
23
|
|
|
24
|
-
@param [in] path= (%sysfunc(pathname(work))) Path for which to return contents
|
|
24
|
+
@param [in] path= (%sysfunc(pathname(work))) Path for which to return contents.
|
|
25
|
+
Pass a blank value to list the platform roots instead - the drives that
|
|
26
|
+
exist on Windows, / on Unix.
|
|
25
27
|
@param [in] fref= (0) Provide a DISK engine fileref as an alternative to PATH
|
|
26
28
|
@param [in] maxdepth= (0) Set to a positive integer to indicate the level of
|
|
27
29
|
subdirectory scan recursion - eg 3, to go `./3/levels/deep`. For unlimited
|
|
28
30
|
recursion, set to MAX.
|
|
31
|
+
@param [in] maxobs= (0) Maximum number of rows to return. Zero means no
|
|
32
|
+
limit. Useful when the folder is expected to be huge and the caller only
|
|
33
|
+
needs a slice of it - no further levels are scanned once the cap is hit.
|
|
29
34
|
@param [in] showparent= (NO) By default, the initial parent directory is not
|
|
30
35
|
part of the results. Set to YES to include it. For this record only,
|
|
31
36
|
directory=filepath.
|
|
@@ -37,10 +42,16 @@
|
|
|
37
42
|
attempt is made to get all properties whether a file or folder, but some
|
|
38
43
|
files/folders cannot be accessed, and so not all properties can / will be
|
|
39
44
|
populated.
|
|
45
|
+
@param [in] level= (0) Ignored - retained so that callers of previous versions
|
|
46
|
+
do not break. Recursion is now done in a loop rather than by re-invoking
|
|
47
|
+
the macro.
|
|
40
48
|
|
|
41
49
|
@returns outds contains the following variables:
|
|
42
50
|
- directory (containing folder)
|
|
43
|
-
- file_or_folder
|
|
51
|
+
- file_or_folder. folder when it can be opened as a directory, file when
|
|
52
|
+
it is not a directory (or exists but is not readable, which the copy,
|
|
53
|
+
hash and zip tools treat as a file), and locked when it is listed but
|
|
54
|
+
cannot be opened at all - a broken link, for instance
|
|
44
55
|
- filepath (path/to/file.name)
|
|
45
56
|
- filename (just the file name)
|
|
46
57
|
- ext (.extension)
|
|
@@ -49,9 +60,8 @@
|
|
|
49
60
|
- OS SPECIFIC variables, if <code>getattrs=</code> is used.
|
|
50
61
|
|
|
51
62
|
<h4> SAS Macros </h4>
|
|
52
|
-
@li
|
|
53
|
-
@li
|
|
54
|
-
@li mf_wordsinstr1butnotstr2.sas
|
|
63
|
+
@li mf_getuniquefileref.sas
|
|
64
|
+
@li mf_nobs.sas
|
|
55
65
|
@li mp_dropmembers.sas
|
|
56
66
|
|
|
57
67
|
<h4> Related Macros </h4>
|
|
@@ -67,101 +77,251 @@
|
|
|
67
77
|
, getattrs=NO
|
|
68
78
|
, showparent=NO
|
|
69
79
|
, maxdepth=0
|
|
70
|
-
,
|
|
80
|
+
, maxobs=0
|
|
81
|
+
, level=0 /* deprecated - ignored, kept for backwards compatibility */
|
|
71
82
|
)/*/STORE SOURCE*/;
|
|
72
83
|
%let getattrs=%upcase(&getattrs)XX;
|
|
84
|
+
%let showparent=%upcase(&showparent)XX;
|
|
85
|
+
|
|
86
|
+
/* the separator belongs to the platform, not to the path text - a unix
|
|
87
|
+
directory name may contain a backslash without that being the separator */
|
|
88
|
+
%if "%upcase(&sysscp)"="WIN" or "%upcase(&sysscp)"="DNTHOST" %then %let mpsep=\;
|
|
89
|
+
%else %let mpsep=/;
|
|
73
90
|
|
|
74
|
-
|
|
75
|
-
%local
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
%local lvl nfront total room done mp_roots mpsep;
|
|
92
|
+
%local fref1 fref2;
|
|
93
|
+
|
|
94
|
+
/* the parent can be supplied as a fileref rather than a path */
|
|
95
|
+
%if &fref ne 0 %then %let path=%sysfunc(pathname(&fref));
|
|
96
|
+
|
|
97
|
+
/* MAX is not a number, so convert it (and anything not a digit) to an int */
|
|
98
|
+
%if %length(&maxdepth)=0 or %sysfunc(verify(&maxdepth,0123456789))>0 %then %do;
|
|
99
|
+
%if "%upcase(&maxdepth)"="MAX" %then %let maxdepth=2147483647;
|
|
100
|
+
%else %let maxdepth=0;
|
|
101
|
+
%end;
|
|
102
|
+
%if %length(&maxobs)=0 or %sysfunc(verify(&maxobs,0123456789))>0 %then %let maxobs=0;
|
|
78
103
|
|
|
79
104
|
/* drop main (top) table if it exists */
|
|
80
|
-
%
|
|
81
|
-
|
|
105
|
+
%mp_dropmembers(%scan(&outds,-1,.), libref=WORK)
|
|
106
|
+
|
|
107
|
+
/* an empty table with the target structure - each level is appended to it */
|
|
108
|
+
data &outds;
|
|
109
|
+
length directory filepath $2000 file_or_folder $6 filename $255 ext $20
|
|
110
|
+
msg $200 level 8;
|
|
111
|
+
call missing(of _all_);
|
|
112
|
+
stop;
|
|
113
|
+
run;
|
|
114
|
+
|
|
115
|
+
/* a unique fileref per purpose, generated once - only macro vars are local */
|
|
116
|
+
%let fref1=%mf_getuniquefileref();
|
|
117
|
+
%let fref2=%mf_getuniquefileref();
|
|
118
|
+
|
|
119
|
+
%let mp_roots=0;
|
|
120
|
+
%if %length(&path)=0 %then %let mp_roots=1;
|
|
121
|
+
|
|
122
|
+
%if &mp_roots=1 %then %do;
|
|
123
|
+
/*
|
|
124
|
+
A blank path is the platform roots: there is no filesystem root on Windows,
|
|
125
|
+
so the drives that exist are the top level, and / is that level on Unix.
|
|
126
|
+
*/
|
|
127
|
+
data work.__mp_dirlist_level;
|
|
128
|
+
length directory filepath $2000 file_or_folder $6 filename $255
|
|
129
|
+
ext $20 msg $200 level 8;
|
|
130
|
+
length drive $3 letters $26;
|
|
131
|
+
call missing(of _all_);
|
|
132
|
+
%if "%upcase(&sysscp)"="WIN" or "%upcase(&sysscp)"="DNTHOST" %then %do;
|
|
133
|
+
letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
134
|
+
do i=1 to 26;
|
|
135
|
+
drive=cats(substr(letters,i,1),':');
|
|
136
|
+
rc=filename("&fref1",cats(drive,'\'));
|
|
137
|
+
did=dopen("&fref1");
|
|
138
|
+
if did>0 then do;
|
|
139
|
+
rc=dclose(did);
|
|
140
|
+
directory=drive;
|
|
141
|
+
filepath=cats(drive,'\');
|
|
142
|
+
filename=filepath;
|
|
143
|
+
file_or_folder='folder';
|
|
144
|
+
level=0;
|
|
145
|
+
output;
|
|
146
|
+
end;
|
|
147
|
+
rc=filename("&fref1");
|
|
148
|
+
end;
|
|
149
|
+
%end;
|
|
150
|
+
%else %do;
|
|
151
|
+
directory='';
|
|
152
|
+
filepath='/';
|
|
153
|
+
filename='/';
|
|
154
|
+
file_or_folder='folder';
|
|
155
|
+
level=0;
|
|
156
|
+
output;
|
|
157
|
+
%end;
|
|
158
|
+
keep directory filepath file_or_folder filename ext msg level;
|
|
159
|
+
run;
|
|
160
|
+
proc append base=&outds data=work.__mp_dirlist_level nowarn force;
|
|
161
|
+
run;
|
|
162
|
+
/* the roots are folders, so they are what the next level expands */
|
|
163
|
+
data work.__mp_dirlist_frontier;
|
|
164
|
+
set work.__mp_dirlist_level(where=(file_or_folder='folder'));
|
|
165
|
+
level=1;
|
|
166
|
+
keep filepath level;
|
|
167
|
+
run;
|
|
168
|
+
%let lvl=1;
|
|
169
|
+
%end;
|
|
170
|
+
%else %do;
|
|
171
|
+
/* level 0 is the parent itself; the path is read with symget so that quotes
|
|
172
|
+
and macro triggers in a folder name are never evaluated as SAS code */
|
|
173
|
+
data work.__mp_dirlist_frontier;
|
|
174
|
+
length filepath $2000 level 8;
|
|
175
|
+
filepath=symget('path');
|
|
176
|
+
level=0;
|
|
177
|
+
run;
|
|
178
|
+
%let lvl=0;
|
|
82
179
|
%end;
|
|
83
180
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
181
|
+
%let nfront=%sysfunc(coalesce(%mf_nobs(work.__mp_dirlist_frontier),0));
|
|
182
|
+
%let done=0;
|
|
183
|
+
|
|
184
|
+
%do %until(&nfront=0 or &lvl>&maxdepth or &done=1);
|
|
185
|
+
|
|
186
|
+
data work.__mp_dirlist_level;
|
|
187
|
+
set work.__mp_dirlist_frontier;
|
|
188
|
+
length directory filepath $2000 file_or_folder $6 filename $255 ext $20
|
|
189
|
+
msg $200 sep $1 prefix $2000 fname $255 dmsg $200;
|
|
190
|
+
drop sep prefix fname dmsg rc did mid i;
|
|
191
|
+
directory=filepath;
|
|
192
|
+
msg='';
|
|
193
|
+
file_or_folder='';
|
|
194
|
+
ext='';
|
|
195
|
+
filename='';
|
|
196
|
+
rc=filename("&fref1", directory);
|
|
197
|
+
did=dopen("&fref1");
|
|
198
|
+
dmsg=sysmsg();
|
|
100
199
|
if did=0 then do;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
stop;
|
|
200
|
+
/* nothing to list - a parent that vanished between levels, or a path
|
|
201
|
+
that does not exist; the entries that pointed here are already marked
|
|
202
|
+
locked by the level that produced them */
|
|
105
203
|
end;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
204
|
+
else do;
|
|
205
|
+
/* strip any trailing separator, keeping / and drive roots intact */
|
|
206
|
+
do while(length(directory)>1);
|
|
207
|
+
if substr(directory,length(directory),1) not in ('/','\') then leave;
|
|
208
|
+
if length(directory)=3 and substr(directory,2,1)=':' then leave;
|
|
209
|
+
directory=substr(directory,1,length(directory)-1);
|
|
210
|
+
end;
|
|
211
|
+
sep=symget('mpsep');
|
|
212
|
+
if directory='/' or (length(directory)=3 and substr(directory,2,1)=':')
|
|
213
|
+
then prefix=directory;
|
|
214
|
+
else prefix=cats(directory,sep);
|
|
215
|
+
do i=1 to dnum(did);
|
|
216
|
+
fname=dread(did,i);
|
|
217
|
+
filename=fname;
|
|
218
|
+
filepath=cats(prefix,fname);
|
|
219
|
+
msg='';
|
|
220
|
+
ext='';
|
|
221
|
+
/* dopen alone is enough to tell a folder from anything else, and it
|
|
222
|
+
returns immediately for a fifo - fopen would block until a writer
|
|
223
|
+
appeared */
|
|
224
|
+
rc=filename("&fref2",filepath);
|
|
225
|
+
mid=dopen("&fref2");
|
|
226
|
+
if mid>0 then do;
|
|
227
|
+
file_or_folder='folder';
|
|
228
|
+
rc=dclose(mid);
|
|
229
|
+
end;
|
|
230
|
+
else do;
|
|
231
|
+
dmsg=sysmsg();
|
|
232
|
+
if index(dmsg,'is not a directory')>0 then do;
|
|
233
|
+
file_or_folder='file';
|
|
234
|
+
ext=prxchange('s/.*\.{1,1}(.*)/$1/',1,filename);
|
|
235
|
+
if filename=ext then ext=' ';
|
|
236
|
+
end;
|
|
237
|
+
else if index(dmsg,'uthorization')>0 then do;
|
|
238
|
+
/* present but not readable. It stays a file, as it was before the
|
|
239
|
+
entry test was fixed - the copy, hash and zip tools skip anything
|
|
240
|
+
that is not a file, and a backup that silently omits an unreadable
|
|
241
|
+
file is worse than one that fails on it */
|
|
242
|
+
file_or_folder='file';
|
|
243
|
+
ext=prxchange('s/.*\.{1,1}(.*)/$1/',1,filename);
|
|
244
|
+
if filename=ext then ext=' ';
|
|
245
|
+
msg=dmsg;
|
|
246
|
+
end;
|
|
247
|
+
else do;
|
|
248
|
+
/* listed but not openable at all - a broken link, for instance */
|
|
249
|
+
file_or_folder='locked';
|
|
250
|
+
msg=dmsg;
|
|
251
|
+
end;
|
|
252
|
+
end;
|
|
253
|
+
rc=filename("&fref2");
|
|
254
|
+
output;
|
|
255
|
+
end;
|
|
256
|
+
rc=dclose(did);
|
|
111
257
|
end;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
end;
|
|
115
|
-
else do;
|
|
116
|
-
msg=sysmsg();
|
|
117
|
-
put _all_;
|
|
118
|
-
stop;
|
|
119
|
-
end;
|
|
120
|
-
dnum = dnum(did);
|
|
121
|
-
do i = 1 to dnum;
|
|
122
|
-
filename = dread(did, i);
|
|
123
|
-
filepath=cats(directory,'/',filename);
|
|
124
|
-
rc = filename(fref2,filepath);
|
|
125
|
-
midd=dopen(fref2);
|
|
126
|
-
dmsg=sysmsg();
|
|
127
|
-
if did > 0 then file_or_folder='folder';
|
|
128
|
-
rc=dclose(midd);
|
|
129
|
-
midf=fopen(fref2);
|
|
130
|
-
fmsg=sysmsg();
|
|
131
|
-
if midf > 0 then file_or_folder='file';
|
|
132
|
-
rc=fclose(midf);
|
|
133
|
-
|
|
134
|
-
if index(fmsg,'File is in use') or index(dmsg,'is not a directory')
|
|
135
|
-
then file_or_folder='file';
|
|
136
|
-
else if index(fmsg,'Insufficient authorization') then file_or_folder='file';
|
|
137
|
-
else if file_or_folder='' then file_or_folder='locked';
|
|
258
|
+
rc=filename("&fref1");
|
|
259
|
+
run;
|
|
138
260
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
261
|
+
/* trim the level to what is left of the maxobs budget before appending */
|
|
262
|
+
%let total=%sysfunc(coalesce(%mf_nobs(&outds),0));
|
|
263
|
+
%let room=2147483647;
|
|
264
|
+
%if &maxobs>0 %then %let room=%eval(&maxobs-&total);
|
|
265
|
+
%if &room>0 %then %do;
|
|
266
|
+
data work.__mp_dirlist_level;
|
|
267
|
+
set work.__mp_dirlist_level(obs=&room);
|
|
268
|
+
run;
|
|
269
|
+
proc append base=&outds data=work.__mp_dirlist_level force nowarn;
|
|
270
|
+
run;
|
|
271
|
+
%end;
|
|
272
|
+
|
|
273
|
+
%let total=%sysfunc(coalesce(%mf_nobs(&outds),0));
|
|
274
|
+
%if &maxobs>0 and &total>=&maxobs %then %let done=1;
|
|
275
|
+
|
|
276
|
+
/* the folders of this level become the parents of the next one */
|
|
277
|
+
%let nfront=0;
|
|
278
|
+
%if &done=0 and &lvl<&maxdepth %then %do;
|
|
279
|
+
data work.__mp_dirlist_frontier;
|
|
280
|
+
set work.__mp_dirlist_level(where=(file_or_folder='folder'));
|
|
281
|
+
level=level+1;
|
|
282
|
+
keep filepath level;
|
|
283
|
+
run;
|
|
284
|
+
%let nfront=%sysfunc(coalesce(%mf_nobs(work.__mp_dirlist_frontier),0));
|
|
285
|
+
%end;
|
|
286
|
+
|
|
287
|
+
%let lvl=%eval(&lvl+1);
|
|
288
|
+
|
|
289
|
+
%end;
|
|
290
|
+
|
|
291
|
+
/* include the starting folder itself, when asked */
|
|
292
|
+
%if %substr(&showparent,1,1)=Y %then %do;
|
|
293
|
+
data work.__mp_dirlist_level;
|
|
294
|
+
length directory filepath $2000 file_or_folder $6 filename $255 ext $20
|
|
295
|
+
msg $200 level 8;
|
|
296
|
+
/* the parent is only listed when it can be opened, so a path that does
|
|
297
|
+
not exist stays an empty result even with showparent=YES */
|
|
298
|
+
filepath=symget('path');
|
|
299
|
+
rc=filename("&fref1",filepath);
|
|
300
|
+
did=dopen("&fref1");
|
|
301
|
+
if did>0 then rc=dclose(did);
|
|
302
|
+
rc=filename("&fref1");
|
|
303
|
+
if did=0 then stop;
|
|
304
|
+
directory=filepath;
|
|
305
|
+
do while(length(directory)>1);
|
|
306
|
+
if substr(directory,length(directory),1) not in ('/','\') then leave;
|
|
307
|
+
if length(directory)=3 and substr(directory,2,1)=':' then leave;
|
|
308
|
+
directory=substr(directory,1,length(directory)-1);
|
|
146
309
|
end;
|
|
147
|
-
output;
|
|
148
|
-
end;
|
|
149
|
-
rc = dclose(did);
|
|
150
|
-
%if &showparent=YES and &level=0 %then %do;
|
|
151
310
|
filepath=directory;
|
|
152
311
|
file_or_folder='folder';
|
|
153
312
|
ext='';
|
|
154
313
|
filename=scan(directory,-1,'/\');
|
|
155
314
|
msg='';
|
|
156
|
-
level
|
|
315
|
+
level=0;
|
|
157
316
|
output;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
run;
|
|
317
|
+
run;
|
|
318
|
+
proc append base=&outds data=work.__mp_dirlist_level force nowarn;
|
|
319
|
+
run;
|
|
320
|
+
%end;
|
|
161
321
|
|
|
162
322
|
%if %substr(&getattrs,1,1)=Y %then %do;
|
|
163
|
-
data &
|
|
164
|
-
set &
|
|
323
|
+
data &outds;
|
|
324
|
+
set &outds;
|
|
165
325
|
length infoname infoval $60 fref $8;
|
|
166
326
|
if _n_=1 then call missing(fref);
|
|
167
327
|
rc=filename(fref,filepath);
|
|
@@ -203,59 +363,20 @@ run;
|
|
|
203
363
|
run;
|
|
204
364
|
proc sort;
|
|
205
365
|
by filepath sasname;
|
|
206
|
-
proc transpose data=&
|
|
366
|
+
proc transpose data=&outds out=&outds(drop=_:);
|
|
207
367
|
id sasname;
|
|
208
368
|
var infoval;
|
|
209
369
|
by filepath file_or_folder filename ext ;
|
|
210
370
|
run;
|
|
211
371
|
%end;
|
|
212
372
|
|
|
213
|
-
data &
|
|
214
|
-
set &
|
|
373
|
+
data &outds;
|
|
374
|
+
set &outds(where=(filepath ne ''));
|
|
215
375
|
run;
|
|
216
376
|
|
|
217
|
-
/**
|
|
218
|
-
* The above transpose can mean that some updates create additional columns.
|
|
219
|
-
* This necessitates the occasional use of datastep over proc append.
|
|
220
|
-
*/
|
|
221
|
-
%if %mf_existds(&outds) %then %do;
|
|
222
|
-
%local basevars appvars newvars;
|
|
223
|
-
%let basevars=%mf_getvarlist(&outds);
|
|
224
|
-
%let appvars=%mf_getvarlist(&out_ds);
|
|
225
|
-
%let newvars=%length(%mf_wordsinstr1butnotstr2(Str1=&appvars,Str2=&basevars));
|
|
226
|
-
%if &newvars>0 %then %do;
|
|
227
|
-
data &outds;
|
|
228
|
-
set &outds &out_ds;
|
|
229
|
-
run;
|
|
230
|
-
%end;
|
|
231
|
-
%else %do;
|
|
232
|
-
proc append base=&outds data=&out_ds force nowarn;
|
|
233
|
-
run;
|
|
234
|
-
%end;
|
|
235
|
-
%end;
|
|
236
|
-
%else %do;
|
|
237
|
-
proc append base=&outds data=&out_ds;
|
|
238
|
-
run;
|
|
239
|
-
%end;
|
|
240
|
-
|
|
241
|
-
/* recursive call */
|
|
242
|
-
%if &maxdepth>&level or &maxdepth=MAX %then %do;
|
|
243
|
-
data _null_;
|
|
244
|
-
set &out_ds;
|
|
245
|
-
where file_or_folder='folder';
|
|
246
|
-
%if &showparent=YES and &level=0 %then %do;
|
|
247
|
-
if filepath ne directory;
|
|
248
|
-
%end;
|
|
249
|
-
length code $10000;
|
|
250
|
-
code=cats('%nrstr(%mp_dirlist(path=',filepath,",outds=&outds"
|
|
251
|
-
,",getattrs=&getattrs,level=%eval(&level+1),maxdepth=&maxdepth))");
|
|
252
|
-
put code=;
|
|
253
|
-
call execute(code);
|
|
254
|
-
run;
|
|
255
|
-
%end;
|
|
256
|
-
|
|
257
377
|
/* tidy up */
|
|
258
|
-
proc sql;
|
|
259
|
-
drop table
|
|
378
|
+
proc sql noprint;
|
|
379
|
+
drop table work.__mp_dirlist_frontier, work.__mp_dirlist_level;
|
|
380
|
+
quit;
|
|
260
381
|
|
|
261
382
|
%mend mp_dirlist;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Create a PDF report from a dataset using ODS
|
|
4
|
+
@details Renders a dataset as a paginated PDF with ODS PDF, so the output
|
|
5
|
+
carries real typesetting - proportional fonts, repeated column headers on
|
|
6
|
+
every page, titles, footnotes and page numbers - rather than a picture of a
|
|
7
|
+
grid. Values are printed through PROC PRINT, so SAS formats and labels are
|
|
8
|
+
applied to what the reader sees.
|
|
9
|
+
|
|
10
|
+
This is the server-side half of a download pair: send the result with
|
|
11
|
+
`mp_streamfile` using `contenttype=PDF`.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
|
|
15
|
+
filename mypdf temp;
|
|
16
|
+
%mp_ds2pdf(sashelp.class, outref=mypdf
|
|
17
|
+
,title=Class listing
|
|
18
|
+
,footnote=Class table - generated &sysdate9);
|
|
19
|
+
|
|
20
|
+
%mp_streamfile(contenttype=PDF,inref=mypdf,outname=class.pdf)
|
|
21
|
+
|
|
22
|
+
Handling of the ODS session: the macro opens its own PDF destination, sets
|
|
23
|
+
titles and footnotes for the duration of the report and clears them on the
|
|
24
|
+
way out, so its own text does not leak into whatever the caller prints next.
|
|
25
|
+
It does not save and restore the caller's titles, even though they can be
|
|
26
|
+
read: SASHELP.VTITLE holds the current lines (TYPE T and F). Re-emitting
|
|
27
|
+
them means rebuilding SAS statements out of free text that may contain
|
|
28
|
+
quotes, semicolons or macro triggers, which is a separate problem this macro
|
|
29
|
+
does not take on - so a caller that needs its own titles back after the
|
|
30
|
+
report should capture them from SASHELP.VTITLE and set them again.
|
|
31
|
+
|
|
32
|
+
The page numbers are written with the `(*ESC*)` inline-function prefix
|
|
33
|
+
rather than with an escape character, so the report does not depend on the
|
|
34
|
+
caller having run `ods escapechar=`.
|
|
35
|
+
|
|
36
|
+
@param [in] ds The dataset to print. A name without a libref is read from
|
|
37
|
+
WORK.
|
|
38
|
+
@param [out] outref= (pdfout) Fileref to contain the PDF. Assigned as a TEMP
|
|
39
|
+
file if it is not already allocated.
|
|
40
|
+
@param [in] title= Optional report title, printed on every page.
|
|
41
|
+
@param [in] footnote= Optional footnote text. The page number is appended to
|
|
42
|
+
it (see `pagenum=`), so pass the provenance here - dataset, filter, user,
|
|
43
|
+
timestamp - and leave the numbering to the macro.
|
|
44
|
+
@param [in] by= Optional space separated BY variables. Each BY group starts a
|
|
45
|
+
new page, so the data must already be sorted by those variables.
|
|
46
|
+
@param [in] maxobs= (0) Maximum number of observations to print. 0 prints
|
|
47
|
+
every observation. Use it to cap very large tables, and say so in
|
|
48
|
+
`footnote=` when a cap has been applied.
|
|
49
|
+
@param [in] options= Additional options for the ODS PDF statement, for
|
|
50
|
+
example `fontsize=9`. The statement always carries `notoc`.
|
|
51
|
+
@param [in] style= Optional ODS style. Left to the site default when blank.
|
|
52
|
+
@param [in] orientation= (LANDSCAPE) Page orientation, one of LANDSCAPE or
|
|
53
|
+
PORTRAIT. This is a SAS system option rather than an ODS PDF attribute, so
|
|
54
|
+
the previous setting is restored on the way out.
|
|
55
|
+
@param [in] pagenum= (PAGE) Numbering appended to the footnote. Supported
|
|
56
|
+
values:
|
|
57
|
+
@li PAGE - "Page n"
|
|
58
|
+
@li PAGEOF - "Page n of m"
|
|
59
|
+
@li NO - no page number
|
|
60
|
+
The numbers come from the ODS inline functions `{thispage}` and
|
|
61
|
+
`{lastpage}`, written behind the `(*ESC*)` prefix so no ODS ESCAPECHAR has
|
|
62
|
+
to be set. SAS documents `{lastpage}` as preproduction, and warns that
|
|
63
|
+
images and URL links can be dropped from a title or footnote that uses it -
|
|
64
|
+
this macro prints a table only, so the total is safe here, but that is why
|
|
65
|
+
it is not the default.
|
|
66
|
+
|
|
67
|
+
@return The PDF is written to `outref`. No dataset is created.
|
|
68
|
+
|
|
69
|
+
<h4> SAS Macros </h4>
|
|
70
|
+
@li mp_abort.sas
|
|
71
|
+
|
|
72
|
+
@author 4GL Apps Ltd
|
|
73
|
+
@copyright 4GL Apps Ltd. This code may only be used within Data Controller
|
|
74
|
+
and may not be re-distributed or re-sold without the express permission of
|
|
75
|
+
4GL Apps Ltd.
|
|
76
|
+
|
|
77
|
+
**/
|
|
78
|
+
|
|
79
|
+
%macro mp_ds2pdf(
|
|
80
|
+
ds
|
|
81
|
+
,outref=pdfout
|
|
82
|
+
,title=
|
|
83
|
+
,footnote=
|
|
84
|
+
,by=
|
|
85
|
+
,maxobs=0
|
|
86
|
+
,options=
|
|
87
|
+
,style=
|
|
88
|
+
,orientation=LANDSCAPE
|
|
89
|
+
,pagenum=PAGE
|
|
90
|
+
)/*/STORE SOURCE*/;
|
|
91
|
+
|
|
92
|
+
%local obsopt foot pagetxt odsopts prev_orient;
|
|
93
|
+
|
|
94
|
+
%if %index(&ds,.)=0 %then %let ds=WORK.&ds;
|
|
95
|
+
%let ds=%upcase(&ds);
|
|
96
|
+
%let pagenum=%upcase(&pagenum);
|
|
97
|
+
%let orientation=%upcase(&orientation);
|
|
98
|
+
|
|
99
|
+
%if %sysfunc(exist(&ds))=0 %then %do;
|
|
100
|
+
%mp_abort(
|
|
101
|
+
msg=Dataset &ds does not exist
|
|
102
|
+
,mac=&sysmacroname
|
|
103
|
+
)
|
|
104
|
+
%end;
|
|
105
|
+
|
|
106
|
+
/* the fileref is only assigned when the caller has not done so */
|
|
107
|
+
%if %sysfunc(fileref(&outref)) > 0 %then %do;
|
|
108
|
+
filename &outref temp;
|
|
109
|
+
%end;
|
|
110
|
+
|
|
111
|
+
%let obsopt=;
|
|
112
|
+
%if %eval(&maxobs)>0 %then %let obsopt=(obs=&maxobs);
|
|
113
|
+
|
|
114
|
+
/* the caller's footnote keeps its own text; numbering is appended to it.
|
|
115
|
+
(*ESC*) is used rather than an escape character so the inline functions work
|
|
116
|
+
without the caller having set ods escapechar. */
|
|
117
|
+
%if &pagenum=PAGE %then %let pagetxt=Page (*ESC*){thispage};
|
|
118
|
+
%else %if &pagenum=PAGEOF %then
|
|
119
|
+
%let pagetxt=Page (*ESC*){thispage} of (*ESC*){lastpage};
|
|
120
|
+
|
|
121
|
+
%let foot=&footnote;
|
|
122
|
+
%if %length(&pagetxt)>0 %then %do;
|
|
123
|
+
%if %length(&foot)>0 %then %let foot=&foot &pagetxt;
|
|
124
|
+
%else %let foot=&pagetxt;
|
|
125
|
+
%end;
|
|
126
|
+
|
|
127
|
+
%let odsopts=notoc;
|
|
128
|
+
%if %length(&options)>0 %then %let odsopts=&odsopts &options;
|
|
129
|
+
|
|
130
|
+
%let prev_orient=%sysfunc(getoption(orientation));
|
|
131
|
+
options orientation=&orientation;
|
|
132
|
+
|
|
133
|
+
ods pdf file=&outref &odsopts
|
|
134
|
+
%if %length(&style)>0 %then style=&style;;
|
|
135
|
+
|
|
136
|
+
/* each of these needs its own %do block: a bare "%then statement;" swallows
|
|
137
|
+
the semicolon as part of the %if, so the statements after it are read as a
|
|
138
|
+
continuation of the same statement */
|
|
139
|
+
%if %length(&title)>0 %then %do;
|
|
140
|
+
title "&title";
|
|
141
|
+
%end;
|
|
142
|
+
%if %length(&foot)>0 %then %do;
|
|
143
|
+
footnote "&foot";
|
|
144
|
+
%end;
|
|
145
|
+
|
|
146
|
+
proc print data=&ds&obsopt noobs;
|
|
147
|
+
%if %length(&by)>0 %then %do;
|
|
148
|
+
by &by;
|
|
149
|
+
%end;
|
|
150
|
+
run;
|
|
151
|
+
|
|
152
|
+
ods pdf close;
|
|
153
|
+
title;
|
|
154
|
+
footnote;
|
|
155
|
+
options orientation=&prev_orient;
|
|
156
|
+
|
|
157
|
+
%mend mp_ds2pdf;
|
|
@@ -59,7 +59,9 @@
|
|
|
59
59
|
@li file_hash - the hash output
|
|
60
60
|
@li hash_duration - how long the hash took (first hash always takes longer)
|
|
61
61
|
@li file_path - /full/path/to/each/file.ext
|
|
62
|
-
@li file_or_folder -
|
|
62
|
+
@li file_or_folder - "file", "folder", or "locked" for an entry that
|
|
63
|
+
is listed but cannot be opened at all (a broken link). The hash is
|
|
64
|
+
built from files, so a locked entry contributes no row
|
|
63
65
|
@li level - the depth of the directory (top level is 0)
|
|
64
66
|
|
|
65
67
|
@version 9.4m6
|
package/base/mp_streamfile.sas
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
@li CSV
|
|
18
18
|
@li EXCEL
|
|
19
19
|
@li MARKDOWN
|
|
20
|
+
@li PDF
|
|
20
21
|
@li TEXT
|
|
21
22
|
@li ZIP
|
|
22
23
|
Feel free to submit PRs to support more mime types! The official list is
|
|
@@ -181,6 +182,23 @@ run;
|
|
|
181
182
|
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
|
182
183
|
%end;
|
|
183
184
|
%end;
|
|
185
|
+
%else %if &contentype=PDF %then %do;
|
|
186
|
+
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
|
187
|
+
data _null_;
|
|
188
|
+
rc=stpsrv_header('Content-Type','application/pdf');
|
|
189
|
+
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
|
190
|
+
run;
|
|
191
|
+
%end;
|
|
192
|
+
%else %if &platform=SASVIYA %then %do;
|
|
193
|
+
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.pdf'
|
|
194
|
+
contenttype='application/pdf'
|
|
195
|
+
contentdisp="attachment; filename=&outname";
|
|
196
|
+
%end;
|
|
197
|
+
%else %if &platform=SASJS %then %do;
|
|
198
|
+
%mfs_httpheader(Content-Type,application/pdf)
|
|
199
|
+
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
|
200
|
+
%end;
|
|
201
|
+
%end;
|
|
184
202
|
%else %if &contentype=ZIP %then %do;
|
|
185
203
|
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
|
186
204
|
data _null_;
|
package/base/mp_validatecol.sas
CHANGED
|
@@ -34,6 +34,9 @@
|
|
|
34
34
|
@li ISNUM - checks if the variable is numeric
|
|
35
35
|
@li LIBDS - matches LIBREF.DATASET format
|
|
36
36
|
@li FORMAT - checks if the provided format is syntactically valid
|
|
37
|
+
@li ISPATH - checks that the value is an absolute path this platform would
|
|
38
|
+
accept. Shape only - whether the path exists is a different question
|
|
39
|
+
(mf_isdir / fileexist)
|
|
37
40
|
@param [out] outcol The variable to create, with the results of the match
|
|
38
41
|
|
|
39
42
|
<h4> SAS Macros </h4>
|
|
@@ -110,6 +113,38 @@
|
|
|
110
113
|
if prxmatch(&tempcol, trim(&incol)) then &outcol=1;
|
|
111
114
|
else &outcol=0;
|
|
112
115
|
%end;
|
|
116
|
+
%else %if &rule=ISPATH %then %do;
|
|
117
|
+
/*
|
|
118
|
+
An absolute path on the current platform. This is a shape check: a path
|
|
119
|
+
that passes may still not exist, and one that fails would be rejected by
|
|
120
|
+
the operating system rather than read as a folder.
|
|
121
|
+
*/
|
|
122
|
+
&outcol=0;
|
|
123
|
+
if length(trim(&incol))>0 and anycntrl(&incol)=0 then do;
|
|
124
|
+
%if "%upcase(&sysscp)"="WIN" or "%upcase(&sysscp)"="DNTHOST" %then %do;
|
|
125
|
+
/* a drive root (C:/folder) */
|
|
126
|
+
if substr(&incol,2,1)=':' and substr(&incol,3,1) in ('\','/') then
|
|
127
|
+
&outcol=1;
|
|
128
|
+
/* a UNC share needs both a host and a share - \\host\ is not openable */
|
|
129
|
+
if substr(&incol,1,2)='\\' and scan(&incol,2,'\') ne '' then
|
|
130
|
+
&outcol=1;
|
|
131
|
+
/* characters windows does not accept in a name, and a colon
|
|
132
|
+
anywhere but the drive separator */
|
|
133
|
+
if &outcol=1 then do;
|
|
134
|
+
if index(substr(&incol,3),':')>0 then &outcol=0;
|
|
135
|
+
if index(&incol,byte(34))>0 then &outcol=0;
|
|
136
|
+
if index(&incol,'<')>0 then &outcol=0;
|
|
137
|
+
if index(&incol,'>')>0 then &outcol=0;
|
|
138
|
+
if index(&incol,'|')>0 then &outcol=0;
|
|
139
|
+
if index(&incol,'?')>0 then &outcol=0;
|
|
140
|
+
if index(&incol,'*')>0 then &outcol=0;
|
|
141
|
+
end;
|
|
142
|
+
%end;
|
|
143
|
+
%else %do;
|
|
144
|
+
if substr(&incol,1,1)='/' then &outcol=1;
|
|
145
|
+
%end;
|
|
146
|
+
end;
|
|
147
|
+
%end;
|
|
113
148
|
%else %if &rule=FORMAT %then %do;
|
|
114
149
|
/* match valid SAS format*/
|
|
115
150
|
if _n_=1 then do;
|
package/package.json
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
ordinal_root num,
|
|
19
19
|
ordinal_items num,
|
|
20
20
|
version num,
|
|
21
|
-
id char(
|
|
22
|
-
name char(
|
|
21
|
+
id char(256),
|
|
22
|
+
name char(256),
|
|
23
23
|
providerId char(5),
|
|
24
24
|
implicit num
|
|
25
25
|
|
|
@@ -29,7 +29,11 @@
|
|
|
29
29
|
@param [in] grant_type= (sas_services)
|
|
30
30
|
valid values are "password" or "authorization_code" (unquoted).
|
|
31
31
|
@param [out] outds= (work.viyagroupmembers)
|
|
32
|
-
The library.dataset to be created that contains the list of
|
|
32
|
+
The library.dataset to be created that contains the list of members
|
|
33
|
+
|
|
34
|
+
id and name are declared at $256, the longest active directory can hold for
|
|
35
|
+
a display name or a SAM account name. The $43 they used to carry truncated
|
|
36
|
+
anything longer, and a truncation fails the step on some platforms.
|
|
33
37
|
|
|
34
38
|
|
|
35
39
|
@version VIYA V.03.04
|
|
@@ -85,7 +89,7 @@ run;
|
|
|
85
89
|
%if &SYS_PROCHTTP_STATUS_CODE=404 %then %do;
|
|
86
90
|
%put NOTE: Group &group not found!!;
|
|
87
91
|
data &outds;
|
|
88
|
-
length id name $
|
|
92
|
+
length id name $256;
|
|
89
93
|
call missing(of _all_);
|
|
90
94
|
run;
|
|
91
95
|
%end;
|
|
@@ -96,8 +100,14 @@ run;
|
|
|
96
100
|
)
|
|
97
101
|
%let libref1=%mf_getuniquelibref();
|
|
98
102
|
libname &libref1 JSON fileref=&fname1;
|
|
103
|
+
/* id and name have to be declared, as a group with no members returns no
|
|
104
|
+
such columns to rename. $256 is the longest active directory can hold for
|
|
105
|
+
a display name or a SAM account name: the JSON engine sizes the columns to
|
|
106
|
+
the longest value in the payload, so a shorter declaration truncates the
|
|
107
|
+
name and fails the step with "Multiple lengths were specified for the
|
|
108
|
+
variable ... by input data set(s)". */
|
|
99
109
|
data &outds;
|
|
100
|
-
length id name $
|
|
110
|
+
length id name $256;
|
|
101
111
|
set &libref1..items;
|
|
102
112
|
run;
|
|
103
113
|
libname &libref1 clear;
|