Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Graphics
- /
- How to change X axis label for Proc GLM plots?

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-28-2020 10:18 PM
(2812 views)

Dear Community,

I would like to rename the axes for the plots received after using PROC GLM for a 2 way ANONA equation. I have managed to change the title for the plots and Y-axis. but I do not know how to proceed with x-axis labeling. These are the lines for my program:

option validvarname=any;

PROC GLM Data= work.BN (rename=NDF='NDF(dm), (%)'n) plots=(diagnostics);

CLASS Treatment ;

Model 'NDF(dm), (%)'n = Time |Treatment/solution;

Lsmeans Treatment /cl pdiff adjust=Tukey lines Stderr;

run;

quit;

Thank you and greatly appreciate your time and help.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi @VT89 ,

Actually please use this SGPLOT code. It has the legend title too.

```
proc sgplot data = ANCOVAPlot;
scatter x = _X7 y = _YVAR / group = _GROUP_OBS;
series x = _XCONT1 y = _Predicted_FIT / group = _GROUP_FIT name="series_leg";
keylegend "series_leg" / title = "Treatment" across=2 exclude=("") border;
yaxis label = "NDF(dm), (%)";
xaxis label = "X axis";
run;
```

8 REPLIES 8

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello @VT89 ,

One way you can do it is to go edit the template that is creating the plot. Is it the diagnostics plot that you would like to change? If you update your dataset and the plot that you would like to change then it could be easier to assist you.

An example of editing the template behind the plot is first using ods trace on, to locate the template, and the obtain the code for the template, such as by using -

proc template;

source Stat.GLM.Graphics.FitSummary;

run;

After that you can modify the template.

It's probably easier just to output your dataset from Proc GLM though, and then use SGPLOT to create the plot and customize the axis.

Thanks,

Kriss

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello,

Thank you so much for replying to my query. I am pasting the data I used for creating the plots. I was able to change the title for fit diagnostics plots but I could not find an easy way to edit ANCOVA plot x axis. I do not really know how to use proc template and I did give it a try before posting my question. I was thinking about using proc sgplot but I do not know how I can plot ANCOVA plot using sgplot. If I know how to then it would be easy to edit the axis and more.

Here is the data used for my equation.

SampleType | Treatment | Time | PlantPortion | ndfpw |

BN | S_I | 0 | F | 3.326147 |

BN | S_I | 0 | F | 4.085303 |

BN | S_I | 0 | F | 7.798459 |

BN | S_I | 0 | F | 1.854164 |

BN | S_I | 0 | F | 8.403201 |

BN | S_I | 0 | F | NA |

BN | S_I | 3 | F | 4.378336 |

BN | S_I | 3 | F | 5.970024 |

BN | S_I | 3 | F | 4.991754 |

BN | S_I | 6 | F | 6.077845 |

BN | S_I | 6 | F | 5.119463 |

BN | S_I | 6 | F | 7.625552 |

BN | S_I | 9 | F | 4.898555 |

BN | S_I | 9 | F | 5.667297 |

BN | S_I | 9 | F | 5.862422 |

BN | S_I | 12 | F | 8.046645 |

BN | S_I | 12 | F | 8.79686 |

BN | S_I | 12 | F | 8.624618 |

BN | S_NI | 0 | F | 1.854164 |

BN | S_NI | 0 | F | 8.403201 |

BN | S_NI | 0 | F | NA |

BN | S_NI | 0 | F | 3.326147 |

BN | S_NI | 0 | F | 4.085303 |

BN | S_NI | 0 | F | 7.798459 |

BN | S_NI | 3 | F | 7.225144 |

BN | S_NI | 3 | F | 6.853081 |

BN | S_NI | 3 | F | 6.329218 |

BN | S_NI | 3 | F | 8.708655 |

BN | S_NI | 6 | F | 4.530356 |

BN | S_NI | 6 | F | 6.884661 |

BN | S_NI | 6 | F | 9.946883 |

BN | S_NI | 6 | F | 8.250516 |

BN | S_NI | 9 | F | 6.647393 |

BN | S_NI | 9 | F | 6.343426 |

BN | S_NI | 9 | F | 5.817403 |

BN | S_NI | 9 | F | 5.767742 |

BN | S_NI | 12 | F | 7.546846 |

BN | S_NI | 12 | F | 6.657135 |

BN | S_NI | 12 | F | 6.755493 |

BN | S_NI | 12 | F | 3.543603 |

I really appreciate any help you can provide. Thank you again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello @VT89,

You're welcome. You can try this code. Basically I've used the ODS statement to output the AncovaPlot dataset. And then I've used Proc SGPLOT to plot the graph. I believe you are after the Ancova graph? You can now change the XAXIS label and also the graph title more easily.

The legend is a little different from before, i.e. there's only the line, instead of the line and marker, but I think that's okay?

```
ods output ANCOVAPlot = ANCOVAPlot;
PROC GLM Data= work.BN plots=(diagnostics);
CLASS Treatment ;
Model NDFPW = Time |Treatment/solution;
Lsmeans Treatment /cl pdiff adjust=Tukey lines Stderr;
run;
quit;
proc sgplot data = ANCOVAPlot;
scatter x = _X7 y = _YVAR / group = _GROUP_OBS;
series x = _XCONT1 y = _Predicted_FIT / group = _GROUP_FIT name="series_leg" legendlabel = "Treatment";
keylegend "series_leg" / exclude=("");
yaxis label = "NDF(dm), (%)";
xaxis label = "X axis";
run;
```

Thanks,

Kriss

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi @VT89 ,

Actually please use this SGPLOT code. It has the legend title too.

```
proc sgplot data = ANCOVAPlot;
scatter x = _X7 y = _YVAR / group = _GROUP_OBS;
series x = _XCONT1 y = _Predicted_FIT / group = _GROUP_FIT name="series_leg";
keylegend "series_leg" / title = "Treatment" across=2 exclude=("") border;
yaxis label = "NDF(dm), (%)";
xaxis label = "X axis";
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Awesome! Thank you so much again, Kriss. I really appreciate your help. This works well. The proc template would have been a hard way for me to go, at least I know sgplot use.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You're welcome! I'm glad it helped! Yes ,the SGPLOT is more flexible and easier to adapt.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello@djrisks

I found this code really helpful. I improved on it as follows

**Simple Regression Model**

Proc glm data= Tdata;

ods output FitPlot = Fit_Plot;

where LBTEST in("Alanine Aminotransferase");

model LFTvalues = bckTrans_auc/ solution;

run;

where LBTEST in("Alanine Aminotransferase");

model LFTvalues = bckTrans_auc/ solution;

run;

**The Plot **

proc sgplot data = Fit_Plot;

scatter x = _X3 y = _YVAR ;

series x = _XCONT1 y = _Predicted_FIT;

keylegend "series_leg" / exclude=("");

yaxis label = "AST (Units per liter)";

xaxis label = "AUC(h*ng/mL)";

run;

scatter x = _X3 y = _YVAR ;

series x = _XCONT1 y = _Predicted_FIT;

keylegend "series_leg" / exclude=("");

yaxis label = "AST (Units per liter)";

xaxis label = "AUC(h*ng/mL)";

run;

The above code just gives me a scattered plot with a regression line. I would like some help with improvement on this script to give me the attached sample plot where the regression line is aligned within the bounds of 95%CI. I will appreciate any assistance I can get.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate 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 16. Read more here about **why** you should contribute and **what is in it** for you!

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.