BookmarkSubscribeRSS Feed
Manj
Fluorite | Level 6

Hi 

I have the following code to create the attaced graph


proc template;

define statgraph bar100;

begingraph ;
layout overlay/ xaxisopts=(display=standard label=" "
discreteopts=(tickdisplaylist=(&xticks) tickvaluefitpolicy=split tickvaluesplitchar="~") )
yaxisopts=(display=standard label='Percentage of Patients' linearopts=(viewmin=0 viewmax=100 tickvaluesequence=(start=0 end=100 increment=10) viewmin=0 viewmax=100 tickvalueformat =pct.));
BARCHARTPARM X = avisn y=percent / group=avalx name="lgnd1" ;

discretelegend "lgnd1" /halign=right across=1 sortorder=DESCENDINGFORMATTED;

endlayout;

endgraph;
end;
run;
proc sgrender data=all template=bar100;
run;

 

My Query is how to make the custom colours for the stacks?

I tried using 

Begingraph //datacolors=(grey pink lightblue blue orange yellow lightred red lightgreen green black)

 

This gave me the colours i mentioned  but not as the way i wanted. This pics the colours based on the first xaxis value and so on.  I tried sorting data using my group variable avalx but that make the graph wrong.

 

My output without using the datacolours is below:

My intention is to give grey = 00  pink=02 lightblue=04  blue=08 orange=12 yellow=16 lightred=20 red=24 lightgreen=32 green=48 black=ND

Manj_0-1591894275170.png

 

 

4 REPLIES 4
ballardw
Super User

Have you considered using a DATTRMAP data set? The data set contains formatted values of your variable and appearance settings.

With SGRENDER

Requirements Do either one of the following:
  • specify the attribute map ID variable by using the DATTRVAR statement in the SGRENDER procedure.
  • specify the attribute map ID variable using the DISCRETEATTRVAR variable in the StatGraph template.
If neither of these requirements is met, the descriptions in the attribute map data set are ignored.
The values in the DATTRMAP data set must be sorted by ID. If they are not, only the first value is found.
Manj
Fluorite | Level 6

But I see these are for individual bars and not the stacks within each bars. It is a stacked bar chart .May be I'm missing something? 

DanH_sas
SAS Super FREQ

DATTRMAPS will work for your stacked bar chart as well, as the attribute mapping is tied to your GROUP values. See pages 9-14 in this paper for more information: https://support.sas.com/resources/papers/proceedings17/SAS0675-2017.pdf

 

Hope this helps!

Dan

Manj
Fluorite | Level 6
Hi
Thanks for this. This works if I specify the colours. I found the below from the sas blogs. It says green to red. Quite unsure of this dynamic way of doing it. Im looking for colours from dark yellow--light yellow--red and I have about 12 stacks. The below code is working fro green to red. but im not sure how to alter this code for the scheme im looking for.

/*--Define attributes map data set--*/
data AttrMap;
length FillColor $8 LineColor $8;
id='Hist';
ghigh=192; /*--High value for Green--*/ ???? not sure of this number
rhigh=255; /*--High value for Red--*/ ???? not sure of this number

mid=(&minbin + &maxbin) / 2;
LineColor='CX000000';

do val=&minbin to &maxbin by &BinInt;
value=put(val, 5.0);
if val < mid then do;
g=ghigh; b=0; r=rhigh*(val-&minbin)/ (mid-&minbin);
end;
else do;
r=rhigh; b=0; g=ghigh*(1-((val-&minbin) - (mid-&minbin))/ (mid-&minbin)); ???? what is this calculation?
end;
fillcolor='CX' || put(r, hex2.) || put(g, hex2.) || put(b, hex2.); ???? what is this calculation?
output;
end;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1010 views
  • 2 likes
  • 3 in conversation