本文介绍了Unix / SAS上的文件修改日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 下面是DATA SET步骤的幌子。 我从一个共同的前缀开始的目录中获取文件。 为了这个调试程序,假设前缀为'test'。 所以我们得到了如test_abc.txt,test_123.txt等文件。 做是提取每个文件的最后修改时间。 由于我在Unix系统下,我使用以下foo pipels -o -g --full-time ...来获取我们感兴趣的时间。 在work.tempo中,我希望得到一个名称为filename(vname)和相应的修改日期(mod_datec)的表。 data work.tempo; 长度vname $ 256; rc = dopen(& directory); vmax = dnum(rc); select(& countryname); 当(法国)做; do i = 1 to vmax; vname = dread(rc,i); 如果vname =:&前缀。 然后做; filename foo pipels -g -o --full-time〜/& prefix。*; data _null_; infile foo; input @ 15 mod_date $ 11; 如果mod_date =则停止; mod_datec = scan(mod_date,1, - ) || scan(mod_date,2, - ) || scan(mod_date,3, - ); put mod_datec =; 运行; / *我想从这里输出mod_datec到work.tempo * / end; 结束结束 否则; 结束 rc = dclose(rc); 运行; %mend; %宇宙(地球,法国,测试); 解决方案我已经复制了OP的答案(这是错误的嵌入问题): 我已经解决了这一个。以下是代码 %macro universe(); filename foo pipe ls -g -o -G -l - 空时测试* | awk'{print $ 4,$ 5,$ 7} data mod_date(keep = vname vdate); infile foo; input @ 1 mod_date $ 10。 @ 12希望$ 8。 @ 92 vname $ 18; mod_datec = scan(mod_date,1, - ) || scan(mod_date,2, - ) || scan(mod_date,3, ); heuresc = scan(heures,1,:) || scan(heures,2,:) || scan(heures,3,:); vdate = strip(mod_datec)|| strip(heuresc); 运行; %修补宇宙; %universe(); Voilà,我终于提取了文件名和相应的最后修改日期。我希望对任何人也是有用的。 Below is the guise of the DATA SET step. I got files in a directory which start with a common prefix. For the sake of this debugging program, let's say the prefix is 'test'. So we got files like test_abc.txt, test_123.txt and so on.What we want to do is to extract the last modified time of each file.Since I am under Unix system, I use the following "foo pipe 'ls -o -g --full-time ...'" to get the time which we are interested in.In work.tempo, I wish to get a table with a list of filename(vname) and the corresponding modification date (mod_datec).Voilà le souci, je vous remercie! %macro universe(directory, countryname, prefix); data work.tempo; length vname $256.; rc = dopen(&directory); vmax = dnum(rc); select("&countryname"); when ("France") do; do i = 1 to vmax; vname = dread(rc,i); if vname=:"&prefix." then do; filename foo pipe "ls -g -o --full-time ~/&prefix.*"; data _null_; infile foo; input @15 mod_date $11.; if mod_date=" " then stop; mod_datec = scan(mod_date,1,"-") ||scan(mod_date,2,"-") ||scan(mod_date,3,"-"); put mod_datec= ; run; /*I want to output mod_datec to work.tempo from here*/ end; end; end; otherwise; end; rc = dclose(rc); run; %mend; %universe(Earth, France, test); 解决方案 I've copied the OP's answer (which is incorrectly embedded in the question): I've resolved this one. Below is the code%macro universe(); filename foo pipe "ls -g -o -G -l --full-time test* | awk '{print $4, $5, $7}'"; data mod_date (keep = vname vdate); infile foo; input @1 mod_date $10. @12 heures $8. @92 vname $18.; mod_datec = scan(mod_date,1,"-") ||scan(mod_date,2,"-") ||scan(mod_date,3,"-"); heuresc = scan(heures,1,":") ||scan(heures,2,":") ||scan(heures,3,":"); vdate = strip(mod_datec)||strip(heuresc); run;%mend universe;%universe();Voilà, I finally got to extract the filename and the corresponding last modification date. I hope it'll be useful to anyone else too 这篇关于Unix / SAS上的文件修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-15 21:20