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

Hi,

I have a PROC NLMIXED where some parameters are known to take on some values in a pre-specified grids. I want to put this PROC NLMIXED procedure into a FOR LOOP or something similar, where everytime the parameters take the value in the grid, then the PROC NLMIXED is run, then the output (for example, the parameter estimate or the likelihood) are exported. Finally, I want to combine all these outputs together.

I tried searching on the internet but it seems there is no useful source for me.

Let take an example: I use the data set and the code from the website of UCLA: (Link: http://www.ats.ucla.edu/stat/sas/faq/cens_nlmixed.htm).

The code is:

proc nlmixed data=Simu XTOL=1E-12 method=GAUSS qpoints=100;
  parms beta0=7.3 beta1=-.21 beta2=.96 beta3=3
    sigma2_u=.7 sigma2=75;
  bounds sigma2_u sigma2 >= 0;
  pi = constant('pi');
  mu = beta0 + b_0j + beta1*Xc1 + beta2*Xc2 + beta3*Xi1;
  if Ycensr < 16 then 
    ll = (1 / (sqrt(2*pi*sigma2))) * exp( -(Ycensr-mu)**2 / (2*sigma2) );
  if Ycensr >= 16 then 
    ll = 1 - probnorm( (Ycensr - mu) / sqrt(sigma2) );
  L=log(ll);
  model Ycensr ~ general(L);
  random b_0j ~ normal(0, sigma2_u) subject=ID;
  run;
quit;

The data file is put in the attachment for easy following the question.

Suppose now I have known that beta0 is in c(1,2,3,4,5,6,7,8,9,10) and beta1 is in (-2.5, -2.0,-1.5,-0.5,0). I want to put this PROC NLMIXED procedure into a FOR loop and let beta0 and beta1 only receive values from these two sequences.

I have tried macro variables but it seemed that PROC NLMIXED considered beta0 and beta1 as parameters need to be estimated and optimized the likelihood function with respect of these two parameters as well.

How do I do this? Does any one have a good reference?

 

P/s: I use SAS 9.4

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

 

It sounds like you want beta0 and beta1 to be fixed constants, rather than parameters in the problem that need to be optimized. Perhaps this is part of a simulation design? 

 

 

In general the "SAS way" to "run a procedure in a FOR loop" is to use a BY statement. See

Simulation in SAS: The slow way or the BY way

 

It sounds like you want the data to be the same for each run, but only change the values of beta0 and beta1.  (???) In that case, you can write a data set like this:

 

data Want;
set Simu;
do beta0 = 1 to 10;
   do beta1 = -2.5 to 0 by 0.5;
      output;
   end;
end;
run;

proc sort data=Want;
by beta0 beta1;
run;


proc nlmixed data=Want;
by beta0 beta1;
/* remove beta0 and beta1 from PARMS statement */
...
run;

The WANT data set contains multiple copies of your data, each with different values of beta0 and beta1.

If you remove beta0 and beta1 from the PARMS statement, they are treated as constants.

 

The other way to solve this problem is to run the optimization in SAS/IML software, which gives you complete control over loops and parameters.  A relevant articles is Maximum likelihood estimation in SAS/IML

 

If you want a DIFFERENT random sample for each value of beta0 and beta1, then now you are talking about simulating data in SAS. There is a book on simulating data in SAS that contains hundreds of tips and techniques.  You can also search my blog for simulation articles that discuss general simulation techniques in SAS. 

 

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

 

It sounds like you want beta0 and beta1 to be fixed constants, rather than parameters in the problem that need to be optimized. Perhaps this is part of a simulation design? 

 

 

In general the "SAS way" to "run a procedure in a FOR loop" is to use a BY statement. See

Simulation in SAS: The slow way or the BY way

 

It sounds like you want the data to be the same for each run, but only change the values of beta0 and beta1.  (???) In that case, you can write a data set like this:

 

data Want;
set Simu;
do beta0 = 1 to 10;
   do beta1 = -2.5 to 0 by 0.5;
      output;
   end;
end;
run;

proc sort data=Want;
by beta0 beta1;
run;


proc nlmixed data=Want;
by beta0 beta1;
/* remove beta0 and beta1 from PARMS statement */
...
run;

The WANT data set contains multiple copies of your data, each with different values of beta0 and beta1.

If you remove beta0 and beta1 from the PARMS statement, they are treated as constants.

 

The other way to solve this problem is to run the optimization in SAS/IML software, which gives you complete control over loops and parameters.  A relevant articles is Maximum likelihood estimation in SAS/IML

 

If you want a DIFFERENT random sample for each value of beta0 and beta1, then now you are talking about simulating data in SAS. There is a book on simulating data in SAS that contains hundreds of tips and techniques.  You can also search my blog for simulation articles that discuss general simulation techniques in SAS. 

 

bienco88
Obsidian | Level 7

Thank you a lot.

That is indeed what I want to do.

Big thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1054 views
  • 2 likes
  • 2 in conversation