Hi all,
I'd like to be able to shade an area when using sgplot. Specifically, if I know my forecast will start January 1, 2016, I'd like to shade all areas to the right of that date with light gray shading in the background (not covering the forecast line graph).
Thanks in advance
-Bill
I'll leave the tweaking of the options up to you, but here's a demo on how to get started using a SASHelp dataset.
BAND is the statement in PROC SGPLOT that you're looking for, fillattrs seems to control the transparency and colour, which will be important.
proc sgplot data=sashelp.stocks;
where stock ='IBM';
scatter x=date y=open;
band y=open lower="01Jan2000"d upper= "01Jan2006"d / fillattrs=(color = red transparency=0.5) ;
run;quit;
In general if you're looking for Graph Examples, see the SAS Graph Gallery or robslink.com for many, many samples.
I'll leave the tweaking of the options up to you, but here's a demo on how to get started using a SASHelp dataset.
BAND is the statement in PROC SGPLOT that you're looking for, fillattrs seems to control the transparency and colour, which will be important.
proc sgplot data=sashelp.stocks;
where stock ='IBM';
scatter x=date y=open;
band y=open lower="01Jan2000"d upper= "01Jan2006"d / fillattrs=(color = red transparency=0.5) ;
run;quit;
In general if you're looking for Graph Examples, see the SAS Graph Gallery or robslink.com for many, many samples.
You might want to use a BLOCK plot for this type of display. Here is a simple example:
data air;
set sashelp.air;
lenth shade $ 8;
if date >= '01jan1957'd then shade="Forecast";
else shade="Actual";
run;
proc sgplot data=air;
block x=date block=shade / filltype=alternate fillattrs=GraphAltBlock altfillattrs=GraphBlock;
series x=date y=air;
run;
See http://support.sas.com/documentation/cdl/en/grstatproc/69716/HTML/default/viewer.htm#n0ikbvq5nwz6ezn... for more syntax options.
Hope this helps!
Dan
See the example and code in the article "Highlight forecast regions in graphs."
Thanks to all...I have it working perfectly!
Cheers
-Bill
@BCNAV Please mark the appropriate solution as the correct answer.
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.