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.
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!
DATA Temp;
DO X= 1 TO 3;
DO Y = 1 TO 5;
P = PUT(X+((6-Y)-1)*3, $2.);
IF P="10" THEN P="A";
IF P="11" THEN P="B";
IF P="12" THEN P="C";
IF P="13" THEN P="D";
IF P="14" THEN P="E";
IF P="15" THEN P="F";
OUTPUT;
END;
END;
RUN;
1
DATA 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;
14
RUN;
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!
DATA myAnno; SET Temp;
FUNCTION='LABEL'; XSYS='2'; YSYS='2'; X=X; Y=Y;
POSITION=TRIM(LEFT(P)); TEXT='POS = '||TRIM(LEFT(P));
RUN;
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!
SYMBOL1 VALUE=dot HEIGHT=3 COLOR=green;
AXIS1 LABEL=NONE OFFSET=(10, 10);
AXIS2 LABEL=NONE OFFSET=(20, 20);
TITLE "Effect of the POSITION Variable in an ANNOTATE Data Set";
PROC GPLOT DATA=Temp;
PLOT Y*X / NAME="F6_54_" ANNOTATE=myAnno HAXIS=AXIS2 VAXIS=AXIS1;
RUN; QUIT;
1
SYMBOL1 VALUE=dot HEIGHT=3 COLOR=green;
2
AXIS1 LABEL=NONE OFFSET=(10, 10);
3
AXIS2 LABEL=NONE OFFSET=(20, 20);
4
TITLE "Effect of the POSITION Variable in an ANNOTATE Data Set";
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.