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

Hi,

  Im creating a stacked barcahart  and Im looking forward to make changes or add the below:

1) the panel label is on top of each panel ,how do I move that to the bottom of each panel?

2) I use colormodel=(white grey black) and colorresponse=groupvariable  which gives me the custom colours but my legend disappears if I add this in my code. How do I do custom colors for the stacks?

3) how do I add %symbol to the y axis tick values?

my code at present is :

proc template;
define statgraph bar100;
begingraph;

layout datapanel classvars=(trt01p) /
columns=2 rows=1 columndatarange=union headerlabeldisplay=value
rowaxisopts=(display=(tickvalues) griddisplay=on linearopts=(tickvalueformat=pct.))
columnaxisopts=(display=(tickvalues)
timeopts=(tickvalueformat=monname3.));
layout prototype / cycleattrs=true;
BARCHARTPARM X = avisit y=percent / group=avalc name="lgnd1" ;*colormodel=(white grey black) colorresponse=aval;
innermargin / align=bottom opaque=true separator=True;
axistable x=avisit value=count/ display=(label) classdisplay=stack class=avalc classorder=descending labelposition=max position=0 pad=10 ;
endinnermargin;
endlayout;
sidebar / align=bottom;
discretelegend "lgnd1" /valign=bottom down=1 sortorder=ASCENDINGFORMATTED title='PGI-S response categories' ;

endsidebar;
endlayout;
endgraph;
end;
run;


proc sgrender data=g100 template=bar100 ;
run;

 

The output i get for this code is :

Manj_0-1589482535724.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

First of all, you need to use DATALATTICE instead of DATAPANEL to be able to move the headers to the bottom. Use the COLUMNHEADERS option to more it to the BOTTOM.

 

As for your colors, the COLORMODEL option should be used only for COLORRESPONSE data. Since you are using a GROUP variable, use the DATACOLORS option on the BEGINGRAPH statement to set the colors for the group variable. If you need specific colors associated with specific group values, use a DISCRETEATTRMAP.

 

Hope this helps!

Dan

View solution in original post

3 REPLIES 3
DanH_sas
SAS Super FREQ

First of all, you need to use DATALATTICE instead of DATAPANEL to be able to move the headers to the bottom. Use the COLUMNHEADERS option to more it to the BOTTOM.

 

As for your colors, the COLORMODEL option should be used only for COLORRESPONSE data. Since you are using a GROUP variable, use the DATACOLORS option on the BEGINGRAPH statement to set the colors for the group variable. If you need specific colors associated with specific group values, use a DISCRETEATTRMAP.

 

Hope this helps!

Dan

Manj
Fluorite | Level 6

Thanks , It worked!

Manj
Fluorite | Level 6

I have nowupdated the code to the below. Now the only issue with presenign the % symbol along with y axis tickmarks. I tried creating a format using the proc format and tried giving that in the tickvalueformat . When i give this, this gives the yaxis tick label as 0% 10% etc, but the legend disappears , How to present y axis tick value aas 0% 10% etc and keep the legend ?


proc template;
define statgraph bar100;
begingraph / datacolors=(white lightgrey darkgrey grey black) datacontrastcolors= (black black black black black);

layout datalattice columnvar=trt01p /
columns=2 rows=1 columndatarange=union columnheaders=BOTTOM headerlabeldisplay=value
rowaxisopts=(display=all label='Percentage of Patients' linearopts=(viewmin=0 viewmax=100 tickvaluesequence=(start=0 end=100 increment=10) viewmin=0 viewmax=100 tickvalueformat =pct.))
columnaxisopts=(display=(label tickvalues) );
layout prototype / cycleattrs=true;
BARCHARTPARM X = avisit y=percent / group=avalc name="lgnd1" ;

innermargin / align=bottom opaque=true separator=True;
axistable x=avisit value=count/ display=(label) classdisplay=stack class=avalc classorder=descending labelposition=max position=0 pad=10 ;
endinnermargin;

endlayout;

sidebar / align=bottom;
discretelegend "lgnd1" /valign=bottom down=1 sortorder=ASCENDINGFORMATTED title='PGI-S response categories' ;
endsidebar;

endlayout;
endgraph;
end;
run;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1045 views
  • 2 likes
  • 2 in conversation