I'm trying to use an array to accomplish the following. However, I've never used one before and I'm having a bit of trouble.
Basically I want to take the following data and create one row(observation) for each acct, seq1, seq2 combination:
acct seq1 seq2 la ln
9999 1 10 20.01 100
9999 1 10 19.05 1
9999 2 11 26.77 100
9999 2 11 24.86 1
8888 3 20 38.43 218
8888 3 20 37.53 1
This is what I want to end up with. Note, I'm only showing la1 through la3 and ln1 through ln3 for the sake of space. It would actually to go to la7 and ln7:
acct seq1 seq2 la1 la2 la3 ln1 ln2 ln3
9999 1 10 20.01 19.05 . 100 1 .
9999 2 11 26.77 24.86 . 100 1 .
8888 3 20 38.43 37.53 . 218 1 .
Here is the code that I've attempted so far. Any assistance would be greatly appreciated:
data want;
set have;
by acct seq1 seq2;
if first.seq2 then do;
array la_array {7} la1-la7;
array ln_array {7} ln1-ln7;
end;
do i = 1 to 7;
la_array(i)=la;
ln_array(i)=ln;
end;
run;
if
statement block. What you want to do in that block is initialize things to zero. You need toretain
your variables that are in the arrays, and you need to only populatela_array[seq1]
, not all seven each loop through the dataset. – Joe