Parameterized lines
are straight lines specified by a point and a slope. The statement
must be used with another plot statement that is derived from data
values that provide boundaries for the axis area. For example, the
LINEPARM statement can be used with a scatter plot or a histogram.
The following example
shows weight with respect to height for a class of students. A single
line is generated by specifying values for the point and for the slope.
The line in the example approximates a line of best fit.
|
proc sgplot data=sashelp.class
noautolegend;
scatter x=height y=weight;
lineparm x=50 y=50 slope=3.89;
run;
|
You can generate multiple
lines by specifying a numeric variable for any or all required arguments.
Examples are provided for the SGPLOT and the SGPANEL procedures. The
following two examples create lines of best fit for male and female
participants in a heart disease study. The lines show weight with
respect to height.
The examples first sort
the data set by male and female participants. The sorted data is output
to a data set named HEART.
proc sort data=sashelp.heart(keep=height weight sex)
out=heart;
by sex;
run;
The examples then use
the REG procedure and output the regression statistics to a data set
named STATS. The STATS data set includes the slope and the Y-intercept
for the regression.
proc reg data=heart
outest=stats(rename=(height=slope));
by sex;
model weight=height;
run;
Finally, the examples
merge the HEART and the STATS data sets.
data heartStats;
merge heart stats(keep=intercept slope sex);
run;
The first example uses
the SGPLOT procedure to show lines of best fit for females and males
in the study. The regression lines are labeled and have their own
legend.
|
proc sgplot data=heartStats;
scatter x=height y=weight;
lineparm x=0 y=intercept slope=slope /
name="Line" group=sex
curvelabel;
keylegend "Line";
run;
|
The following example
uses the SGPANEL procedure to create the same information, which is
paneled by gender.
|
proc sgpanel data=heartStats
noautolegend;
panelby sex;
scatter x=height y=weight;
lineparm x=0 y=intercept slope=slope;
run;
|
Options are available
that enable you to customize the line and enhance its appearance.
For example, you can do the following:
-
specify line attributes, labels,
and label attributes
-
specify legend labels and line
transparency
-
prevent the line from being extended
beyond the axis offset
Note: This list does not
include all available options.