SASUnit Examples  Version 1.5.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  %let search = %qscan(&l_i_path.,-1,'/');
47  %let k = %index(&l_i_path.,%qtrim(&search.));
48  %let path = %qsubstr(&l_i_path.,1,%eval(&k.-2));
49  %if %qsubstr(&path.,1,1) eq %str(%') %then
50  %let path = &path.%str(%');
51  %if %qsubstr(&path.,1,1) eq %str(%") %then
52  %let path = &path.%str(%");
53 
54  %SYSEXEC(find -L &path. ! -name &path -name "&search." -ls -type f > &dirfile.);
55 
56  %if &g_verbose. %then %do;
57  %put ======== OS Command Start ========;
58  /* Evaluate sysexec´s return code */
59  %if &sysrc. = 0 %then %put &g_note.(SASUNIT): Sysrc : 0 -> SYSEXEC SUCCESSFUL;
60  %else %put &g_error.(SASUNIT): Sysrc : &sysrc -> An Error occured;
61 
62  /* put sysexec command to log*/
63  %put &g_note.(SASUNIT): SYSEXEC COMMAND IS: find -L &path. ! -name &path -name "&search." -ls -type f > &dirfile.;
64 
65  /* write &dirfile to the log*/
66  data _null_;
67  infile "&dirfile" truncover lrecl=512;
68  input line $512.;
69  putlog line;
70  run;
71  %put ======== OS Command End ========;
72  %end;
73 
74  data &o_out (keep=membername filename changed );
75  array dum{7} $;
76  array dat{3} $;
77  length filename membername $255
78  temp_path temp_file $255
79  fileall $1024
80  ;
81  format changed datetime20.;
82  infile _dirfile delimiter=' ' truncover;
83  input dum1-dum7 $ dat1-dat3 $ fileall $;
84  filename = fileall;
85  if substr(dum3,1,1)='d' then delete;
86  if index(dat3,':') gt 0 then do;
87  changed = input(compress(dat2 || dat1 || year(today())) || " " || dat3, datetime.);
88  if datepart(changed) gt today() then do;
89  changed = input(compress(dat2 || dat1 || year(today())-1) || " " || dat3, datetime.);
90  end;
91  end;
92  else do;
93  changed =input(compress( dat2 || dat1 || dat3) || " 00:00", datetime.);
94  end;
95  loca = length(filename) - length(scan(filename,-1,'/')) + 1;
96  membername = substr(filename,loca);
97 
98  %if &i_recursive=0 %then %do;
99  temp_path = dequote("&path");
100  temp_file = scan(filename,-1,"/");
101  if (trim(temp_path) !! "/" !! trim(temp_file) = filename) then output;
102  %end;
103  run;
104 
105 %errexit:
106 %MEND _dir;