Code for the Linear Regression Example

SAS/STAT must be installed on the system in order to successfully run this code.
data sportscars;
  set sashelp.cars;
  if type = "Sports";
  run;
proc print data=sportscars;run;

data sportscars2 (keep= horsepower mpg_city shortname);
  set sportscars;
  id=find(strip(model), " ");
  put model id;
  if (id > 0) then shortname=substr(model, 1, id);
  run;
proc print data=sportscars2;run;

proc sort data=sportscars2;
   by shortname;
   run;

proc means data=sportscars2;
  by shortname;
  var horsepower mpg_city;
  output out=sasuser.sportsCarsMean
         mean = HP MPG;
  run;
proc print data=sasuser.sportsCarsMean;run;


title 'Linear Regression';
proc reg data=sasuser.sportsCarsMean outest=sportscarfit_est;
   model hp=mpg;
   output out=sasuser.sportsCarMeanFit
          lcl=lower
          ucl=upper
		  lclm=lowermean
		  uclm=uppermean
          predicted=predict;
   run;

proc sort data=sasuser.sportsCarMeanFit;
   by mpg;
   run;

proc print data=sasuser.sportsCarMeanFit;  run;
/* */

ods listing sge=on style=Listing;
ods graphics on / reset width=400px imagename='CarsLabels';
proc sgplot data=sasuser.sportsCarMeanFit;
  band x=mpg upper=uppermean lower=lowermean / name='band' 
             legendlabel='Confidence';
  scatter x=mpg y=hp / dataLabel=shortname name='plot';
  series x=mpg y=predict / name='predict' legendlabel='Predicted';
  xaxis grid;
  yaxis grid;
  keylegend 'predict' 'band' / across=1 location=inside 
             position=TOPRIGHT;
run; 
ods listing close;
title;