www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback


/****************************************************************/
/* Labeling Data Points in a Two-Dimensional Plot           	*/
/*								                                       */
/* Labeling data points in a plot can emphasize or clarify  	*/
/* their values. The data points are labeled with the Annotate	*/
/* facility.																	*/
/*																					*/
/* This example is detailed in SAS/GRAPH Software Examples 		*/
/* Version 6 First Edition. 												*/
/****************************************************************/

/* Set graphics options */

goptions reset=all ftext=centxi htext=3 gunit=pct colors=(black) border;

/*****************************************************************/
/* Create the input data set, GAMES. GAMES contains the cities in*/
/* which the events were held from 1976 through 1992 and the	 */
/* cost of the broadcast rights.				 */
/*****************************************************************/

data games;
   input place $ 1-11 cost;
   cards;
Montreal      25
Moscow        87
Los Angeles  225
Seoul        309
Barcelona    401
;

/*****************************************************************/
/* Create a format for the values of COST. The AMTFMT. format 	 */
/* adds a comma and an M to the values and prefixes the values	 */
/* with a dollar sign ($). Because AMTFMT. is defined in a 	 */
/* PICTURE statement, AMTFMT, affects only the display of values.*/
/*****************************************************************/

proc format;
   picture amtfmt low-high='00,009M'
                  (prefix='$');
run;

/*****************************************************************/
/* Create the Annotate data set, LABELS. LABELS adds the cost to */
/* each data point. Since values of the plot variables are used  */
/* to position the labels, the coordinate system must be 	 */
/* absolute data values (2).					 */
/*****************************************************************/

data labels;
   length function style text $ 8;
   retain function 'label' xsys ysys '2' hsys '3' style 'centxi'
          size 4 when 'a' color 'black';
   drop place cost;

   set games end=lastob; /* The PLACE and COST variables from GAMES */
                         /* determine the values of the */
   xc=place; y=cost;     /* of the XC and Y variables. XC is used instead of */
                         /* X because PLACE is a character variable. */

   text=left(put(cost,amtfmt.)); /* The formatted values of COST are */
                                 /* displayed as the text.  */

   if _n_=1 then position='C';   /* The value of POSITION changes, depending */
                                 /* upon the data point's */
   else if lastob then position='A'; /* location on the plot line. */
   else position='B'; output;
run;

/* Add the title and footnotes. */

title1 height=5 'Cost of U.S. Broadcast Rights for the Olympics';
footnote1 font=swissl height=2.5 justify=left ' SAS/GRAPH'
          move=(+0,+.5) '02'x move=(+0,-.5) ' Software'
          justify=right 'GAMES ';


/* Modify the appearance of the axes. */

/* The VALUE= options in the AXIS1 statement stacks the tick mark */
/* labels by adding JUSTIFY=CENTER between the text strings.	  */

axis1 label=none
      order=('Montreal' 'Moscow' 'Los Angeles' 'Seoul' 'Barcelona')
      value=(tick=1 'Montreal' justify=center '1976'
             tick=2 'Moscow' justify=center '1980'
             tick=3 'Los Angeles' justify=center '1984'
             tick=4 'Seoul' justify=center '1988'
             tick=5 'Barcelona' justify=center '1992');
axis2 label=('$U.S.,' justify=right 'Millions') order=(0 to 500 by 100);

pattern1 color=bioy value=solid; /* Define the pattern for the area in the plot. */

symbol1 color=bioy value=none interpol=join; /* Select the color and */
                                             /* interpolation method. */

/* Produce the plot. The PLOT statement includes the annotation defined */
/* in the LABELS data set. */

proc gplot data=games;
   plot cost*place / areas=1 haxis=axis1 vaxis=axis2
                     href= 'Moscow' 'Los Angeles' 'Seoul' chref=black
                     vref=100 to 400 by 100 cvref=black vminor=0
                     cframe=blue annotate=labels;
run;
quit;
Copyright (c) 2002 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement