Data visualization with SAS programming

SGPLOT and Shading of Forecast Area

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

SGPLOT and Shading of Forecast Area

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


Accepted Solutions
Solution
2 weeks ago
Grand Advisor
Posts: 16,905

Re: SGPLOT and Shading of Forecast Area

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;

http://support.sas.com/documentation/cdl/en/grstatproc/69716/HTML/default/viewer.htm#n1t2ihc734azuvn...

 

In general if you're looking for Graph Examples, see the SAS Graph Gallery or robslink.com for many, many samples. 

View solution in original post


All Replies
Solution
2 weeks ago
Grand Advisor
Posts: 16,905

Re: SGPLOT and Shading of Forecast Area

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;

http://support.sas.com/documentation/cdl/en/grstatproc/69716/HTML/default/viewer.htm#n1t2ihc734azuvn...

 

In general if you're looking for Graph Examples, see the SAS Graph Gallery or robslink.com for many, many samples. 

SAS Super FREQ
Posts: 877

Re: SGPLOT and Shading of Forecast Area

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

SAS Super FREQ
Posts: 3,310

Re: SGPLOT and Shading of Forecast Area

See the example and code in the article "Highlight forecast regions in graphs."

Occasional Contributor
Posts: 17

Re: SGPLOT and Shading of Forecast Area

Thanks to all...I have it working perfectly!

 

Cheers

-Bill

Grand Advisor
Posts: 16,905

Re: SGPLOT and Shading of Forecast Area

@BCNAV Please mark the appropriate solution as the correct answer. 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 114 views
  • 1 like
  • 4 in conversation