如何从带有 sas 宏的文件夹中选取最新一周的文件?
我需要从文件夹中选择最新的一周文件,但我不想每次都输入一周。这是一份每周报告,我想让它像按 F3 并运行它一样简单。
eg. sales_data_201123
sales_data_201124
等等。在上面的示例中,应选择 sales_data_201124
,因为它是最新的。
请指教! 拉詹斯
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 latest one.
Please advise!
Rajans
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以解决这个问题。一种方法是查找特定文件 - 例如,使用
today()
函数结合intnx()
来计算您要查找的文件的名称。正在查找然后打开该文件。然而,我认为一种更简单的方法是将目录中的所有文件名读取到一个数据集中:
然后只需对 fnames 进行排序并选择最后一个,或者更好的是,使用 proc sql 将文件名放入宏变量中:
现在可以使用
&fname
调用要打开的文件。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 withintnx()
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:
Then just sort
fnames
and choose the last one, or better yet, useproc sql
to put the filename into a macro variable:The file you want to open can now be called with
&fname
.