Sample 24916: Plot X axis values in data order
This example creates a new horizontal axis variable that reflects the original ordering of the data and can be used to plot the data.
/*********************************************************/
/* Using the GPLOT Procedure, How Can I Have the */
/* Horizontal Axis Values Based on the Order in */
/* Which the Data is Read? */
/* */
/* The SAS System sorts the input data by the horizontal */
/* axis variable to come up with the default axis order. */
/* This example creates a new horizontal axis variable */
/* that reflects the original ordering of the data and */
/* can be used to plot the data. This new variable and */
/* the old variable can then be used to create a control */
/* data set. This data set can be used with PROC FORMAT */
/* to create a format that properly labels the */
/* data-ordered values along the axis. This program */
/* also illustrates how to produce a vertical axis on */
/* the right side of the graph that has the same axis */
/* range as the left vertical axis. */
/*********************************************************/
/* Set graphics options */
goptions reset=all border colors=(black) ftext=swiss;
/* Create input data set, ONE */
data one;
input state $2. sales;
datalines;
VA 5200
SC 9800
NC 7500
GA 12500
NY 17600
;
/* Create a new variable STATEORD that contains the */
/* numerical ordering of observations from the original */
/* data set ONE. */
data addn;
set one;
stateord=_n_;
run;
/* Create the control data set STNAME using the ADDN */
/* data set. The control data set contains the */
/* following required variables: */
/* START contains the unformatted values */
/* LABEL contains the formatted values (state names) */
/* FMTNAME= contains the name of the format (DATAORD) */
/* TYPE= contains the type of the format, N for numeric */
/* or C for character variables. */
data stname;
set addn(rename=(stateord=start state=label));
fmtname='dataord';
type='N';
keep fmtname label start type;
run;
/* The format DATAORD is created using the input */
/* control data set STNAME. */
proc format cntlin=stname;
/* Define TITLE and SYMBOL statements */
title1 f=swissb 'Sales by State';
symbol1 i=none f=swissb v='$' h=4 c=green;
symbol2 i=none v=none;
/* Create axis definitions */
axis1 order=(0 to 20000 by 5000) offset=(0,0)
value=(f=swissb) label=none;
axis2 minor=none offset=(3,3) value=(f=swissb h=1)
label=none;
/* Produce plot */
proc gplot data=addn;
plot sales*stateord / vaxis=axis1 autovref haxis=axis2;
plot2 sales*stateord / vaxis=axis1 ;
format sales dollar8. stateord dataord.;
run;
quit;

This example creates a new horizontal axis variable that reflects the original ordering of the data and can be used to plot the data.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Axis
|
| Date Modified: | 2005-08-31 03:03:14 |
| Date Created: | 2004-11-11 11:08:00 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |