SAS 在数据步骤中调用 ProcSQL-Macro
SAS Calling ProcSQL-Macro in Data Step
我无法通过在我的数据步骤中调用宏来 运行 我的 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 proc sql; insert into have (Time,seconds)
values
---- ------
180 180 180 180 1 ! ("9:10:00"t,33000); insert into have (Time,seconds) values 1 !
("16:50:00"t,60600); quit; ERROR 180-322: Statement is
not valid or it is used out of proper order.
我不知道要更改什么才能使用它...
感谢您的帮助!最佳
使用call execute调用宏。
If first.security then call execute('%adding');
但是,宏将 运行 在数据步骤之后,而不是在数据步骤期间。
此外,尝试以多种方式更改数据可能会导致调试困难。您的 DATA、SET 和 SQL 都引用相同的数据集。
如果您尝试更改过程中的数据并添加记录,您可能需要考虑在数据步骤本身中使用显式 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;
您也不应该有条件地计算滞后值,因为滞后是一个队列。你会得到意想不到的行为。我没有突出显示您流程中的所有问题,但这应该足以帮助您找到其余问题。
我无法通过在我的数据步骤中调用宏来 运行 我的 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 proc sql; insert into have (Time,seconds) values
---- ------
180 180 180 180 1 ! ("9:10:00"t,33000); insert into have (Time,seconds) values 1 !
("16:50:00"t,60600); quit; ERROR 180-322: Statement is not valid or it is used out of proper order.
我不知道要更改什么才能使用它...
感谢您的帮助!最佳
使用call execute调用宏。
If first.security then call execute('%adding');
但是,宏将 运行 在数据步骤之后,而不是在数据步骤期间。 此外,尝试以多种方式更改数据可能会导致调试困难。您的 DATA、SET 和 SQL 都引用相同的数据集。
如果您尝试更改过程中的数据并添加记录,您可能需要考虑在数据步骤本身中使用显式 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;
您也不应该有条件地计算滞后值,因为滞后是一个队列。你会得到意想不到的行为。我没有突出显示您流程中的所有问题,但这应该足以帮助您找到其余问题。