これは、Windows ベースのディレクトリ リストを sas データ セットにプルする簡単なマクロです。
%macro DirList(dir);
/* %if &SUBDIR eq %then %let subdir=/s; */ /*** &SUBDIR が定義されていません ****/
filename dirpipe pipe "dir &DIR.\*.* /s /-c";
data dir_list(label="ディレクトリ一覧 [&DIR.]" drop=re_: _line_ date time);
形式パス
ファイル $250。
ModDT datetime19.
サイズ16。
_line_ $32000. ;
_N_ = 1 の場合は実行します。
re_path=prxparse("/(.+)のディレクトリ/");
re_subd=prxparse("/(\d\d\/\d\d\/\d\d\d\d)\s+(\d\d:\d\d [A|P]M)\s+\ s+(\S.*)/");
re_file=prxparse("/(\d\d\/\d\d\/\d\d\d\d)\s+(\d\d:\d\d [A|P]M)\s+( \d+)\s+(\S.*)/");
re_: パスを保持します。
終わり;
infile dirpipe lrecl=32000; 入力; _line_ = _infile_;
lengthn(_line_)=0 の場合は削除します。
そうしないと
if prxmatch(re_path, _line_) then do;
パス = prxposn(re_path, 1, _line_);
終わり;
そうしないと
if prxmatch(re_subd, _line_) then do;
date=input(prxposn(re_subd, 1, _line_), mmddyy10.);
time=input(prxposn(re_subd, 2, _line_), time6.);
ModDT=dhms(日付, 0, 0, 時間);
File=prxposn(re_subd, 3, _line_);
サイズ = .D; /*サブディレクトリのレコードをマーク*/
ファイルが ('.', '..') にない場合、出力します。
終わり;
そうしないと
if prxmatch(re_file, _line_) then do;
date=input(prxposn(re_file, 1, _line_), mmddyy10.);
time=input(prxposn(re_file, 2, _line_), time6.);
ModDT=dhms(日付, 0, 0, 時間);
size=input(prxposn(re_file, 3, _line_), 16.);
file=prxposn(re_file, 4, _line_);
出力;
終わり;
走る;
ファイル名 dirpipe クリア;
%繕う;
そして、これが彼らが呼ばれる方法です
%dirlist(c:);
%dirlist(c:\temp);
ベース ディレクトリを指定する場合、末尾のバックスラッシュがないことに注意してください。C:
ありませんC:\
。