SASUnit Examples  Version 1.3.0
unix_aix/_dir.sas
Go to the documentation of this file.
1 
24 %MACRO _dir(i_path=
25  ,i_recursive=0
26  ,o_out=dir
27  );
28 
29  %LOCAL dirfile encoding s l_i_path;
30 
31  proc sql noprint;
32  create table &o_out (filename char(255));
33  quit;
34 
35  %IF (not %sysfunc (exist (&o_out))) %THEN %GOTO errexit;
36 
37  %let encoding=pcoem850;
38  %let s =;
39  %let dirfile=%sysfunc(pathname(work))/&o_out..dir.txt;
40  filename _dirfile "&dirfile" encoding=&encoding;
41 
42  %put &g_note.(SASUNIT): Directory search is: &i_path;
43 
44  %let l_i_path=%qsysfunc(tranwrd(&i_path, %str( ), %str(\ )));
45 
46  %IF &i_recursive=0 %then
47  %let s = -prune;
48 
49  %let search = %qscan(&l_i_path.,-1,'/');
50  %let k = %index(&l_i_path.,%qtrim(&search.));
51  %let path = %qsubstr(&l_i_path.,1,%eval(&k.-2));
52  %if %qsubstr(&path.,1,1) eq %str(%') %then
53  %let path = &path.%str(%');
54  %if %qsubstr(&path.,1,1) eq %str(%") %then
55  %let path = &path.%str(%");
56 
57  %SYSEXEC(find &path. -name "&search." -ls &s. -type f > &dirfile.);
58 
59  data &o_out (keep=filename changed);
60  array dum{7} $;
61  array dat{3} $;
62  length filename $255
63  fileall $1024
64  ;
65  format changed datetime20.;
66  infile _dirfile delimiter=' ' truncover;
67  input dum1-dum7 $ dat1-dat3 $ fileall $;
68  filename = fileall;
69  if substr(dum3,1,1)='d' then delete;
70  if index(dat3,':') gt 0 then do;
71  changed = input(compress(dat2 || dat1 || year(today())) || " " || dat3, datetime.);
72  if changed gt today() then do;
73  changed = input(compress(dat2 || dat1 || year(today())-1) || " " || dat3, datetime.);
74  end;
75  end;
76  else do;
77  changed =input(compress( dat2 || dat1 || dat3) || " 00:00", datetime.);
78  end;
79  run;
80 
81 %errexit:
82 %MEND _dir;