BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
pedroy341
Calcite | Level 5

Hello. I am trying to approximate a 36 points series to a quaterly data of 9 quarters. The objetive here is that the optimized series of 36 points fits the goal for those 9 quarters with minimal error while  being a smooth and monotonous function. I was trying to use the following code:

proc iml;
   /* Step 1: Define Bayes values from macro variables */
   bayes = {
       &bayes1,
       &bayes2,
       &bayes3,
       &bayes4,
       &bayes5,
       &bayes6,
       &bayes7,
       &bayes8,
       &bayes9
   };
   /* Step 2: Define initial guess (e.g., from macro variables &pd1–&pd36) */
    PD_ini = {
        &PD1, &PD2, &PD3, &PD4, &PD5, &PD6, &PD7, &PD8, &PD9, &PD10, &PD11, &PD12, &PD13, &PD14, &PD15, &PD16, &PD17, &PD18, &PD19, &PD20, &PD21, &PD22, &PD23, &PD24, &PD25, &PD26, &PD27, &PD28, &PD29, &PD30, &PD31, &PD32, &PD33, &PD34, &PD35, &PD36
    };
PD_init=t(PD_ini);
 
   /* Step 3: Define the objective function */
   start objetive(pd) global(bayes);
       S = j(1, 36, .);
       CumPD = j(1, 36, .);
 
       S[1] = 1 - pd[1];
       CumPD[1] = 1 - S[1];
 
       do t = 2 to 36;
           S[t] = S[t-1] * (1 - pd[t]);
           CumPD[t] = 1 - S[t];
       end;
 
       obj = 0;
       do i = 0 to 8;
           t = i * 3 + 1;  /* Corresponds to months 0, 3, ..., 24 */
           condPD = (CumPD[t+12] - CumPD[t]) / S[t];
           err = (condPD - bayes[i+1]) * 100;
           obj = obj + err##2;
       end;
 
       return (obj);
   finish;
 
   /* Step 4: Call optimizer */
   optn = {0};  /* 0 = minimize */
   call nlpqn(rc, result, "objetive", initPD, optn);
 
   /* Step 5: Output results */
   print rc result;
quit;

But I keep getting this error:
74 ! /* 0 = minimize */
75 call nlpqn(rc, result, "objetive", initPD, optn);
ERROR: (execution) Matrix has not been set to a value.

I have also tried to use the initial matrixes as constants but it didnt work either.
Ex:  bayes = {0.0002639011, 0.0003372667, 0.0004005217, 0.0004619689, 0.0005238603, 0.0005852403, 0.000645032, 0.0007037884, 0.0007612079 and  PD_ini = j(1,36,0.01);

Note: My base SAS software is 9.4 and the IML is For SAS/IML 15.2.

Can someone give some pointers or some help. I would apreciate it 😃





1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The vector for the initial guess is called PD_init in the program, but you are passing initPD (which is undefined) as an argument to CALL NLPQN.

That information (which matrix was not set to a value) is part of the log, so please copy/paste the entire error message in future posts.

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

The vector for the initial guess is called PD_init in the program, but you are passing initPD (which is undefined) as an argument to CALL NLPQN.

That information (which matrix was not set to a value) is part of the log, so please copy/paste the entire error message in future posts.

pedroy341
Calcite | Level 5
Hello! Thank you a lot for your answer. This was my first post and I didn't submit it in a acceptable format. Luckly I have sorted it out.
I will make sure to be more carefully next time.
Rick_SAS
SAS Super FREQ

No worries. Glad your problem is solved!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 3 replies
  • 666 views
  • 1 like
  • 2 in conversation