Published on :
Reporting CREATION_INTERNE

Illustration of the POSITION option in ANNOTATE with GPLOT

This code is also available in: Deutsch Español Français
Awaiting validation
The script proceeds in several steps. Firstly, it initializes global graphic options. Secondly, a DATA STEP is used to create the 'Temp' dataset, which contains coordinates (X, Y) and a variable 'P' representing different positions. Thirdly, another DATA STEP generates the 'myAnno' annotation dataset from 'Temp', defining the necessary ANNOTATE functions (LABEL) and using the 'P' variable to specify the position of the annotation text. Finally, PROC GPLOT is executed to display a scatter plot based on 'Temp', with labels positioned according to 'myAnno' specifications, thus visually illustrating the impact of the POSITION option.
Data Analysis

Type : CREATION_INTERNE


Both datasets ('Temp' and 'myAnno') used in this script are entirely created and generated internally. 'Temp' is populated via SAS loops and calculations, and 'myAnno' is derived from 'Temp' for annotation purposes.

1 Code Block
System parameters and graphic options
Explanation :
This block configures the path for graphic files via a FILENAME statement (note that the Windows path 'c:\...' might require adaptation for a Linux/Viya environment). It then initializes global graphic options by resetting parameters, enabling a border, specifying graphic units in percentage, text height, and font.
Copied!
1FILENAME Fig "c:\JES\figures\Chapter_6\";
2GOPTIONS RESET=ALL BORDER GUNIT=PCT HTEXT=3 FTEXT='Arial';
3 
2 Code Block
DATA STEP Data
Explanation :
This DATA STEP creates the 'Temp' dataset. It uses nested loops to generate observations with variables X (from 1 to 3) and Y (from 1 to 5). The variable 'P' is calculated, formatted as a character, and 'IF' conditions transform it into letters (A to F) for certain numeric values. Each iteration produces a distinct observation.
Copied!
1DATA Temp;
2 DO X= 1 TO 3;
3 DO Y = 1 TO 5;
4 P = PUT(X+((6-Y)-1)*3, $2.);
5 IF P="10" THEN P="A";
6 IF P="11" THEN P="B";
7 IF P="12" THEN P="C";
8 IF P="13" THEN P="D";
9 IF P="14" THEN P="E";
10 IF P="15" THEN P="F";
11 OUTPUT;
12 END;
13 END;
14RUN;
3 Code Block
DATA STEP
Explanation :
This DATA STEP builds the 'myAnno' annotation dataset based on the 'Temp' dataset. It assigns specific values to variables required by SAS/GRAPH ANNOTATE: FUNCTION (for labels), XSYS and YSYS (for coordinate systems), X and Y (point coordinates), POSITION (for text alignment), and TEXT (the label content, derived from the 'P' variable).
Copied!
1DATA myAnno; SET Temp;
2 FUNCTION='LABEL'; XSYS='2'; YSYS='2'; X=X; Y=Y;
3 POSITION=TRIM(LEFT(P)); TEXT='POS = '||TRIM(LEFT(P));
4RUN;
4 Code Block
PROC GPLOT
Explanation :
This block configures the visual elements of the graph: the type, size, and color of symbols (SYMBOL1), as well as the absence of labels and offset for axes (AXIS1, AXIS2). A title is defined for the graph. Finally, PROC GPLOT is executed to create a scatter plot of Y versus X, using the 'Temp' dataset. The ANNOTATE=myAnno option is used to overlay the previously defined annotations, and custom axes are applied.
Copied!
1SYMBOL1 VALUE=dot HEIGHT=3 COLOR=green;
2AXIS1 LABEL=NONE OFFSET=(10, 10);
3AXIS2 LABEL=NONE OFFSET=(20, 20);
4TITLE "Effect of the POSITION Variable in an ANNOTATE Data Set";
5PROC GPLOT DATA=Temp;
6 PLOT Y*X / NAME="F6_54_" ANNOTATE=myAnno HAXIS=AXIS2 VAXIS=AXIS1;
7RUN; QUIT;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.