SAS delete 和 return 语句
SAS delete and return statements
我正在查看其他人的代码并尝试确定是否:
if x = y then do;
delete;
return;
end;
相当于:
if x = y then do;
delete;
end;
来自关于 DELETE 的文档:
When DELETE executes, the current observation is not written to a data set, and SAS returns immediately to the beginning of the DATA step for the next iteration.
这让我相信第一个例子中的 'return' 语句没有被执行?
与其猜测不如测试。
- 创建一个包含 x/y 个值的数据集,一个满足条件,一个不满足条件。
- 运行 数据步骤并添加 PUT 语句以便您可以跟踪日志
从log中看到执行DELETE后什么都没有,可以确认RETURN没有执行,是多余的
仅供参考 - 需要考虑的一件事 - 这种行为是否随时间发生了变化,或者代码是否发生了变化,也许这曾经有效?通常是这样。
data have;
input x y;
cards;
1 2
1 1
;;;;
run;
data demo;
set have;
if x = y then do;
put "Record Deleted 1";
delete;
put "Record Deleted 2";
return;
put "Record Deleted 3";
end;
else put "Record Retained";
run;
日志:
78 data demo;
79 set have;
80 if x = y then do;
81 put "Record Deleted 1";
82 delete;
83 put "Record Deleted 2";
84 return;
85
86 put "Record Deleted 3";
87
88 end;
89 else put "Record Retained";
90
91 run;
Record Retained
Record Deleted 1
NOTE: There were 2 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.DEMO has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 798.71k
OS Memory 24232.00k
Timestamp 10/18/2021 10:25:05 PM
Step Count 39 Switch Count 2
Page Faults 0
Page Reclaims 135
Page Swaps 0
Voluntary Context Switches 10
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264
我正在查看其他人的代码并尝试确定是否:
if x = y then do;
delete;
return;
end;
相当于:
if x = y then do;
delete;
end;
来自关于 DELETE 的文档:
When DELETE executes, the current observation is not written to a data set, and SAS returns immediately to the beginning of the DATA step for the next iteration.
这让我相信第一个例子中的 'return' 语句没有被执行?
与其猜测不如测试。
- 创建一个包含 x/y 个值的数据集,一个满足条件,一个不满足条件。
- 运行 数据步骤并添加 PUT 语句以便您可以跟踪日志
从log中看到执行DELETE后什么都没有,可以确认RETURN没有执行,是多余的
仅供参考 - 需要考虑的一件事 - 这种行为是否随时间发生了变化,或者代码是否发生了变化,也许这曾经有效?通常是这样。
data have;
input x y;
cards;
1 2
1 1
;;;;
run;
data demo;
set have;
if x = y then do;
put "Record Deleted 1";
delete;
put "Record Deleted 2";
return;
put "Record Deleted 3";
end;
else put "Record Retained";
run;
日志:
78 data demo;
79 set have;
80 if x = y then do;
81 put "Record Deleted 1";
82 delete;
83 put "Record Deleted 2";
84 return;
85
86 put "Record Deleted 3";
87
88 end;
89 else put "Record Retained";
90
91 run;
Record Retained
Record Deleted 1
NOTE: There were 2 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.DEMO has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 798.71k
OS Memory 24232.00k
Timestamp 10/18/2021 10:25:05 PM
Step Count 39 Switch Count 2
Page Faults 0
Page Reclaims 135
Page Swaps 0
Voluntary Context Switches 10
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264