【问题标题】:SAS Calling ProcSQL-Macro in Data StepSAS在数据步骤中调用ProcSQL-Macro
【发布时间】:2016-08-13 04:16:39
【问题描述】:

我无法通过在我的数据步骤中调用宏来运行我的 PROC SQL 函数。 单独的 SQL 函数有效,但我需要让它为每个安全组运行。

%macro adding;
        proc sql;
        insert into have (Time,seconds) values
        ("9:10:00"t,33000);
        insert into have (Time,seconds) values
        ("16:50:00"t,60600);
        quit;
%mend;

data have;
set have;
by security;
if first.security then %adding;
if seconds=33000 then date=lag(date);
if seconds=60600 then date=lag(date);
run;

错误是:

1 过程 sql;插入有(时间,秒) 价值观

---- ------


   180               180 180 180 1   ! ("9:10:00"t,33000);         insert into have (Time,seconds) values 1   !

("16:50:00"t,60600);放弃;错误 180-322:语句是 无效或使用顺序不正确。

我不知道要改什么才可以用...

感谢您的帮助!最好的

【问题讨论】:

    标签: macros sas proc


    【解决方案1】:

    使用 call execute 来调用宏。

    If first.security then call execute('%adding');
    

    但是,宏将在数据步骤之后运行,而不是期间。 此外,尝试以多种方式更改数据可能会导致调试困难。您的 DATA、SET 和 SQL 都引用相同的数据集。

    如果您尝试更改 proc 中的数据并添加记录,您可能需要考虑在数据步骤本身中使用显式 OUTPUT 语句。如果需要,您可以使用宏来生成这些语句。

     If first.security then do;
         Time=...;
          Seconds=....;
         Output;
         Time=....;
          Seconds=....;
          Output;
      End;
    
       *rest of SAS code;
       Output; Add an explicit output if required;
       Run;
    

    您也不应该有条件地计算滞后值,因为滞后是一个队列。你会得到意想不到的行为。我没有强调您的流程中的所有问题,但这应该足以帮助您找到其余的问题。

    【讨论】:

    • 感谢您的提示和帮助!欣赏它,并将继续掌握宏观问题
    猜你喜欢
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多