refline 2800/axis=x lineattrs=(color=red thickness=2.0);
DOES one reference line inside SGPLOT. I am running a macro, need generate SGPLOT with multiple reference lines and the values are
varied (upto macro outcome).
Anyone knows how, assume the macro saves out reference line values into a set of macro variables, refvalues.
Hi @hellohere,
Can you modify the macro so that it concatenates the reference line values into a single macro variable? Then you could just refer to that macro variable in the REFLINE statement, as shown in the example below (which also uses optional labels for the reference lines).
%let refvalues=57.5 62.8 66.5;
%let reflabels="Q1" "Median" "Q3";
proc sgplot data=sashelp.class;
scatter x=height y=weight;
refline &refvalues / axis=x label=(&reflabels) labelloc=inside;
run;
One way I can think of is to store the refvalues into a dataset, and generate a text line for each reference value, and then passes into
PROC SGPLOT ... tedious though. Any straightforward way?!
Hi @hellohere,
Can you modify the macro so that it concatenates the reference line values into a single macro variable? Then you could just refer to that macro variable in the REFLINE statement, as shown in the example below (which also uses optional labels for the reference lines).
%let refvalues=57.5 62.8 66.5;
%let reflabels="Q1" "Median" "Q3";
proc sgplot data=sashelp.class;
scatter x=height y=weight;
refline &refvalues / axis=x label=(&reflabels) labelloc=inside;
run;
/*
That is due to your variable "residual_q" did not contains ZERO.
Add option NOCLIP in it.
*/
proc sgplot data=sashelp.class;
scatter x=weight y=height;
refline 0 / axis=y NOCLIP ;
run;
@hellohere wrote:
How to make a HREF(Horizontal RefLine)?! at y-axis, say y=100?
Add the statement
refline 100;
to the PROC SGPLOT step in my solution. The axis=y option is not necessary (but can be used for clarity) because the default axis for reference lines is the y-axis.
@hellohere wrote:
thanks for reply. It still does not show up. The issue might be that I am using y2axis.
Then specify axis=y2 as in the example below:
%let refvalues=57.5 62.8 66.5; %let reflabels="Q1" "Median" "Q3"; proc sgplot data=sashelp.class; scatter x=height y=weight / y2axis; refline &refvalues / axis=x label=(&reflabels) labelloc=inside; refline 100 / axis=y2 label="Your label" labelloc=inside; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.