【发布时间】:2014-02-10 18:31:21
【问题描述】:
我对 SAS 比较陌生,正在努力将代码从 SAS 转换为 R。 我遇到了这个让我有点困惑的sn-p。
data A ; set B;
by date id Units;
retain Total;
if first.id and last.id then do;
Total=Units;
output;
end;
else do ;
if first.id then Total=Units;
else Total=sum(Total,Units);
if last.id then output;
end;
run;
如果我对这段代码的理解是正确的,这个 sn-p 会输出一个名为 A 的数据集,它是(在 SQL 术语中)所有第一次和最后一次出现的 id 和最后一次出现的 id 的并集。我对吗?那么 By 语句的目的是什么?我尝试通过 SAS 帮助,但我仍然感到困惑。
提前致谢!
【问题讨论】: