Hello--
The following is a simplified example of a problem I am trying to wade through.
I have a dataset that has State scores by year. I want to plot the scores over time for each of the states--with specific colors, linestyles, and shapes for each state. I also want to use the annotate function to shade a portion of the graph that I would like to accentuate. I was able to get the annotate to work with sgplot, but cannot get it to work with sgrender. Any help would be greatly appreciated.
Specifically:
--How can I get the shaded part to work with annotate?
--Is there an easier way to accomplish my different colors, linestyles, markers by state?
Thanks.
Nick
data statescores;
input state $ year score;
cards;
NC 2010 75
NC 2011 77
NC 2012 72
NC 2013 85
NC 2014 87
SC 2010 72
SC 2011 73
SC 2012 60
SC 2013 79
SC 2014 76
VA 2010 80
VA 2011 80
VA 2012 79
VA 2013 81
VA 2014 83
;
run;
data drop;
input startdate enddate;
datalines;
2011 2013
;
data annorec;
length function style color $8;
retain xsys '2' ysys '1' when 'b';
set drop;
function='move';
x=startdate;
y=60;
output;
function='bar';
x=enddate;
y=90;
color='ltgray';
style='solid';
output;
run;
proc template;
define style styles.stocks;
parent=styles.listing;
style GraphData1 from GraphData1 /
ContrastColor=blue
Color=red
MarkerSymbol="CircleFilled"
Linestyle=1;
style GraphData2 from GraphData2 /
ContrastColor=brown
Color=blue
MarkerSymbol="none"
Linestyle=2;
style GraphData3 from GraphData3 /
ContrastColor=orange
Color=orange
MarkerSymbol="none"
Linestyle=2;
end;
run;
proc template;
define statgraph trend;
begingraph;
entrytitle "Scores for NC, SC, and VA";
discreteattrmap name="stockname" / ignorecase=true;
value 'NC' /
markerattrs=GraphData1(color=red symbol=circlefilled)
lineattrs=GraphData1(color=red pattern=solid);
value 'SC' /
markerattrs=GraphData2(color=orange)
lineattrs=GraphData2(color=green pattern=dot);
value 'VA' /
markerattrs=GraphData3(color=blue)
lineattrs=GraphData3(color=blue pattern=dot);
enddiscreteattrmap;
discreteattrvar attrvar=stockmarkers var=stock
attrmap="stockname";
layout overlay;
seriesplot x=year y=score /
group=state
display=(markers)
name="scores";
discretelegend "scores" / title="State Scores";
endlayout;
endgraph;
end;
run;
/* Plot the scores*/
ods pdf file="/sasdata/username/testgraph.pdf";
ods pdf style=styles.stocks;
proc sgrender data=statescores template=trend sganno=annorec;
run;
quit;
ods pdf close;
Have a look at Annotating ODS Graphics :: SAS(R) 9.4 ODS Graphics: Procedures Guide, Third Edition. There are no "move" or "bar" annotate function, I'm very surprised how you managed to get this annotate to work with sgplot. It looks like you are trying to use the annotations from SAS/GRAPH (GPlot)! - it will not work, ODS Graphics annotations are totally different.
Hey Andrey--
This helps a lot. Thanks. I still can't get the syntax quite right, though. It looks like I need the rectangle function with fillcolor:
data annorec;
/* length function style color $8; */
retain xsys '2' ysys '1' when 'b';
set drop;
function='rectangle';
height=.4;
width=2;
x=startdate;
y=60;
display="all";
FILLCOLOR='LTGRAY';
output;
run;
Any ideas what I'm missing here?
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.