如何按日期循环 sas 宏



>我定义了一个获取 1 天数据的宏。例如

%macro getOneday(stnd_d);
data _null_;
    call symputx('numdate',&stnd_d.);
run;
data oneday&numdate;
   set alldata;
   where stdd = &stnd_d;
run;
%mend;

现在我想将该宏从开始日期循环到结束日期。

 data _null_;
    do i = '01mar2015'd to '30mar2015'd;
    %getOneday(stnd_d = i)
    end;
 run;

我不知道如何将日期表达式值作为参数传递给 %getOneday()。

我希望

你理解宏 - getOneday会简单地通过替换%getOneday将它内部编写的所有代码写入data _null_语句中,并且由于您无法在data步骤中编写data步骤,因此会抛出错误。您只需将data _NULL_语句替换为如下所示的macro即可。同样使用这样的日期也不起作用,因为Macro将它们视为 char ,在循环中使用它们之前,您必须将它们转换为date格式%do

%macro test;
data _null_;
date1='01mar2015'd;
date2='30mar2015'd;
call symputx("date1",date1);
call symputx("date2",date2);
run;
%put &date1.;
%put &date2.;
    %do i = &date1. %to &date2.;
    %getOneday(stnd_d = &i.)
    %end;
 %mend;
 %test;

最新更新