【发布时间】:2021-09-14 13:04:49
【问题描述】:
假设我有一个库save,其中包含每日文件thefile_dly_yyyymmdd,
例如save.thefile_dly_20150831, save.thefile_dly_20150901, ... , save.thefile_dly_20210731.
我想对该库中的历史数据进行一些操作,但是,我只想提取特定日期之间的文件,并且只想保留与每个月的最后一个文件对应的文件,例如我要提取save.thefile_dly_20150831、save.thefile_dly_20150930、save.thefile_dly_20151031等
类似于以下内容。
%macro loop_through(start,end);
%do i = &start. %to &end.;
%if %sysunc(exist(SAVE.THEFILE_DLY_&i.)) %then %do;
/* Do some data processing on the file */
%end;
%end;
%mend;
%loop_though(20150831,20210731);
问题在于上述代码将遍历 20150831 和 20210731 之间的每个整数,这不是最优的,而且它会处理该月存在的每个文件,而不仅仅是与最后一个对应的文件每个月的一天。
如何调整?任何建议将不胜感激。
【问题讨论】:
-
您可以在库 SAVE 中列出数据集名称。