Proc IML has its own graphics commmands which can be used to produce high quality graphics output, similar to that produced by proc gplot. Some of the basic commands are illustrated here.
There are two coordinate systems used in IML graphics. These coordinate systems are used to relate the range of data values to physical positions on the output device.
The world coordinate system is the coordinate system determined by the range of values of the data. In the world coordinate system, the range of values along each axis are arbitrary. A window is a rectangular area defined in the world coordinate system.
The normalized coordinate system is the coordinate system used to logically describe positions on the output device, usually the screen or page. The lower left corner of the output device ALWAYS has coordinate (0,0) in the normalized system; the upper right corner ALWAYS has coordinate (100,100) in the normalized system. A viewport is a rectangular area in the normalized system.
By defining multiple viewports and windows and linking them, it is possible to put multiple graphs on a single page of output.
Here is a short program that defines three vectors x and
y and z. The graph of y against
x and z against x are placed on
the same page.
proc iml;
/* Define the data */
x={1,2,3,4,5};
y={1,4,9,16,25};
z={1,-4,9,-16,25};
reset clip; /* clip data at edge of viewport*/
/* Start making the graphs */
call gstart; /* MUST be used to start IML graphics session */
call gopen('xyz-plot'); /* Open new graphics segment */
call gset('font','swiss'); /* font and height for text */
call gset('height',1.0);
call gwindow({-5 -5 7 30}); /* declare window for y vs. x graph */
/* slightly larger than data range */
/* to leave room for text */
call gport({0 50 100 100}); /* declare port for y vs. x graph */
/* port is upper half of screen */
call gpoint(x,y,'plus'); /* plot the data points marking */
/* each with a plus sign */
call gdraw(x, y,1); /* connect the dots using linestyle 1 */
call gxaxis({0 0},5,6, , ,'2.',.5); /* draw x and y axis and label them */
call gyaxis({0 0},25,6, , ,'2.',.5);
call gtext(3,-3,'X Values'); /* Horizontal text labelling x axis */
call gvtext(-1,20,'Y Values'); /* Vertical text labelling y axis */
call gtext(2,27,'Graph of Y versus X'); /* Title text */
/*Now make z versus x plot */
call gwindow({-5 -30 7 30}); /* declare window for z vs. x graph */
/* slightly larger than data range */
/* to leave room for text */
call gport({0 0 100 50}); /* declare port for z vs. x graph */
/* port is lower half of screen */
call gpoint(x,z); /* plot the data points marking */
/* each with a plus */
call gdraw(x,z,2); /* connect the dots using linesytle 2 */
call gxaxis({0 0},5,6, , ,'2.',.5); /* draw x and y axis and label them */
call gyaxis({0 -25},50,11, , ,'3.',.5);
call gtext(3,-25,'X Values'); /* Horizontal text labelling x axis */
call gvtext(-1,20,'Z Values'); /* Vertical text labelling y axis */
call gtext(2,27,'Graph of Z versus X'); /* Title text */
call gshow; /* MUST be used to display graphs */
call gclose; /* close graphics segment */
Most of the commands are self-explanatory. Here are some details. For further information see the SAS/IML Software manual or the online help under SAS SYSTEM--MODELLING AND ANALYSIS TOOLS--INTERACTIVE MATRIX LANGUAGE.
gpoint(x,y,'plus') sequentially plots the pairs of points
determined by the corresponding entries of the vectors x and
y. The vectors x and y must have the same length. The
optional plot symbol (here 'plus') can be specified.
gdraw(x,y,1) sequentially connects the pairs of points determined
by the corresponding entries of the vectors x and y. The
vectors x and y must have the same length. The optional line
style (here the default value 1) selects a line style.
gxaxis({0 0},5,6, , ,'2.0',.5) draws the x axis beginning at the
point {0 0}, of length 5, with 6 tick marks. Each label
is in the format 2.0 and of height .5 units. Space must be
left for the 2 optional and omitted arguments.
The first two arguments of the text commands gtext and gvtext
specify the lower left corner of the position of the first letter of
text in world coordinates. The text height and style are determined by
the gset commands given earlier.
Copyright © 1997 by Jerry Alan Veeh. All rights reserved.