71%macro mp_hashdirectory(inloc,
72 outds=work.mp_hashdirectory,
78%local curlevel tempds maxlevel;
80%
if not(%eval(%unquote(&iftrue))) %then %
return;
83%mp_dirlist(path=&inloc, outds=&outds, maxdepth=&maxdepth, showparent=YES)
87 set &outds (rename=(filepath=file_path));
88 length FILE_HASH $32 HASH_DURATION 8;
89 keep directory file_hash hash_duration file_path file_or_folder level;
92 if file_or_folder=
'file' then
do;
95 drop fname val fid is_empty;
96 rc=filename(fname,file_path);
100 is_empty=fget(fid,val);
104 if is_empty ne 0 then delete;
105 else file_hash=hashing_file(
"&method",cats(file_path),0);
107 hash_duration=datetime()-ts;
110proc sort data=&outds ;
111 by descending level directory file_path;
117 call symputx(
'maxlevel',level,
'l');
122%
do curlevel=&maxlevel %to 0 %by -1;
123 data work._data_ (keep=directory file_hash);
125 where level=&curlevel;
126 by descending level directory file_path;
127 length str $32767 tmp_hash $32;
128 retain str tmp_hash ;
130 if first.directory then
do;
137 str=cats(str,file_hash);
138 if mod(i,100)=0 or last.directory then
do;
139 tmp_hash=hashing(
"&method",cats(tmp_hash,str));
143 if last.directory then
do;
147 if last.level then stop;
149 %let tempds=&syslast;
151 proc sql undo_policy=none;
152 create table &outds as
154 ,coalesce(b.file_hash,a.file_hash) as file_hash
161 on a.file_path=b.directory
162 order by level desc, directory, file_path;
166%mend mp_hashdirectory;