BookmarkSubscribeRSS Feed
thorstenlehr
Calcite | Level 5

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.

Thorsten

 

ata step01;
INPUT time     conc;
datalines;
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
run;

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

run;
quit;

4 REPLIES 4
SteveDenham
Jade | Level 19

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

thorstenlehr
Calcite | Level 5

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

Thorsten

kessler
SAS Employee

Thorsten,

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 = .;
run;   

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;
     else
        delta = args[2];
     if abs(x) < delta then
         f = (delta - abs(x))/(delta*delta);
     else
         f = 0;
     return (f);
  endsub;
run;

options cmplib=funcs;

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

Marc

SteveDenham
Jade | Level 19

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

 

 

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!

Multiple Linear Regression in SAS

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.

Discussion stats
  • 4 replies
  • 1285 views
  • 4 likes
  • 3 in conversation