Syntax Example for PROC MODEL

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

                    SAS Sample Library

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

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

title 'Holzman Function (1969), Himmelblau No. 21, N=3';
data zero;
   do i = 1 to 99;
      output;
   end;
run;

proc model data=zero;
   parms x1= 100 x2= 12.5 x3=  3;
   bounds .1 <= x1 <= 100,
           0 <= x2 <=  25.6,
           0 <= x3 <=   5;

   t = 2 / 3;
   u = 25 + (-50 * log(0.01 * i )) ** t;
   v = (u - x2) ** x3;
   w = exp(-v / x1);
   eq.foo = -.01 * i + w;

   fit foo / method=marquardt;
run;

title;

data d;
   date = 0;
run;

proc model data=d;
   endo x;
   bounds x < 0;

   eq.sqrt = x**2 - 4;

   solve / optimize out=o;
run;

proc print data = o; run;

/*------ data set for fit task------ */
data a ;
   do group = 1 to 3 ;
      do i = 1 to 100 ;
         x = normal(1);
         y = 2 + 3*x + rannor(1) ;
         output ;
      end ;
   end ;
run ;

/*------ data set for solve task------ */
data d ;
   do group = 1 to 3 ;
      x = normal(1) ;
      output ;
   end ;
run ;

/* ------  2 BY statements, one of them appear after SOLVE statement ------ */
proc model data = a ;
   by group ;
   y = a0 + a1*x ;
   fit y / outest = b1 ;
   solve y / data = d estdata = b1 out = c1 ;
   by group ;
run;

proc print data = b1 ;run;
proc print data = c1 ; run;

/*------ 1 BY statement that appears before SOLVE statement------ */
proc model data = a ;
   by group ;
   y = a0 + a1*x ;
   fit y / outest = b2 ;
   solve y / data = d estdata = b2 out = c2 ;
run;

proc print data = b2 ; run;
proc print data = c2 ; run;

/*------ 1 BY statement that appears after SOLVE statement------*/
proc model data = a ;
   y = a0 + a1*x ;
   fit y / outest = b3 ;
   solve y / data = d estdata = b3 out = c3 ;
   by group ;
run;

proc print data = b3 ; run;
proc print data = c3 ; run;

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
;

title 'Segmented Model -- Quadratic with Plateau';
proc model data=a;

   x0 = -.5 * b / c;

   if x < x0 then y = a + b*x + c*x*x;
   else           y = a + b*x0 + c*x0*x0;

   fit y start=( a .45 b .5 c -.0025 );

   estimate 'Join point' x0 ,
            'plateau' a + b*x0 + c*x0**2 ;
run;

title;

data d;
   do i = 0 to 1;
      date=i;
      if i = 0 then r = -1;
      else          r = +1;
      output;
   end;
run;


proc model data=d ;
   endo x y;

   eq.a = x*x - 4;
   eq.b = y*y - 9;

   restrict x*y*r > 1;

   solve /  optimize out=o outall;
quit;

proc print data = o; run;