@maroulator1 wrote:
Is it then fair to say that from the variables Var1 - Var5 in my dataset, if I only wanted to make changes to 3 of them, say Var1, Var3, and Var5 there is no way to do so other than putting Var1, Var3, and Var 5 into an array?
Not at all. What the ARRAY syntax allows is quick flexibility.
If you do something like
Array v (*) var1 var3 var5;
do i= 1 to dim(v);
v[i]=sum(v[i], 3000);
end;
is equivalent to writing
var1= sum(var1,3000);
var3= sum(var3,3000);
var5= sum(var5,3000);
The flexibility of an array based approach is that consider your next data set you need to do similar has 15 variables. It is much easier to just replace the list in the Array definition with the "new" list of 15 variable names. None of the other code would need to change. However if using the the Var1= statements you would need to rewrite/add 15 statements. And then the time after that with 8 variable for example you would need to remove statements and make the variables match the new list.
You could even use something like
array V(*) var1-var5;
do i=1 to dim(v);
if i in (1, 3, 5) then v[i] = sum(v[i], 3000);
end;
The IN operator returns true when i is any of the values in the list (note: not variables).
This would only do the addition with the index variable is the value of the element in the array that you want to modify. The STYLE choice of which code to use could depend. The last would be a better solution if you know that the variables will stay constant but that the variables that need that adjustment change frequently.
If you search this forum long enough I believe you will find a few questions/solutions involving arrays with 1000 or more variables.
Another use of the Arrays might be that you need to adjust the values differently for different variables. That might lead to a temporary array with the values used for the adjustment and code that looks like:
Array v (*) var1 var3 var5;
do i= 1 to dim(v);
v[i]=sum(v[i], temp[i]);
end;
Where Temp has been properly defined to hold the constant values needed to adjust each variable.
... View more