Hi ,
I made an annotated dataset to try out the sgplot, and found the result is not what I expected, Could you tell me what i should do to make my existing annotated datasets are still valuable in new powerful procedure sgplot?
Thank you so very much.
****************************************************************************;
data xx;
do Dt='1JAN2016'd to '1jan2017'd;
retain CNT 1;
cat1=rand('bernolli',0.3);
cat2=rand('bernolli',0.5);
mon=month(DT);
output;
end;
run;
proc means data=xx sum;
var CAT1 CAT2;
class MON ;
output out=res_cnt sum=/autoname;
run;
data plt;
set res_cnt;
x=_n_;
y=CAT1_sum;
if mon>.;
run;
%annomac;
data plt_anno ;
set plt;
%dclanno;
%line(0,0,10,10,black,1,1);
%line(0,0,12,22,black,1,1);
%line(0,0,22,33,black,1,1);
%line(0,0,32,44,black,1,1);
run;
axis1;
axis2;
proc ganno annotate=plt_anno;
title1 "ganno";
run;
proc gplot data=plt;
title1 "gplot";
plot y*mon/anno=plt_anno;
run;
proc sgplot data=plt sganno=plt_anno;
title1 "sgplot";
scatter x=mon y=y;
run;
***************************************************************************;
The advantage to SGPLOT is that sometimes there's an easier/better way to do things.
Both codes generate a standard scatter plot but the GPLOT has some random lines?
In SGPLOT I would consider using REFLINE/POLYGON/TEXT instead to mimic some of the functionality you had with the annotation sets. I'm not sure this would work in your exact situation/example.
Annotation in SGPLOT is NOT the same as in GPLOT. You cannot use the same data set. That is one reason the option name is called SGANNO, not ANNO. See this article on some information.
That said, there are better ways to create graphs in SG procedures without use of annotation as alluded to by Reeza. See Getting Started articles in Graphically Speaking Blog for many articles on using plot layers.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.