sas中宏的do循环中的步长

Step size in macro's do loop in sas

所以我想 运行 为我的宏函数嵌套循环。 这是我的代码,SAS 似乎不喜欢 by -1。无论如何我编写这个代码让第二个循环减少-1? 在这种情况下,我的 yearMix = 1982yearMax = 1994.

%Macro theLoop;
    %Do I = &yearMin+1 %to &YearMax-1;
        %Do J = &YearMax-1 %to &I by -1;
            %Meaw;
        %END;
    %END;
%MEND theLoop;
%theLoop;

我收到这个错误:

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &I by -1
ERROR: The %TO value of the %DO J loop is invalid.
ERROR: The macro THELOOP will stop executing.

您使用 %by 而不是 by 在宏 %do 循环中指定增量。更多详细信息,请参阅用户指南 here.

在您的代码中,SAS 试图将 &I by -1 计算为数值。

%let yearMin = 1982;
%let yearMax = 1994;

%Macro theLoop;
    %Do I = %eval(&yearMin+1) %to %eval(&YearMax-1);
        %Do J = %eval(&YearMax-1) %to &I %by -1;
            %put &i =  &j = ;
        %END;
    %END;
%MEND theLoop;
%theLoop;