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

保持ステートメントを使用して、各値を次の観察にコピーできます。

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