SAS Scan不喜欢第二个参数(do循环计数器)

时间:2014-10-20 13:51:40

标签: sas database-scan

需要第二双眼睛:

%MACRO FIND_CLOSEST_LIMIT_OR_DEDUCTIBLE(limOrDedOption,limOrDedValue);
    %LET numOptions = %Sysfunc(Countw(&limOrDedOption.));

    limOrDedSetFlag = 'N';
    %DO curLimOrDed = 1 %TO &numOptions.;
        IF limOrDedSetFlag = 'N' AND &curLimOrDed = 1 AND &limOrDedValue. <= %Scan(&limOrDedOption.,&curLimOrDed.) THEN DO;
            &limOrDedValue. = %Scan(&limOrDedOption,1);
            limOrDedSetFlag = 'Y';
        END;
        IF limOrDedSetFlag = 'N' AND &curLimOrDed. >= 2 THEN DO;
            lowerLimOrDed = %Scan(&limOrDedOption,prevLimOrDed, &curLimOrDed. - 1);
            upperLimOrDed = %Scan(&limOrDedOption.,&curLimOrDed);
            IF &limOrDedValue. < %Scan(&limOrDedOption.,&curLimOrDed) THEN DO;
                IF (&limOrDedValue. - lowerLimOrDed)/ (upperLimOrDed - lowerLimOrDed) < 0.5 THEN 
                    &limOrDedValue. = lowerLimOrDed;
                ELSE &limOrDedValue. = upperLimOrDed;
                limOrDedSetFlag = 'Y';
            END;
        END;
    %END;

    IF MISSING(&limOrDedValue.) THEN &limOrDedValue. = 0;
/*  DROP lowerLimOrDed upperLimOrDed;*/
%MEND FIND_CLOSEST_LIMIT_OR_DEDUCTIBLE;

收到以下错误:

MPRINT(FIND_CLOSEST_LIMIT_OR_DEDUCTIBLE):   IF limOrDedSetFlag = 'N' AND 1 >= 2 THEN DO;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       prevLimOrDed 
ERROR: Argument 2 to macro function %SCAN is not a number.
NOTE 137-205: Line generated by the invoked macro "FIND_CLOSEST_LIMIT_OR_DEDUCTIBLE".
104         DO;    lowerLimOrDed = %Scan(&limOrDedOption,prevLimOrDed, &curLimOrDed. - 1);    upperLimOrDed =
                                                                                         _
                                                                                         22
104      ! %Scan(&limOrDedOption.,&curLimOrDed);    IF &limOrDedValue. < %Scan(&limOrDedOption.,&curLimOrDed) THEN DO;     IF
104      ! (&limOrDedValue. - lowerLimOrDed)/ (
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, 
              a missing value, INPUT, PUT.  

看起来SAS不喜欢&amp; curLimOrDed - 1.有什么帮助?

谢谢!

2 个答案:

答案 0 :(得分:2)

我猜您需要附上&curLimOrDed - 1

进入%EVAL()函数,以便按预期进行评估:%EVAL(&curLimOrDed - 1)

除此之外,错误消息实际上表明了问题:

The condition was: prevLimOrDed 

那是因为在你的陈述中:

lowerLimOrDed = %Scan(&limOrDedOption,prevLimOrDed, &curLimOrDed. - 1);

prevLimOrDed不用作宏变量,但在宏函数中使用。它是数据步变量吗? 对于%SCAN函数,它只表示文本&#34; prevLimOrDed&#34;,而函数需要一个数字参数。

答案 1 :(得分:0)

扫描功能的第三个参数用于分隔符,分隔符必须是字符值。您正在第三个参数中进行一些计算。