@sasjs/core 2.50.0 → 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.
Files changed (2) hide show
  1. package/base/mp_dirlist.sas +61 -18
  2. package/package.json +1 -1
@@ -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;
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "^2.39.0"
37
37
  },
38
- "version": "2.50.0"
38
+ "version": "2.51.0"
39
39
  }