@sasjs/core 4.39.0 → 4.40.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
@@ -237,6 +237,7 @@ If you find this library useful, please leave a [star](https://github.com/sasjs/
237
237
 
238
238
  The following repositories are also worth checking out:
239
239
 
240
+ * [xieliaing/SAS](https://github.com/xieliaing/SAS)
240
241
  * [SASJedi/sas-macros](https://github.com/SASJedi/sas-macros)
241
242
  * [chris-swenson/sasmacros](https://github.com/chris-swenson/sasmacros)
242
243
  * [greg-wotton/sas-programs](https://github.com/greg-wootton/sas-programs)
@@ -27,6 +27,9 @@
27
27
  @param [in] maxdepth= (0) Set to a positive integer to indicate the level of
28
28
  subdirectory scan recursion - eg 3, to go `./3/levels/deep`. For unlimited
29
29
  recursion, set to MAX.
30
+ @param [in] showparent= (NO) By default, the initial parent directory is not
31
+ part of the results. Set to YES to include it. For this record only,
32
+ directory=filepath.
30
33
  @param [out] outds= (work.mp_dirlist) The output dataset to create
31
34
  @param [out] getattrs= (NO) If getattrs=YES then the doptname / foptname
32
35
  functions are used to scan all properties - any characters that are not
@@ -63,6 +66,7 @@
63
66
  , fref=0
64
67
  , outds=work.mp_dirlist
65
68
  , getattrs=NO
69
+ , showparent=NO
66
70
  , maxdepth=0
67
71
  , level=0 /* The level of recursion to perform. For internal use only. */
68
72
  )/*/STORE SOURCE*/;
@@ -145,6 +149,15 @@ data &out_ds(compress=no
145
149
  output;
146
150
  end;
147
151
  rc = dclose(did);
152
+ %if &showparent=YES and &level=0 %then %do;
153
+ filepath=directory;
154
+ file_or_folder='folder';
155
+ ext='';
156
+ filename=scan(directory,-1,'/\');
157
+ msg='';
158
+ level=&level;
159
+ output;
160
+ %end;
148
161
  stop;
149
162
  run;
150
163
 
@@ -232,6 +245,9 @@ run;
232
245
  data _null_;
233
246
  set &out_ds;
234
247
  where file_or_folder='folder';
248
+ %if &showparent=YES and &level=0 %then %do;
249
+ if filepath ne directory;
250
+ %end;
235
251
  length code $10000;
236
252
  code=cats('%nrstr(%mp_dirlist(path=',filepath,",outds=&outds"
237
253
  ,",getattrs=&getattrs,level=%eval(&level+1),maxdepth=&maxdepth))");
package/base/mp_ds2md.sas CHANGED
@@ -92,7 +92,7 @@ data _null_;
92
92
  run;
93
93
 
94
94
  %if %upcase(&showlog)=YES %then %do;
95
- options ps=max;
95
+ options ps=max lrecl=max;
96
96
  data _null_;
97
97
  infile &outref;
98
98
  input;
@@ -100,4 +100,4 @@ run;
100
100
  run;
101
101
  %end;
102
102
 
103
- %mend mp_ds2md;
103
+ %mend mp_ds2md;
@@ -11,7 +11,7 @@
11
11
  put hashkey=;
12
12
  run;
13
13
 
14
- ![sas md5 hash dataset log results](https://i.imgur.com/MqF98vk.png)
14
+ ![sas md5 hash dataset log results](https://i.4gl.io/1/KorUKoyE05.png/raw)
15
15
 
16
16
  <h4> SAS Macros </h4>
17
17
  @li mf_getattrn.sas
@@ -21,11 +21,12 @@
21
21
 
22
22
  <h4> Related Files </h4>
23
23
  @li mp_hashdataset.test.sas
24
+ @li mp_hashdirectory.sas
24
25
 
25
26
  @param [in] libds dataset to hash
26
27
  @param [in] salt= Provide a salt (could be, for instance, the dataset name)
27
- @param [in] iftrue= A condition under which the macro should be executed.
28
- @param [out] outds= (work.mf_hashdataset) The output dataset to create. This
28
+ @param [in] iftrue= (1=1) A condition under which the macro should be executed
29
+ @param [out] outds= (work._data_) The output dataset to create. This
29
30
  will contain one column (hashkey) with one observation (a $hex32.
30
31
  representation of the input hash)
31
32
  |hashkey:$32.|
@@ -0,0 +1,149 @@
1
+ /**
2
+ @file
3
+ @brief Returns a unique hash for each file in a directory
4
+ @details Hashes each file in each directory, and then hashes the hashes to
5
+ create a hash for each directory also.
6
+
7
+ This makes use of the new `hashing_file()` and `hashing` functions, available
8
+ since 9.4m6. Interestingly, these can even be used in pure macro, eg:
9
+
10
+ %put %sysfunc(hashing_file(md5,/path/to/file.blob,0));
11
+
12
+ Usage:
13
+
14
+ %let fpath=/some/directory;
15
+
16
+ %mp_hashdirectory(&fpath,outds=myhash,maxdepth=2)
17
+
18
+ data _null_;
19
+ set work.myhash;
20
+ put (_all_)(=);
21
+ run;
22
+
23
+ Whilst files are hashed in their entirety, the logic for creating a folder
24
+ hash is as follows:
25
+
26
+ @li Sort the files by filename (case sensitive, uppercase then lower)
27
+ @li Take the first 100 hashes, concatenate and hash
28
+ @li Concatenate this hash with another 100 hashes and hash again
29
+ @li Continue until the end of the folder. This is the folder hash
30
+ @li If a folder contains other folders, start from the bottom of the tree -
31
+ the folder hashes cascade upwards so you know immediately if there is a
32
+ change in a sub/sub directory
33
+ @li If the folder has no content (empty) then it is ignored. No hash created.
34
+
35
+ <h4> SAS Macros </h4>
36
+ @li mp_dirlist.sas
37
+
38
+ <h4> Related Files </h4>
39
+ @li mp_hashdataset.sas
40
+ @li mp_hashdirectory.test.sas
41
+ @li mp_md5.sas
42
+
43
+ @param [in] inloc Full filepath of the file to be hashed (unquoted)
44
+ @param [in] iftrue= (1=1) A condition under which the macro should be executed
45
+ @param [in] maxdepth= (0) Set to a positive integer to indicate the level of
46
+ subdirectory scan recursion - eg 3, to go `./3/levels/deep`. For unlimited
47
+ recursion, set to MAX.
48
+ @param [in] method= (MD5) the hashing method to use. Available options:
49
+ @li MD5
50
+ @li SH1
51
+ @li SHA256
52
+ @li SHA384
53
+ @li SHA512
54
+ @li CRC32
55
+ @param [out] outds= (work.mp_hashdirectory) The output dataset. Contains:
56
+ @li directory - the parent folder
57
+ @li file_hash - the hash output
58
+ @li hash_duration - how long the hash took (first hash always takes longer)
59
+ @li file_path - /full/path/to/each/file.ext
60
+ @li file_or_folder - contains either "file" or "folder"
61
+ @li level - the depth of the directory (top level is 0)
62
+
63
+ @version 9.4m6
64
+ @author Allan Bowe
65
+ **/
66
+
67
+ %macro mp_hashdirectory(inloc,
68
+ outds=work.mp_hashdirectory,
69
+ method=MD5,
70
+ maxdepth=0,
71
+ iftrue=%str(1=1)
72
+ )/*/STORE SOURCE*/;
73
+
74
+ %local curlevel tempds ;
75
+
76
+ %if not(%eval(%unquote(&iftrue))) %then %return;
77
+
78
+ /* get the directory listing */
79
+ %mp_dirlist(path=&inloc, outds=&outds, maxdepth=&maxdepth, showparent=YES)
80
+
81
+ /* create the hashes */
82
+ data &outds;
83
+ set &outds (rename=(filepath=file_path));
84
+ length FILE_HASH $32 HASH_DURATION 8;
85
+ keep directory file_hash hash_duration file_path file_or_folder level;
86
+
87
+ ts=datetime();
88
+ if file_or_folder='file' then do;
89
+ file_hash=hashing_file("&method",cats(file_path),0);
90
+ end;
91
+ hash_duration=datetime()-ts;
92
+ run;
93
+
94
+ proc sort data=&outds ;
95
+ by descending level directory file_path;
96
+ run;
97
+
98
+ data _null_;
99
+ set &outds;
100
+ call symputx('maxlevel',level,'l');
101
+ stop;
102
+ run;
103
+
104
+ /* now hash the hashes to populate folder hashes, starting from the bottom */
105
+ %do curlevel=&maxlevel %to 0 %by -1;
106
+ data work._data_ (keep=directory file_hash);
107
+ set &outds;
108
+ where level=&curlevel;
109
+ by descending level directory file_path;
110
+ length str $32767 tmp_hash $32;
111
+ retain str tmp_hash ;
112
+ /* reset vars when starting a new directory */
113
+ if first.directory then do;
114
+ str='';
115
+ tmp_hash='';
116
+ i=0;
117
+ end;
118
+ /* hash each chunk of 100 file paths */
119
+ i+1;
120
+ str=cats(str,file_hash);
121
+ if mod(i,100)=0 or last.directory then do;
122
+ tmp_hash=hashing("&method",cats(tmp_hash,str));
123
+ str='';
124
+ end;
125
+ /* output the hash at directory level */
126
+ if last.directory then do;
127
+ file_hash=tmp_hash;
128
+ output;
129
+ end;
130
+ if last.level then stop;
131
+ run;
132
+ %let tempds=&syslast;
133
+ /* join the hash back into the main table */
134
+ proc sql undo_policy=none;
135
+ create table &outds as
136
+ select a.directory
137
+ ,coalesce(b.file_hash,a.file_hash) as file_hash
138
+ ,a.hash_duration
139
+ ,a.file_path
140
+ ,a.file_or_folder
141
+ ,a.level
142
+ from &outds a
143
+ left join &tempds b
144
+ on a.file_path=b.directory
145
+ order by level desc, directory, file_path;
146
+ drop table &tempds;
147
+ %end;
148
+
149
+ %mend mp_hashdirectory;
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.13.0"
37
37
  },
38
- "version": "4.39.0"
38
+ "version": "4.40.0"
39
39
  }