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

Hello everyone, 

 

I am stuck in dealing with the macro to get the additional estimates using proc nlmixed. 

Let's me generalize my model. My dependent variable is Y and independent variable is X1 and X2.

I also have a categorical variable Z as another independent variable. Z receive value 0, 1, 2, 3. 

My model looks like this:

%macro nlmixed(datain);

proc nlmixed data=&datain qpoints=15 ecov;
parms a0=-3 b1=0 b2=0 b3=0 c1=0 c2=0;
Y=a0 + b1*Z + b2*X1+ b3*X1*Z +c1*X2 + c2*X2*Z;

 

/*I want to additionally estimate beta and omega based on the coefficients b2, b3, c1 and c2*/

/*for each value of Z, I have corresponding estimates for beta and omega*/


estimate 'beta0' (b2*b2 + b3*b3*0)/(1 + b2*b2 + b3*b3*0 + c1*c1+c2*c2*0);
estimate 'omega0' (c1*c1 + c2*c2*0)/(1 + b2*b2 + b3*b3*0 + c1*c1+c2*c2*0);
estimate 'beta1' (b2*b2 + b3*b3*1)/(1 + b2*b2 + b3*b3*1 + c1*c1+c2*c2*1);
estimate 'omega1' (c1*c1 + c2*c2*1)/(1 + b2*b2 + b3*b3*1 + c1*c1+c2*c2*1);

estimate 'beta2' (b2*b2 + b3*b3*2)/(1 + b2*b2 + b3*b3*2 + c1*c1+c2*c2*2);
estimate 'omega2' (c1*c1 + c2*c2*2)/(1 + b2*b2 + b3*b3*2 + c1*c1+c2*c2*2);

estimate 'beta3' (b2*b2 + b3*b3*3)/(1 + b2*b2 + b3*b3*3 + c1*c1+c2*c2*3);
estimate 'omega3' (c1*c1 + c2*c2*3)/(1 + b2*b2 + b3*b3*3 + c1*c1+c2*c2*3);
run;

%mend;

 

The macro works, but the problem is I have the other variable Z where it has up to 10 values. It means that I have to write 20 estimate statements. So, I was trying to plug a do-loop in the macro, but it's not working 😞 The do-loop I have tried is:

 

%do i = 0 to 3; 

estimate 'beta&i' %eval((b2*b2 + b3*b3*&i)/(1 + b2*b2 + b3*b3*&i + c1*c1+c2*c2*&i));
estimate 'omega&i' %eval((c1*c1 + c2*c2*&i)/(1 + b2*b2 + b3*b3*&i + c1*c1+c2*c2*&i));

%end;

 

Could you please help me to fix the do-loop so that I can save time in fixing code and running it with different variable Z?

 

Thank you so much in advance. 

Regards, 

Windy.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @windy,

 

Try this modification of your %DO loop:

%do i=0 %to 3;
  estimate "beta&i"  (b2*b2 + b3*b3*&i)/(1 + b2*b2 + b3*b3*&i + c1*c1+c2*c2*&i);
  estimate "omega&i" (c1*c1 + c2*c2*&i)/(1 + b2*b2 + b3*b3*&i + c1*c1+c2*c2*&i);
%end;

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @windy,

 

Try this modification of your %DO loop:

%do i=0 %to 3;
  estimate "beta&i"  (b2*b2 + b3*b3*&i)/(1 + b2*b2 + b3*b3*&i + c1*c1+c2*c2*&i);
  estimate "omega&i" (c1*c1 + c2*c2*&i)/(1 + b2*b2 + b3*b3*&i + c1*c1+c2*c2*&i);
%end;
windy
Quartz | Level 8

Hello @FreelanceReinh,

 

The calculation is working, but the &i in estimation parameters (beta&i and omega&i) are not resolved. 

 

 

FreelanceReinh
Jade | Level 19

@windy wrote:

Hello @FreelanceReinh,

 

The calculation is working, but the &i in estimation parameters (beta&i and omega&i) are not resolved. 


When you submit

options mprint;

and then the macro call, the resolved code should occur in the log, as shown below:

...
MPRINT(NLMIXED):   estimate "beta0" (b2*b2 + b3*b3*0)/(1 + b2*b2 + b3*b3*0 + c1*c1+c2*c2*0);
MPRINT(NLMIXED):   estimate "omega0" (c1*c1 + c2*c2*0)/(1 + b2*b2 + b3*b3*0 + c1*c1+c2*c2*0);
MPRINT(NLMIXED):   estimate "beta1" (b2*b2 + b3*b3*1)/(1 + b2*b2 + b3*b3*1 + c1*c1+c2*c2*1);
MPRINT(NLMIXED):   estimate "omega1" (c1*c1 + c2*c2*1)/(1 + b2*b2 + b3*b3*1 + c1*c1+c2*c2*1);
MPRINT(NLMIXED):   estimate "beta2" (b2*b2 + b3*b3*2)/(1 + b2*b2 + b3*b3*2 + c1*c1+c2*c2*2);
MPRINT(NLMIXED):   estimate "omega2" (c1*c1 + c2*c2*2)/(1 + b2*b2 + b3*b3*2 + c1*c1+c2*c2*2);
MPRINT(NLMIXED):   estimate "beta3" (b2*b2 + b3*b3*3)/(1 + b2*b2 + b3*b3*3 + c1*c1+c2*c2*3);
MPRINT(NLMIXED):   estimate "omega3" (c1*c1 + c2*c2*3)/(1 + b2*b2 + b3*b3*3 + c1*c1+c2*c2*3);
...

Note that I used double quotes around "beta&i" and "omega&i", whereas the single quotes in your code prevented the resolution of the macro variable reference &i.

 

windy
Quartz | Level 8

Oh wow, beautiful. It's working now. 

Thank you so much for your help, @FreelanceReinh.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 608 views
  • 2 likes
  • 2 in conversation