Hi all,
I am building a formula which shows below by referring Sum a series in SAS
When I run,
start Sumcon(n);
i = 1:n; /* index of terms */
return( sum((deltak/k[i]##2)#exp(r[i]#T[i])#Q[i]) ); /* sum of terms */
finish;
n = T(1:68);
sum = j(nrow(n),1); /* allocate a vector for the results */
do k = 1 to nrow(n);
sum[k] = Sumcon( n[k] );
end;
It returns ERROR: (execution) Matrix has not been set to a value.
where the variables k, r, t, Q are all (68,1) vectors, the deltak is a fixed value 5.
How can I achieve this formula?
Thanks a lot.
Here is how I would compute the sum. I am using 5-dimensional vectors instead of 68 elements:
proc iml;
/* Use n = 5 instead of 68.
Make up some fake values for the column vectors k, r, t, Q */
k = {1,2,3,4,5};
r = {1,2,3,4,5} / 5;
T = {1,2,3,4,5} / 10;
Q = {1,2,3,4,5} / 15;
deltak = 2;
v = deltak/k##2 # exp(r#T)#Q;
sum = sum(v);
ERROR: (execution) Matrix has not been set to a value.
Print out each of the matrices involved and see which one(s) do not have values.
The vectors are not in scope inside the function. You either need to pass them in or use a GLOBAL statement. See "Understanding local and global variables in the SAS/IML language."
Here is how I would compute the sum. I am using 5-dimensional vectors instead of 68 elements:
proc iml;
/* Use n = 5 instead of 68.
Make up some fake values for the column vectors k, r, t, Q */
k = {1,2,3,4,5};
r = {1,2,3,4,5} / 5;
T = {1,2,3,4,5} / 10;
Q = {1,2,3,4,5} / 15;
deltak = 2;
v = deltak/k##2 # exp(r#T)#Q;
sum = sum(v);
Please take another look at Rick's post above, as I think it is the solution that you want. Ignore everything up to deltak=2, as this is artificial data to show that the solution works. Try to include the last 2 lines in your own code, and tell us what happens.
The comment in my program says "Make up some fake values for the column vectors k, r, t, Q"
Thus, these are fake values. Not real. Made up. Use your values instead.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.