Dear all,
Apologies for the multiple posts. I wanted to share the progress I was able to make with the previous question. In case it helps anyone help me.
I used 'submit' and 'endsubmit' to convert all the vector operations in my previous post into data steps. This enabled me to get rid of the Do-loop. However, with the code below, nlpnra is simply returning the initial value. Any suggestions on what am I doing wrong will be very helpful.
Thank you very much in advance.
proc iml;
start LogLik(param);
p1 = param[1];
p2 = param[2];
p3 = param[3];
p4 = param[4];
p5 = param[5];
submit p1 p2 p3 p4 p5;
data _null_;
set want;
/*scroll further probability*/
if position < 3 then sc_p = 1;
else sc_p = logistic(&p1 + &p2*position + &p3*pred_usage + &p4*relevant_offer_cnt_wt + &p5*credits_r);
/*end probability*/
if position < max_pos then ed = 0;
else ed = 1 - sc_p;
by seq;
retain prod_choice;
retain prod_scroll;
retain ll;
retain total_ll 0;
if first.seq then do;
prod_choice = 1;
prod_scroll = 1; end;
prod_choice = prod_choice*not_choosing_prob;
prod_scroll = prod_scroll*sc_p;
prod_choice_end = prod_choice*ed;
lag_prod_scroll = lag(prod_scroll);
if first.seq then lag_prod_scroll = 1;
pos_end_ll = lag_prod_scroll*prod_choice_end;
if first.seq then ll = pos_end_ll;
else ll = ll + pos_end_ll;
if last.seq then do;
log_ll = log(ll);
total_ll = total_ll + log_ll;
end;
call symput ("total_ll",total_ll);
run;
endsubmit;
C = &total_ll.;
return sum(C);
finish;
param = {-0.1 -0.005 0.1 -0.1 0.2 0.0};
optn = {1, /* 3. find max of function, and */ 4}; /* print moderate amount of output */
con = {. . . . . .,
. . . . . .};
call nlpnra(rc, xres, "LogLik", param, optn, con);
quit;
Best,
Rakesh
> Apologies for the multiple posts.
You can't have a data step within PROC IML.
Are you sure this line is getting the value of the macro variable generated by the submitted data step?
C = &total_ll.;
Or does it just get the value of the macro variable that was present when the IML step started?
Does IML have something similar to the SYMGET() or SYMGETN() function of the data step?
> Does IML have something similar to the SYMGET() or SYMGETN() function of the data step?
You can call almost every DATA step function from an IML program. See Calling Base SAS Functions from SAS/IML Programs - The DO Loop
Specifically, you can certainly call SYMGET.
Both SYMGET and directly referencing the macro variable will work. For example, run this program:
proc iml;
SUBMIT;
data _null_;
call symputx("test", 3.14);
run;
ENDSUBMIT;
x = &test;
y = symget("test");
print x y;
quit;
However, if you are using a DO loop, then use SYMGET, because the loop is parsed and compiled, which means that the macro resolution occurs at parse time, not run time. See Macros and loops in the SAS/IML language - The DO Loop
Thank you, Rick and Tom.
I see that symget works in the ml environment. However, in the line highlighted by Tom "C = &total_ll.;", the macro variable is not getting updated with each iteration of nlpnra. It simply retains the value before the start of proc iml.
Any suggestions on how do I update this variable with nlpnra?
> Apologies for the multiple posts.
Thank you, Rick. In light of this suggestion, we could put the submit/endsubmit thread to rest.
In the previous post, I use the native SAS IML module to compute the objective function. Any suggestions on improving it would be very helpful.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.