Hello,
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];
6 end;
7 else do x = 1 to 3;
8 array3[x] = .;
9 end;
10 end;
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];
13 Z+1;
14 end;
15 Z+1;
...but it says there's an array subscript out of range at line 12.
I've attached the actual code I used.
Ideas???
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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.