Forecasting using SAS Forecast Server, SAS/ETS, and more

Parameter estimation with proc model and ODEs

New Contributor
Posts: 2

Parameter estimation with proc model and ODEs

Dear all,


I'm trying to fit a dataset with proc model and ordinary differential equations, but somehow it does not work.

SAS complains that I don't have the values A1 and A2 in the dataset, but they can't be in the dataset. Any ideas? The dataset and the code is attached below.


Many thanks in advance.



ata step01;
INPUT time     conc;
0.1    1.50
0.2    3.20
0.4    4.30
0.6    5.10
0.8    5.40
1    5.20
1.2    5.00
1.4    4.80
2    4.00
3    2.50
4    1.50
5    1.00
6    0.62
7    0.40
8    0.25
10    0.10

proc model data=step01;
ENDOGENOUS A1 400 A2 0 ;
dert.A1 = -ka * A1;
dert.A2 =  ka * A1 - (CL/V2)*A2;
FIT CONC start=(KA 2.5 CL 20 V2 50) ;


Respected Advisor
Posts: 2,655

Re: Parameter estimation with proc model and ODEs

I got what look like satisfactory results by changing the ENDOGENOUS statement to a PARAMETERS statement.  I'm pretty sure that SAS expects endogenous variables to be part of the input dataset here, so by shifting to PARAMETERS, it fits those at t=0.


Steve Denham

New Contributor
Posts: 2

Re: Parameter estimation with proc model and ODEs

Dear Steve,


many thanks. It works perfectly.


Does anyone know how I can add a second input/pulse (i.e. a drug dosing) to the first differential equation after a certain time, e.g. 12 hours? How can I integrate this into a dataset?


Many thanks


SAS Employee
Posts: 25

Re: Parameter estimation with proc model and ODEs


I was surprised to see that Steve's suggestion to change the ENDO statement into a PARMS statement does allow PROC MODEL to estimate this one compartment model; however, I would not recommend this approach as it exploits an unintended side effect in PROC MODEL and may not work in the future.

The more standard way of estimating this model would be to include the unobserved values, a1 and a2, in the data set:

data step02;
   set step01;
   a1 = .;
   a2 = .;

proc model data=step02;
   endo a1 400 a2 0;

I would also like to point out that neither of these approaches may be exactly what you want. Presumably, in your model the dose is administered at time = 0.  In your code the STEP01 data set's first observation is at time=0.1.  That means when PROC MODEL integrates these ODEs it uses a1=400, and a2=0 as the initial conditions at time=0.1.  To set the initial conditions a1=400, and a2=0 at time=0 you should add an extra observation with time=0 and conc=0 to the top of your data set.


Regarding adding a pulse, or bolus, dose to the first equation you could use code like the following:

dert.A1 = -ka * A1 + dose*dirac(time - tbolus);

after first defining a dirac function using PRC FCMP:

proc fcmp outlib=work.funcs.f;
  function dirac(args[*]) varargs;
     x = args[1];
     if dim (args) = 1 then
         delta = 1e-6;
        delta = args[2];
     if abs(x) < delta then
         f = (delta - abs(x))/(delta*delta);
         f = 0;
     return (f);

options cmplib=funcs;

You would need to define the TBOLUS, and DOSE variables either in your data set, or your model program.


Respected Advisor
Posts: 2,655

Re: Parameter estimation with proc model and ODEs

Sweet answer to use FCMP to come up with a Dirac function for a pulse input.  That's something I wish I had known about $) years ago (of course, there was no PROC MODEL then, let alone PROC FCMP).


Steve Denham



Ask a Question
Discussion stats
  • 4 replies
  • 3 in conversation