/*-----------------------------------------------------------------
            S A S   S A M P L E   L I B R A R Y                   
                                                                  
      NAME: RSRGS                                                 
     TITLE: Details Example for PROC RSREG                        
   PRODUCT: STAT                                                  
    SYSTEM: ALL                                                   
      KEYS: response surface regression                           
     PROCS: RSREG                                                 
      DATA:                                                       
                                                                  
   SUPPORT: Bob Derr                                              
       REF: SAS/STAT User's Guide, PROC RSREG chapter             
      MISC:                                                       
                                                                  
-----------------------------------------------------------------*/

/*----------------------------------------------------------------
Searching for Multiple Response Conditions
----------------------------------------------------------------*/


data a;
   input x1 x2 y1 y2 y3;
   datalines;
-1      -1         1.8 1.940  3.6398
-1       1         2.6 1.843  4.9123
 1      -1         5.4 1.063  6.0128
 1       1         0.7 1.639  2.3629
 0       0         8.5 0.134  9.0910
 0       0         3.0 0.545  3.7349
 0       0         9.8 0.453 10.4412
 0       0         4.1 1.117  5.0042
 0       0         4.8 1.690  6.6245
 0       0         5.9 1.165  6.9420
 0       0         7.3 1.013  8.7442
 0       0         9.3 1.179 10.2762
 1.4142  0         3.9 0.945  5.0245
-1.4142  0         1.7 0.333  2.4041
 0       1.4142    3.0 1.869  5.2695
 0      -1.4142    5.7 0.099  5.4346
;


data b;
   set a end=eof;
   output;
   if eof then do;
      y1=.;
      y2=.;
      y3=.;
      do x1=-2 to 2 by .1;
         do x2=-2 to 2 by .1;
            output;
         end;
      end;
   end;
run;


proc rsreg data=b out=c;
   model y1 y2 y3=x1 x2 / predict;
run;

data d;
   set c;
   if y2<2;
   if y3<y2+y1;

proc sort data=d;
   by descending y1;
run;

data d; set d;
   if (_n_ <= 5);
proc print;
run;

ods graphics on;
proc rsreg data=a plots=surface(overlaypairs);
   model y1 y2=x1 x2;
run;
ods graphics off;