SASUnit Examples  Version 1.5.0
linux/_dir.sas
Go to the documentation of this file.
1 
28 %MACRO _dir (i_path=
29  ,i_recursive=0
30  ,o_out=dir
31  );
32 
33  %LOCAL dirfile encoding s l_i_path;
34 
35  data &o_out ;
36  length filename $255;
37  format changed datetime20.;
38  run;
39 
40  %IF &syserr NE 0 %THEN %GOTO errexit;
41 
42  %LET encoding=wlatin1;
43  %LET dirfile=%sysfunc(pathname(work))/.dir.txt;
44  filename _dirfile "&dirfile" encoding=&encoding;
45 
46  %put &g_note.(SASUNIT): Directory search is: &i_path;
47 
48  %let l_i_path=%qsysfunc(tranwrd(&i_path, %str( ), %str(\ )));
49  %IF &i_recursive=0 %then %let s=-maxdepth 1;
50  %SYSEXEC(find -P &l_i_path. &s. -type f -printf "%nrstr(%h/%f\t%TD\t%TT\t\r\n)" > &dirfile. 2>/dev/null);
51 
52  %if &g_verbose. %then %do;
53  %put ======== OS Command Start ========;
54  /* Evaluate sysexec´s return code */
55  %if &sysrc. = 0 %then %put &g_note.(SASUNIT): Sysrc : 0 -> SYSEXEC SUCCESSFUL;
56  %else %put &g_error.(SASUNIT): Sysrc : &sysrc -> An Error occured;
57 
58  /* put sysexec command to log*/
59  %put &g_note.(SASUNIT): SYSEXEC COMMAND IS: find -P &l_i_path. &s. -type f -printf "%nrstr(%h/%f\t%TD\t%TT\t\r\n)" > &dirfile. 2>/dev/null;
60 
61  /* write &dirfile to the log*/
62  data _null_;
63  infile "&dirfile" truncover lrecl=512;
64  input line $512.;
65  putlog line;
66  run;
67  %put ======== OS Command End ========;
68  %end;
69 
70  data &o_out. (keep=membername filename changed);
71  length membername filename $255;
72  format changed datetime20.;
73  infile _dirfile delimiter='09'x truncover;
74  input filename $ d:mmddyy8. t:time8.;
75  changed = dhms (d, hour(t), minute(t), 0);
76  loca = length(filename) - length(scan(filename,-1,'/')) + 1;
77  membername = substr(filename,loca);
78  run;
79 
80  proc sort data=&o_out.;
81  by filename;
82  run;
83 
84 %errexit:
85 %MEND _dir;