01-10-2018 12:57 PM
I'm a new SAS user, so thanks in advance for your help.
I have a loop inside a loop that puts x variable values into an array, and then the outer loop iterates y times. When it iterates the next y time, I want the array to keep the previous values and add the new values to that array instead of replacing the previous values (I assume that if I use retain, it would stop it from replacing but not add the new ones). This is my basic code.
1 do y = 1 to 5;
2 if array1[y] ~= . then
3 do x = 1 to 3;
4 if array2[x] = . or array2[x] < array1[y] then array3[x] = .;
5 else array3[x] = array2[x] - array1[y];
7 else do x = 1 to 3;
8 array3[x] = .;
I tried adding this before the last end statement (so it is included in the y iteration):
Z = 1; (specified outside of loops)
11 do j = 1 to 3;
12 array4[Z] = array3[j];
...but it says there's an array subscript out of range at line 12.
I've attached the actual code I used.
01-10-2018 01:19 PM
Each array has a fixed number of elements. In that sense, it is not something you can expand or add to. All you can do is replace some of the current values within the array.
There may be a way to accomplish what you need, but you will have to illustrate the "before" and "after" picture using a couple of observations of data.