Esteemed Advisers:
I'm trying but failing to get annotate a scatterplot with arrows. Below is a simplified version of my code that demonstrates the problem. Probably a simple fix that I'm just not seeing.
Thanks in advance for your help,
Gene
options mprint symbolgen;
/*Create scatter plot dataset*/
data work.plot_data;
input lat lon alt;
datalines;
34.0 -105.0 120
33.0 -104.0 120
;
run;
/*Create arrow dataset file*/
data work.arrow_data;
input latbeg lonbeg latend lonend;
datalines;
34.5 -105.5 34.0 -105.0
33.5 -104.5 33.0 -104.0
;
run;
/*Create arrow_anno dataset*/
data arrow_anno;
set work.arrow_data;
retain xsys ysys '2' hsys '3' when 'a';
function='arrow';
x1=lonbeg;
y1=latbeg;
x2=lonend;
y2=latend;
color='black';
line=2;
size=.7;
style='FILLED';
run;
ods graphics;
/*Generate plot*/
proc sgplot data=work.plot_data sganno=arrow_anno aspect=1;
Title "Anno Arrow Test";
scatter x=lon y=lat;
xaxis grid min=-106 max=-103 minorgrid;
yaxis grid min=30 max=35 minorgrid;
run;
data plot_data;
input lat lon alt;
datalines;
34.0 -105.0 120
33.0 -104.0 120
;
run;
data arrow_data;
input latbeg lonbeg latend lonend;
datalines;
34.5 -105.5 34.0 -105.0
33.5 -104.5 33.0 -104.0
;
run;
data arrow_anno; set arrow_data;
function='arrow';
shape='filled';
layer='front';
linecolor='black';
linethickness=1;
drawspace='datavalue';
x1=lonbeg;
y1=latbeg;
x2=lonend;
y2=latend;
run;
proc sgplot data=plot_data sganno=arrow_anno aspect=1;
Title "Anno Arrow Test";
scatter x=lon y=lat;
xaxis grid min=-106 max=-103 minorgrid;
yaxis grid min=30 max=35 minorgrid;
run;
The SGANNO feature uses a different data set than the SAS/GRAPH Annotation data set.
You need different variable names and values.
See: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n17wm229xfidj7n1nfx67jsb3yj5.htm
Also see for overview : https://support.sas.com/rnd/datavisualization/papers/Annotate_Your_SGPLOT_Graphs.pdf
Also note, you could easily use the VECTOR plot or SERIES plot in your use case.
data plot_data;
input lat lon alt;
datalines;
34.0 -105.0 120
33.0 -104.0 120
;
run;
data arrow_data;
input latbeg lonbeg latend lonend;
datalines;
34.5 -105.5 34.0 -105.0
33.5 -104.5 33.0 -104.0
;
run;
data arrow_anno; set arrow_data;
function='arrow';
shape='filled';
layer='front';
linecolor='black';
linethickness=1;
drawspace='datavalue';
x1=lonbeg;
y1=latbeg;
x2=lonend;
y2=latend;
run;
proc sgplot data=plot_data sganno=arrow_anno aspect=1;
Title "Anno Arrow Test";
scatter x=lon y=lat;
xaxis grid min=-106 max=-103 minorgrid;
yaxis grid min=30 max=35 minorgrid;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.