Using Annotate Macros

Macro Structure

The general form of an Annotate macro is
%MACRO (parameters);
In general, the macro name represents a function and the parameters contain the values for the variables that can be used with the function. All macros except DCLANNO, SYSTEM, and SEQUENCE output an observation.
The parameters are either numeric or character. Numeric parameters can be numeric constants or numeric variable names that have been initialized to the appropriate value. Most character parameters must be expressed as literals, that is character strings without quotation marks. Exceptions are the text values that are used with the COMMENT and LABEL macros, which can be expressed as character strings enclosed in quotation marks or as character variable names.
The Annotate facility assigns the parameter values to the corresponding Annotate variables. Therefore, the observations in an Annotate data set that is created with macros that look the same as the ones that you created with assignment statements. For example, the following two statements are equivalent:
%LABEL (10, 15, "Graph", black, 0, 0, centb, 8);

function="label"; x=10; y=15; text="Graph"; color="black"; style="centb";
position="8"; output; 

Making the Macros Available

To use Annotate macros, you must provide your program with access to the data set that contains the macros, and you must compile the macros before you use them. You can access the Annotate macros in one of these ways:
  • If the fileref is not set automatically, find out where the Annotate macros are stored and allocate a fileref that points to the data set:
    filename fileref "external-file";
    Then include the Annotate macros in your session:
    %include fileref (annomac);
  • If the fileref is set automatically, compile the Annotate macros and make them available by simply submitting the ANNOMAC macro:
    %annomac;
    Note: The ANNOMAC macro must be run before any other Annotate macros are used in a SAS session. You will see a message in the SAS log that indicates that the Annotate macros are now available. The message also shows you how to get help for using the macros.

Annotate Macro Task Summary

The following table summarizes the tasks performed by the Annotate macros.
Tasks with Annotate Macros
Tasks
Macro to use
Assign values of (XLSTT,YLSTT) to (XLAST,YLAST)
%TXT2CNTL;
Begin drawing a polygon
%POLY(x, y, color, style, line);
Continue drawing a polygon
%POLYCONT(x, y, color);
Copy (XLAST,YLAST) to (XLSTT,YLSTT)
%CNTL2TXT;
Declare all variables
%DCLANNO;
Draw an arrow
%ARROW(x1, y1, x2, y2, color, line, size, angle, style);
Draw a bar
%BAR(x1, y1, x2, y2, color, line, style);
Draw a circle
%CIRCLE(x, y, size, color);
Draw a frame
%FRAME(color, line, size, style);
Draw a line from (XLAST,YLAST) to (XLSTT,YLSTT)
%DRAW2TXT(color, line, size);
Draw a line from previous point
%DRAW(x, y, color, line, size);
Draw a line
%LINE(x1, y1, x2, y2, color, line, size);
Draw a pie slice or arc
%SLICE(x, y, angle, rotate, size, color, style, line);
Draw a rectangle
%RECT(x 1,y 1,x 2,y 2, color, line, size);
Draw text
%LABEL(x, y, text, color, angle, rotate, size, style, position);
Exchange the values of (XLAST,YLAST) and (XLSTT,YLSTT)
%SWAP;
Move to a point near a pie slice
%PIEXY(angle, size);
Move to a point without drawing
%MOVE(x, y);
Put values into a stack
%PUSH;
Retrieve values from a stack
%POP;
Scale and move input
%SCALET(ptx, pty, x0, y0, x1, y1, x0, vy0, vx1, vy1);
Scale input
%SCALE(ptx, pty, x0, y0, x1, y1, x0, vy0, vx1, vy1);
Set the coordinate system for the observation
%SYSTEM(xsys, ysys, hsys);
Set when to draw an observation
%SEQUENCE(when);
Write a comment to the data set
%COMMENT(text);