BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellohere
Pyrite | Level 9
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. 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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;

View solution in original post

8 REPLIES 8
hellohere
Pyrite | Level 9

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?!

FreelanceReinh
Jade | Level 19

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;
hellohere
Pyrite | Level 9
How to make a HREF(Horizontal RefLine)?! at y-axis, say y=100?
hellohere
Pyrite | Level 9
SAS DOC gives out example below. Somehow I tried and did not show up?!
proc sgplot data=out;
scatter x=s y=residual_q;
refline 0 / axis=y;
run;
Ksharp
Super User
/*
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;
FreelanceReinh
Jade | Level 19

@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
Pyrite | Level 9
thanks for reply. It still does not show up. The issue might be that I am using y2axis. Still confusing though...
FreelanceReinh
Jade | Level 19

@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;

 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1369 views
  • 0 likes
  • 3 in conversation