sas - lag by acct id? -


not sure if need use lag this. here's want do.

here data have...

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 

this want end with...

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 

i have data set sorted acct , sort_order. each acct, want take first type (based on sort_order) , copy each row of acct. example, acct 111111 has "standard" it's first type. want every observation acct 111111 have "standard" it's type.

i tried doing following lag, doesn't quite work right...

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

you can use retain statement copy each value next observation.

data want;     set have;     accnt;     retain want;     if first.accnt want = type; run; 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -