简体   繁体   中英

Step size in macro's do loop in sas

So I want to run nested loop for my macro function. Here's my code, it seem like SAS doesn't like by -1 . Is there anyway I code this to let the second loop decrease step by -1? In this case, my yearMix = 1982 and yearMax = 1994 .

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

I got this error:

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.

You specify your increment in a macro %do loop using %by rather than by . Further details can be found in the user guide here .

In your code SAS is trying to evaluate &I by -1 as a numerical value.

%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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM