开发者

How can I pick the latest week file from a folder with sas macro?

I need to pick the latest week file from a folder, but I don't want to enter the week every time. It's a weekly report which I want to make as easy as pressing F3 and having it run.

eg. sales_data_201123
    sales_data_201124

and so on. In the above example, sales_data_201124 should be selected since it's the l开发者_如何学运维atest one.

Please advise! Rajans


There are a few ways you could approach this. One would be to look for a specific file -- for example, use the today() function combined with intnx() to calculate what is the name of the file you're looking for and then open that file.

I think an easier approach, however, would be to read all the file names in the directory into a data set:

filename fnames pipe 'dir c:\temp\* /b';

data fnames;
  infile fnames pad missover;
  input @1 filename $255.;
  dt=scan(filename,3,'_');
run;

Then just sort fnames and choose the last one, or better yet, use proc sql to put the filename into a macro variable:

proc sql noprint;
  select filename into :fname
  from fnames
  having dt=max(dt);
quit;

The file you want to open can now be called with &fname.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜