您好我有以下数据集:
Account date
y1 01/02/2010
y1 03/02/2010
y1 04/20/2010
y2 02/02/2010
y2 03/15/2010
x2 04/15/2010
我只想为每个帐户选择最早的日期并获得以下输出:
Account date
y1 01/02/2010
y2 02/02/2010
x2 04/15/2010
谢谢。
答案 0 :(得分:2)
使用proc sql,按帐户分组,选择min(date)并使用format=
选项生成正确的日期格式:
proc sql;
select
account,
min(date) format=mmddyy10. as date
from
yourdata
group by
account
;
quit;
如果您希望将输出存储在数据集中,只需在CREATE TABLE
和PROC SQL;
之间插入select
子句:
proc sql;
create table newdata as
select
答案 1 :(得分:1)
数据步骤版本:假设您的数据集按帐户和日期排序,这是按组处理的简单情况:
data want;
set have;
by account;
if first.account;
run;