我正试图从某个by组中删除singlets。这是我的代码:
proc sort data=have; by ID date; run;
data want;
set have;
by ID date;
if first.date and last.date then delete;
run;
对我来说,这应该删除所有在同一ID中只有一个日期的条目。但出于某种原因,没有一个观察结果被允许通过。根据我的数据集,我应该会显示数千个观测结果。我以前在其他数据集上使用过,没有遇到任何问题。我知道这不是什么好事,但我是不是犯了一些我错过的错误?
您正在做的事情:
data want;
set have;
by ID date;
if first.date and last.date then delete; *if this is the first and last record for that date, then delete it;
run;
你想做什么,我相信:
data want;
set have;
by ID date;
if first.ID and last.ID then delete; *if this is the only record for that ID then delete it;
run;
然而,这可能不是你想要的——这取决于你的数据。你也有
proc sort nounikey data=have;
by id;
run;
这删除了任何";独特的";记录。