Resources

Programming Language Example for PROC MODEL

/*--------------------------------------------------------------

                    SAS Sample Library

        Name: modpl.sas
 Description: Example program from SAS/ETS User's Guide,
              The MODEL Procedure
       Title: Programming Language Example for PROC MODEL
     Product: SAS/ETS Software
        Keys: nonlinear simultaneous equation models
        PROC: MODEL
       Notes:

--------------------------------------------------------------*/
/*--- Examples from the Programming Language Section of the
       MODEL Procedure ---*/

/*---  Equation Translations  ---*/

data line;
  do t = 1 to 20;
     x = 5 * ranuni(1234);
     x1 = x;
     x2 = x*x;
     y = 10 + 2 * x;
     output;
  end;
run;
proc model data=line list;
   y = a1 + b1*x1 + c1*x2;
   fit y;
run;
proc model data=line ;
   y = a1 + b1**2 *x1 + c1*x2;
   Dy_a1 = getder(PRED.y,a1);
   Dy_b1 = getder(PRED.y,b1);
   Dy_c1 = getder(PRED.y,c1);
   outvars Dy_a1 Dy_b1 Dy_c1;
   fit y / out=grad;
run;
/*--- Diagnostics and Debugging ---*/

*---------Fitting a Segmented Model using MODEL----*
|      |                                           |
|   y  | quadratic          plateau                |
|      | y=a+b*x+c*x*x      y=p                    |
|      |                     ..................... |
|      |              .     :                      |
|      |          .         :                      |
|      |       .            :                      |
|      |     .              :                      |
|      |    .               :                      |
|      +-----------------------------------------X |
|                          x0                      |
|                                                  |
| continuity restriction: p=a+b*x0+c*x0**2         |
| smoothness restriction: 0=b+2*c*x0 so x0=-b/(2*c)|
*--------------------------------------------------*;
title 'QUADRATIC MODEL WITH PLATEAU';
data a;
   input y x @@;
datalines;
.46 1  .47  2 .57  3 .61  4 .62  5 .68  6 .69  7
.78 8  .70  9 .74 10 .77 11 .78 12 .74 13 .80 13
.80 15 .78 16
;

proc model data=a list xref listcode;
   parms a 0.45 b 0.5 c -0.0025;

   x0 = -.5*b / c;      /* join point */
   if x < x0 then       /* Quadratic part of model */
      y = a + b*x + c*x*x;
   else                 /* Plateau part of model */
      y = a + b*x0 + c*x0*x0;

   fit y;
run;
   title;