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

Hi,

I am migrating from SAS/GRAPH to ODS Graphics and wonder about the equivalent of ORIGIN and LENGTH options of the SAS/GRAPH AXIS statement in ODS.

In SAS/GRAPH, one can specify that an axis starts at coordinates (20, 20)PCT of the output area and has a length of 70PCT. This is very useful to generate all kind of graphs that will align nicely in the produced documents.

Is there an equivalent in ODS Graphics? I have read the GTL literature quite in depth and could not find any such things.

Any help appreciated,

Xavier.

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

If you want the axis lines vertically aligned despite having vastly different tick values, you will need to use the features of the SGPANEL procedure, putting all the graphs that need to be aligned in one multi-cell graph.  This will be a CLASS panel, so you get column of cells, one cell per group value.

 

For true alignment of varied cells (but still in one graph), you will need to use GTL (SGRENDER) with the LAYOUT LATTICE structure.  See the example at the bottom of this linked page of a BarChart and ScatterPlot where the Y axes are aligned despite the different tick values:

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatug&docsetTarget=n11...

 

You may be able to force individual graphs per cell by setting ROWS=1 and COLUMNS=1.

 

View solution in original post

10 REPLIES 10
Rick_SAS
SAS Super FREQ

I suggest you use the REFLINE statement to place vertical and horizontal lines at the locations that you want in data coordinates. For example, the following statements place reference lines at X=0 and Y=0. You can also change the default thickness or color by using the LINEATTRS= option, as shown in the second example.

 

data Center;   /* center the variables */
set sashelp.class;
Height = Height - 62.3;
Weight = Weight - 100;
run;

proc sgplot data=Center;
   refline 0 / axis=x;
   refline 0 / axis=y;
   scatter x=Height y=Weight;
run;

proc sgplot data=Center;
   xaxis grid;
   yaxis grid;
   refline 0 / axis=x lineattrs=(color=darkgray);
   refline 0 / axis=y lineattrs=(color=darkgray);
   scatter x=Height y=Weight;
run;

If you really want to place a line in terms of percentage, you can use an annotation data set. There are several coordinate systems for drawing, and you can use percentages in each system, as shown in the documentation for the SG annotation data sets.

Xavier_Draye
Calcite | Level 5

Hi Rick,

Thank you for your message. May be my question is not well explained. Here is what I would like to control (the two blue arrows):

Capture.PNG

Thanx,

Xavier.

Rick_SAS
SAS Super FREQ

Sanjay already told you how to control that space:

 

title "My Title";
proc sgplot data= sashelp.class pad=(left=20pct bottom=20pct);
   scatter x=Height y=Weight;
run;
Xavier_Draye
Calcite | Level 5

Thanx Rick, but I am afraid this is not right. The PAD option controls the space around the whole [graph + label + ticks] area. See the example below: it adds the extra blue space. It does not allow me to set the distance between the axis and the border of the graphic output.

Capture.PNG

Jay54
Meteorite | Level 14

To control the white space outside the axes, you can use the PAD option.

  proc sgplot data=data pad=(bottom=15pct).

 

See doc for full details.

Xavier_Draye
Calcite | Level 5
Thank you for this answer. From my tests, it seems that the PAD option creates empty space around the whole area (including axis label and tick values). This will not prevent SAS to adjust the position of the axis line to accomodate for the needed space for ticks and label.
ballardw
Super User

@Xavier_Draye wrote:
Thank you for this answer. From my tests, it seems that the PAD option creates empty space around the whole area (including axis label and tick values). This will not prevent SAS to adjust the position of the axis line to accomodate for the needed space for ticks and label.

Please share the code and example data that you are using to test this.

You may need to provide the version of SAS you are running and ODS destination(s) as well. The graphics have been one of the fastest changing elements in the past few releases and specific version info may be needed to diagnose options.

Xavier_Draye
Calcite | Level 5

Hi, 

I am using SAS 9.4 (TS1M4), Win10, 64.

Here is an examle of SAS code :

data sample (drop = i);
  do i = 1 to 50;
    x = rannor(-1);
	ysmall = rannor(-1);
	ylarge = ysmall * 1e3;
	output;
  end;
run;

ods graphics on / reset = all width = 9cm height = 6cm;

proc sgplot data = sample pad = (left = 2cm);
  scatter x = x y = ysmall;
  inset "pad = (left = 2cm)" "Small y values";
  xaxis label = "X axis label";
  yaxis label = "Y axis label";
run;

proc sgplot data = sample pad = (left = 2cm);
  scatter x = x y = ylarge;
  inset "pad = (left = 2cm)" "Large y values";
  xaxis label = "X axis label";
  yaxis label = "Y axis label";
run;

I have annotated the output below. The red line shows what the PAD is doing (same value for the two graphs). I would like the two blue lines to be aligned (which is what the ORIGIN option of AXIS does in SAS/GRAPH).

Capture.PNG 

 

Jay54
Meteorite | Level 14

If you want the axis lines vertically aligned despite having vastly different tick values, you will need to use the features of the SGPANEL procedure, putting all the graphs that need to be aligned in one multi-cell graph.  This will be a CLASS panel, so you get column of cells, one cell per group value.

 

For true alignment of varied cells (but still in one graph), you will need to use GTL (SGRENDER) with the LAYOUT LATTICE structure.  See the example at the bottom of this linked page of a BarChart and ScatterPlot where the Y axes are aligned despite the different tick values:

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatug&docsetTarget=n11...

 

You may be able to force individual graphs per cell by setting ROWS=1 and COLUMNS=1.

 

Xavier_Draye
Calcite | Level 5
Thanx Jay. I was hoping to be able to achieve this alignement for independent graphs, as I used to do with SAS/GRAPH. I understand from your answer that this way of working is not supported by ODS Graphics. I'll therefore adopt the SGPANEL (I think SGSCATTER will do it as well) or LAYOUT LATTICE.
Have a nice day (midnight for me)...
Xavier.

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
  • 10 replies
  • 2485 views
  • 5 likes
  • 4 in conversation