BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
angelface123ish
Fluorite | Level 6

In Proc gplot, is it possible to create different labels for the y-axis within the same program? I am using an annotate data set. Please advise.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  When I try this code using AXIS statements with macro variables for the Axis Labels, it works for me.

goptions reset=all noborder;
title "Study of Height vs Weight";

%let lb1 = Height Graph 1;
%let lb2 = Predicted Weight Graph 2;
%let lb3 = Weight;
 
axis1 label=(color=green h=12pt "&lb1");
axis2 label=(color=purple h=12pt "&lb2");
axis3 label=(color=red h=12pt "&lb3");
  
options orientation=landscape topmargin=1in bottommargin=1in nodate nonumber;
ods rtf file='c:\temp\gplottest.rtf';
proc gplot data=sashelp.class;
   title2 'SASHELP.CLASS';
   plot height*weight / vaxis=axis1 haxis=axis3;
run;
quit;
  
proc gplot data=sashelp.classfit;
   title2 'SASHELP.CLASSFIT';
   plot predict*weight / vaxis=axis2 haxis=axis3;
run;
quit;

ods rtf close;

  These screen shots were taken in PRINT PREVIEW after Word opened the RTF file, but you can see the different colors for each AXIS label was used correctly (even if the print is very small).

Cynthia_sas_0-1649871242992.png

 

Cynthia

View solution in original post

8 REPLIES 8
ballardw
Super User

Is your Annotated data set writing the text for the Y axis label? If not then that has nothing to do with that.

 

If you are actually using GPLOT you may want to consider moving to the much newer SGPLOT that is a tad more flexible.

In the traditional device based graphics procedures like Gplot and Gchart you provide the description of the axis, including the label in an AXIS statement. You can have upto 99 Axis statements defined at any given time. When you create the axis statement the first thing is the number Axis (or Axis1), Axis2 etc. Then you specify in the graph procedure which axis to use in a given role. The same axis definition could the Y axis in one graph, the X axis in another and the Z axis in a 3D plot, plus with Gchart you have "mid" axis options.

 

So Yes you can have different labels because you can create a different label in each axis statement.

 

In the newer Sgplot and Sgpanel you have a Yaxis (or Yaxis2 for the other side of the graph) statement available to define the label and tick mark options for that procedure call.

 

One reason to use SGplot instead of Gplot is that it will do everything Gplot and Gchart do plus many more and overlaying multiple types of graphs (there are limits of which can go with which) is MUCH easier.

angelface123ish
Fluorite | Level 6
Hello. Thank you so much for your informative reply. Unfortunately, I have to use gplot as part of a project. Can you please explain what you mean when you say graphing procedure? Also, if I use the rtf output, Will my plots with different labels on the y axis show up in the same document?
ballardw
Super User

Graphing procedure: the procedure that produces graphs: Gplot, Gchart, Gbarline, Gcontour, Gradar and G3d in the traditional device based graphs. Gmap as well but that does not use Axis statements but does use Pattern and Legend.

 

If you create the document properly, yes all the graphs in the RTF (or PDF or other ODS destination) will have their own labels. This is done by placing all the output generating procedures within on "ODS Sandwich"; and ODS destination start and Ods close pair:

Dummy code:

ods rtf file="C:\folder\mydocument.rtf" <any other options>;

<proc gplot code to create first graph>

<proc gplot code to create second graph>

<other output code>

ods rtf close;

@angelface123ish wrote:
Hello. Thank you so much for your informative reply. Unfortunately, I have to use gplot as part of a project. Can you please explain what you mean when you say graphing procedure? Also, if I use the rtf output, Will my plots with different labels on the y axis show up in the same document?

I would question exactly why Gplot is specified. What if you need to make a graph that Gplot can't make? Gplot does  very few types of plots. Note that quite a few of the different types of "plots" involve the definition in SYMBOL statements as well.

angelface123ish
Fluorite | Level 6
Thank you again for this. I am using a macro . When I use the %let statement for the label, the y axis labels still all come out the same.
Cynthia_sas
SAS Super FREQ

Hi:

  When I try this code using AXIS statements with macro variables for the Axis Labels, it works for me.

goptions reset=all noborder;
title "Study of Height vs Weight";

%let lb1 = Height Graph 1;
%let lb2 = Predicted Weight Graph 2;
%let lb3 = Weight;
 
axis1 label=(color=green h=12pt "&lb1");
axis2 label=(color=purple h=12pt "&lb2");
axis3 label=(color=red h=12pt "&lb3");
  
options orientation=landscape topmargin=1in bottommargin=1in nodate nonumber;
ods rtf file='c:\temp\gplottest.rtf';
proc gplot data=sashelp.class;
   title2 'SASHELP.CLASS';
   plot height*weight / vaxis=axis1 haxis=axis3;
run;
quit;
  
proc gplot data=sashelp.classfit;
   title2 'SASHELP.CLASSFIT';
   plot predict*weight / vaxis=axis2 haxis=axis3;
run;
quit;

ods rtf close;

  These screen shots were taken in PRINT PREVIEW after Word opened the RTF file, but you can see the different colors for each AXIS label was used correctly (even if the print is very small).

Cynthia_sas_0-1649871242992.png

 

Cynthia

angelface123ish
Fluorite | Level 6
Thank you so much for this!
angelface123ish
Fluorite | Level 6

In Proc Gplot, I want to create a different y axis label for each of the plots. How can I do this?

ballardw
Super User

Merged duplicate thread.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 808 views
  • 1 like
  • 3 in conversation