SAS宏按日期循环,如何指示正确的步骤?

SAS macro looping by date, how to indicate the correct step?

我需要为年份、季度和月份创建 3 个 SAS 表,其中包含从今天开始的指定范围。我想有一种更聪明的方法可以做到这一点,但我最终得到了类似的东西(比如,如果我需要回到 5 年前):

    %macro asd;

%let today = %sysfunc(today());
%let end_year = %sysfunc(intnx(year,&today,-5));


proc sql;
create table years
(
Years num informat = date9. format = date9.
);

insert into years

%do i = &today. %to &end_year. %by -365;
%if i = &today.-365 %then %do;
values(&i.-1)
%end;
%else %do;
values(&i.) 
%end;
%end;
;
quit;

%mend asd;
%asd;
run;

问题是我不知道如何将循环中的步骤指示为日期期间,所以我得到了确切的数字,这些数字各不相同(年 - 每 4 年,月 - 每秒月,季度 - 每 16 个季度)。

我添加了一年的循环以尝试至少考虑几个闰年,但它不起作用。因此,在继续几个月并可能实施另一个嵌套循环之前,我想问一下是否有更简单的方法来创建此类表?

谢谢! :)

改变你的循环以循环年数并改为计算循环内所需的宏变量。

示例 - 非宏版本。

 Do I=1 to 5;
     Year=intnx('year', date, 1);

      Rest of code;
 End;