%let gpath='C:\';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
data cars;
set sashelp.cars(where=(type ne 'Hybrid'));
keep type mpg_city horsepower;
run;
proc sort data=cars out=cars_type;
by type;
run;
data cars_type_label_all;
set cars_type;
label=substr(type, 1, 2);
run;
/*proc print;run;*/
data cars_type_label;
set cars_type;
by type;
if first.type then id=0;
id+1;
if mod(id, 10)=1 then label=substr(type, 1, 2);
run;
/*proc print;run;*/
proc sort data=cars_type_label_all out=cars_type_label_all_hp;
by horsepower;
run;
proc sort data=cars_type_label out=cars_type_label_hp;
by horsepower;
run;
/*--Series Curve--*/
/*ods graphics / reset attrpriority=color width=5in height=3in imagename='CurveSeries';*/
/*title 'Mileage by Horsepower and Type';*/
/*proc sgplot data=cars_type_label_hp;*/
/* series x=horsepower y=mpg_city / group=type;*/
/* keylegend / title='';*/
/* run;*/
/*--Series Curve Labels--*/
/*ods graphics / reset attrpriority=color width=5in height=3in imagename='CurveSeriesLabel';*/
/*title 'Mileage by Horsepower and Type';*/
/*proc sgplot data=cars_type_label_hp;*/
/* series x=horsepower y=mpg_city / group=type name='s';*/
/* scatter x=horsepower y=mpg_city / group=type markerchar=label;*/
/* keylegend 's' / title='';*/
/* run;*/
/*--Reg Curve--*/
/*ods graphics / reset attrpriority=color width=5in height=3in imagename='CurveRegLabel';*/
/*title 'Mileage by Horsepower and Type';*/
/*proc sgplot data=cars_type_label_hp;*/
/* reg x=horsepower y=mpg_city / degree=3 nomarkers group=type name='s';*/
/* scatter x=horsepower y=mpg_city / group=type markerchar=label;*/
/* keylegend 's' / title='';*/
/* run;*/
/*--Get Reg Curve Data--*/
ods output sgplot=RegData;
ods graphics / reset attrpriority=color width=5in height=3in imagename='CurveReg';
title 'Mileage by Horsepower and Type';
proc sgplot data=cars_type_label_hp;
reg x=horsepower y=mpg_city / degree=3 nomarkers group=type name='s';
keylegend 's' / title='';
run;
/*proc print;run;*/
ods output sgplot=foo;
ods graphics / reset attrpriority=color width=5in height=3in imagename='CurveRegScatter';
title 'Mileage by Horsepower and Type';
proc sgplot data=cars_type_label_all_hp;
reg x=horsepower y=mpg_city / degree=3 nomarkers group=type name='s';
scatter x=horsepower y=mpg_city / group=type markerchar=label;
keylegend 's' / title='';
run;
data RegCurves;
set RegData(rename=(Regression_Horsepower_mpg_cit__x=x
Regression_Horsepower_mpg_cit__y=y
Regression_Horsepower_mpg_cit_gp=group));
label y2='MPG (City)';
keep x y group id label2 y2;
by group;
if first.group then id=0;
id+1;
if mod(id, 30)=1 or last.group then do; label2=substr(group, 1, 2); y2=y; end;
run;
/*proc print;run;*/
ods output;
ods graphics / reset attrpriority=color width=5in height=3in imagename='CurveRegLabel';
title 'Mileage by Horsepower and Type';
proc sgplot data=RegCurves;
reg x=x y=y / degree=3 nomarkers group=group name='s';
scatter x=x y=y / group=group markerchar=label2;
keylegend 's' / title='';
run;
ods graphics / reset attrpriority=color width=5in height=3in imagename='CurveRegLabel_2';
title 'Mileage by Horsepower and Type';
proc sgplot data=RegCurves;
reg x=x y=y / degree=3 nomarkers group=group name='s';
scatter x=x y=y2 / group=group markerattrs=(size=14 symbol=circlefilled)
filledoutlinedmarkers markerfillattrs=(color=white);
scatter x=x y=y2 / group=group markerchar=label2 markercharattrs=(size=5 weight=bold);
keylegend 's' / title='';
run;
ods listing image_dpi=100;
ods graphics / reset attrpriority=color width=2.7in height=1.8in imagename='CurveRegLabel_Icon';
title 'Mileage by Horsepower and Type';
proc sgplot data=RegCurves noautolegend;
reg x=x y=y / degree=3 nomarkers group=group name='s';
scatter x=x y=y2 / group=group markerattrs=(size=14 symbol=circlefilled)
filledoutlinedmarkers markerfillattrs=(color=white);
scatter x=x y=y2 / group=group markerchar=label2 markercharattrs=(size=5 weight=bold);
run;