BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello dears sas users
My problem is the following:
imagine that i have a plot to draw and i want also to add in the graphic an equation
like Y=X
is it possible ?
because for the moment, i work like that but if there is a shorter and easier way to do it, it would be nice
here is my code:

data class;
set sashelp.class end=fin;
x_1= _n_ * 3;
y_1= _n_ * 3;
weight=weight/2;
if _n_ = 1 then do;; x_1=0; y_1=0; end;
if fin then do; x_1=80; y_1=80; end;
run;

goptions reset=all;
title 'is there a shorter way ???';

symbol1 color=red
interpol=join
value=dot
height=3;

symbol2 value=none
color=black
interpol=join
height=2;

axis1 order=(0 to 100 by 20) offset=(0,0)
label=none
major=(height=2) minor=(height=1)
width=3;

axis2 order=(0 to 100 by 20) offset=(0,0)
label=none
major=(height=2) minor=(height=1)
width=3;

proc gplot data=class;
plot height*weight x_1*y_1 / overlay haxis=axis1 vaxis=axis2 ;
run;
quit;

may be is a dream but it would be very nice if the following code exists;

proc gplot data=sashelp.class;
plot height*weight;
equation Y=X; (this isn't exist yet)
run;
quit;

Thank you very much for yours answers.
3 REPLIES 3
ChrisNZ
Tourmaline | Level 20
The alternative is to use annotation, but that's not simpler.

This allows to manage the 2 plots' data separately:

data class;
set sashelp.class;
weight=weight/2;
output;
if _n_ = 1 then do;
do x_1=0 to 100 by 5;
y_1=x_1**1.2 - 1.5*x - 5 ;
output;
end;
end;
run;
GraphGuy
Meteorite | Level 14
If you're doing a regression like, you can use the 'regeqn' gplot option, such as:

symbol1 interpol=rcclm95 value=circle cv=red ci=pink co=blue;
proc gplot data=sashelp.class;
plot height*weight=1 / regeqn;
run;

-----

Otherwise, you can use the 'note' option to print some text (equation) such as:

symbol v=dot i=none;
proc gplot data=sashelp.class;
plot height*weight;
note move=(20,80)pct c=blue height=3.5pct font="arial" 'Y=X';
run;

-----

If the equation doesn't have to be on the graph itself, you can put some text in a
'title2' or a 'footnote' statement.

And, of course, you could annotate some text for the equation.

And, if the equation doesn't lend itself to a simple single line of text, you could
create a jpg image containing the equation (created using a fancy word-processor
or other tool) and then annotate that image onto the graph.

-----
deleted_user
Not applicable
Thank you for yours answers

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1522 views
  • 0 likes
  • 3 in conversation