BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BCNAV
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

5 REPLIES 5
Reeza
Super User

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. 

DanH_sas
SAS Super FREQ

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

Rick_SAS
SAS Super FREQ

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

BCNAV
Quartz | Level 8

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

 

Cheers

-Bill

Reeza
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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