Hi, I am looking to dynamically reference a variable name within an expression. Examples below: DATA out;
set have;
array values {&num_leases.};
array dates {&num_leases.};
array combined {2* &num_leases.} Var1-Var&num_leases.;
RUN In the above, I would like to create arrays with a length stored in the variable num_leases. For the "combined" array, I would like to then create variables names Var1 Var2... VarN, where N is the number of leases stored in num_leases. I then go on to store values in these arrays, and then I would like to find the last non-missing (i.e. ne .) entry in the "combined" array and use all non-missing elements in an expression, as below: do i = 1 to &num_leases.;
if combined{i} = . then leave;
end;
IRR = finance('xirr',combined{1}:combined{i});
output; So, in the above, I am looping through all elements in the "combined" array, and, when I find the first missing element, I am storing where in the array is it (i.e. element i). I then want to pass the non-missing elements in this array to the finance XIRR function to calculate an IRR. Would anyone be able to help me understand how to dynamically reference variable names, and then pass them to an expression, as per the above? Many thanks!
... View more