BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sasulee
Fluorite | Level 6

Hi all,

I am building a formula which shows below by referring Sum a series in SAS

截屏2020-06-19上午12.18.35.png

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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);

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Sasulee
Fluorite | Level 6
Thanks for replying. However, every column is valued. Is it caused by incorrect use of the sum function?
Rick_SAS
SAS Super FREQ

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."

Rick_SAS
SAS Super FREQ

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);
Sasulee
Fluorite | Level 6
Why r, t, Q should divide by 5, 10, 15 respectively? how can I express this when read all var?
IanWakeling
Barite | Level 11

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.

Rick_SAS
SAS Super FREQ

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 7 replies
  • 1725 views
  • 5 likes
  • 4 in conversation