SASUnit Examples  Version 1.3.0
windows/_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 dirindicator_en dirindicator_de encoding s dirfile xwait xsync xmin l_i_path;
34  %let dirindicator_en=Directory of;
35  %let dirindicator_de=Verzeichnis von;
36  %let encoding=pcoem850;
37  %let l_i_path = %sysfunc(translate(&i_path,\,/));
38 
39  proc sql noprint;
40  create table &o_out (filename char(255));
41  quit;
42  %IF &syserr NE 0 %THEN %GOTO errexit;
43 
44  %let xwait=%sysfunc(getoption(xwait));
45  %let xsync=%sysfunc(getoption(xsync));
46  %let xmin =%sysfunc(getoption(xmin));
47 
48  options noxwait xsync xmin;
49 
50  %let dirfile=%sysfunc(pathname(work))\___dir.txt;
51  filename _dirfile "&dirfile" encoding=&encoding;
52 
53  %put &g_note.(SASUNIT): Directory search is: &i_path;
54 
55  %IF &i_recursive %then %let s=/S;
56 
57  %SYSEXEC(dir &s /a-d "&l_i_path" > "&dirfile");
58 
59  options &xwait &xsync &xmin;
60 
61  data &o_out (keep=filename changed);
62  length dir filename $255 language $2;
63  retain language "__" dir FilePos;
64  infile _dirfile truncover;
65  input line $char255. @;
66  if index (line, "&dirindicator_en") or index (line, "&dirindicator_de") then do;
67  if index (line, "&dirindicator_en") then do;
68  dir = substr(line, index (line, "&dirindicator_en")+length("&dirindicator_en")+1);
69  end;
70  else do;
71  dir = substr(line, index (line, "&dirindicator_de")+length("&dirindicator_de")+1);
72  end;
73  end;
74  if substr(line,1,1) ne ' ' then do;
75  * Check for presence of AM/PM in time value, because you can specify AM/PM timeformat in German Windows *;
76  if (language = "__") then do;
77  Detect_AM_PM = upcase (scan (line, 3, " "));
78  if (Detect_AM_PM in ("AM", "PM")) then do;
79  Filenamepart = scan (line,5, " ");
80  Filepos = index (line, trim(Filenamepart));
81  language = "EN";
82  end;
83  else do;
84  Filenamepart = scan (line,4, " ");
85  Filepos = index (line, trim(Filenamepart));
86  language = "DE";
87  end;
88  end;
89  if language='DE' then do;
90  input @1
91  d ddmmyy10. +2
92  t time5.
93  ;
94  end;
95  else do;
96  input @1
97  d mmddyy10. +2
98  t time9.
99  ;
100  end;
101  changed = dhms (d, hour(t), minute(t), 0);
102  format changed datetime20.;
103  filename = translate(trim(dir) !! '/' !! substr (line,FilePos),'/','\');
104  output;
105  end;
106  run;
107 
108  filename _dirfile;
109 
110 %errexit:
111 %MEND _dir;