SAS: How do I rename an axis label name on sgplot scatter plot

5.8k Views Asked by At

I'm an Animal science student from Slovenia and I'm just finishing my master's thesis. For the finishing touches i need to make a bunch of scatter plots of different traits. All my data values (breeding values of different traits) are in code, for example m_pv10 (omišičenost = muscularity), m_pv31 (age of first calving),... To make the scatter plots easier to read i'd like to rename the x and y-axis labels from m_pv31 to "Age of first calving". I have tried renaming the values in a data step to bypass this problem but some names of the traits include spaces "age of first calving" and no nregular letters as "š" and "č" so the data step won't work.

data datam_copy;
   set datam_copy;
   rename m_pv10=Omišičenost;
          m_pv31=Starost ob prvi telitvi;
          m_pv12=Vime;run;

Is there a way to rename the axis labels directly in the sgplot code? I would be very tratefull for any suggestions.

Urban

2

There are 2 best solutions below

0
On

You can have spaces in the name but generally not a great idea though. Not sure how the accents will work though.

options validvarname = any;

data datam_copy;
   set datam_copy;
   rename m_pv10= 'Omišičenost'n;
          m_pv31= 'Starost ob prvi telitvi'n;
          m_pv12= 'Vime'n;
run;
0
On

You can use the variable label, if that is the level you're working at. Here's an example.

data have;
  set sashelp.class;
  label age="Age of student"
        height="Height of student"
        weight="Weight of student"
        ;
run;

proc sgplot data=have;
  vline age/response=height;
  vline age/response=weight y2axis;
run;
  

You can rename the variable also of course, but this is really the job of the variable label. You can also use the label statement directly in sgplot.

proc sgplot data=sashelp.class;
  vline age/response=height;
  vline age/response=weight y2axis;
  label age="Age of student"
        height="Height of student"
        weight="Weight of student"
        ;
run;