I'm working within Proc IML and have already set up a maximum likelihood function and using nlpnrr method to optimise. The optimisation itself works well. The problem is when I added certain If-Then_else statements within this optimization procedure. I need to put condition on certain elements/observations in the matrices. For example,
if income[,m] < 0 then income[,m]=0; else income[,m]=income[,m];
The rows of the matrix are individuals and m is the number of ways that I calculate income in the previous lines through a do loop..
I noticed that when I put this condition, the way SAS reads it is - if income is negative for ALL the elements in each column then it'll give zeros to ALL the individuals in that column, otherwise it keeps income as it is for everyone. However, what I need to see is to only give 0 to those observations that have a negative income. When I add "i" in the above code so that;
do i=1 to num; /*num is number of observations*/
if income[i,m] < 0 then income[i,m]=0; else income[i,m]=income[i,m];
this works but the problem is that this code doesn't work in optimisation procedure and I get error.
So my question is that how can I do this within the nlpnrr optimisation procedure? I appreciate any help..
Thanks Rick. I used the ‘choose’ function as you siggested and it worked. Thanks so much.
SAS INNOVATE 2024
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.