0

不确定我是否需要为此使用延迟。但这就是我想做的。

这是我的数据...

acct    sort_order        type
111111     1            standard
111111     1            standard
111111     2            non-standard
111111     3            other
111111     3            other
222222     2            non-standard
222222     3            other
222222     3            other

这就是我想要结束的...

acct     sort_order  type           want
111111       1     standard       standard
111111       1     standard       standard
111111       2     non-standard   standard
111111       3     other          standard
111111       3     other          standard
222222       2     non-standard   non-standard
222222       3     other          non-standard
222222       3     other          non-standard

我的数据集按 acct 和 sort_order 排序。对于每个帐户,我想采用第一种类型(基于 sort_order)并将其复制到该帐户的每一行。例如,acct 111111 将“标准”作为它的第一个类型。我希望 acct 111111 的每个观察都具有“标准”作为它的类型。

我尝试在滞后的情况下执行以下操作,但效果不太好......

data want;
set have;
by acct;
want = lag(type);
if first.acct then want = type;
run;
4

1 回答 1

1

您可以使用 retain 语句将每个值复制到下一个观察值。

Data want;
    set have;
    by accnt;
    retain want;
    if first.accnt then want = type;
run;
于 2015-05-14T18:17:24.513 回答