I am trying to produce a graph with multiple groupings. The sample data code is:
proc sort data=sashelp.cars out=cars; by DriveTrain; where n(Cylinders); run;
I used dattrmap
to add distinct colors to the different groups as follow:
data MyAttrMap; length MARKERCOLOR CONTRASTCOLOR color $25; ID='myreg'; value='All' ; MARKERCOLOR='red'; color='red'; MARKERSYMBOL = 'circle'; output; ID='myreg'; value='Front'; MARKERCOLOR='blue'; color='blue'; MARKERSYMBOL = 'circle'; output; ID='myreg1'; value='USA'; CONTRASTCOLOR='yellow'; color='yellow'; output; ID='myreg1'; value='Europe'; CONTRASTCOLOR='black'; color='black'; output; ID='myreg1'; value='Asia'; CONTRASTCOLOR='green'; color='green'; > > output; run; proc sgplot data=work.cars dattrmap=MyAttrMap; hbarparm category=enginesize response=horsepower/group=DriveTrain barwidth=.5 attrid=myreg name='dt'; scatter X=MPG_City Y=enginesize /group=origin name='origin' attrid=myreg1; keylegend 'dt' / title='Drive Train' location=outside position=bottom; keylegend 'origin' / title='Origin' location=outside position=bottom; where DriveTrain in ('All' 'Front'); run;
The Attrmap was created with the intention of having different colors for Origin
and DriveTrain
however, when the output is created the same colors applied to Origin are applied to DriveTrain.
I also tried using Proc template to change the style as follow:
/*Different colors from the ones used above*/ proc template; define style MyStyle; parent = Styles.Listing; STYLE graphdata1 / MARKERSYMBOL = 'circle' LINESTYLE = 1 CONTRASTCOLOR = liypk COLOR = red ; STYLE graphdata2 / MARKERSYMBOL = 'circle' LINESTYLE = 1 CONTRASTCOLOR = stybr COLOR = yellow ; STYLE graphdata3 / MARKERSYMBOL = 'circle' LINESTYLE = 1 CONTRASTCOLOR = mog COLOR = green ; STYLE graphdata4 / MARKERSYMBOL = 'circle' LINESTYLE = 1 CONTRASTCOLOR = brown COLOR = pink ; STYLE graphdata5 / MARKERSYMBOL = 'circle' LINESTYLE = 1 CONTRASTCOLOR = black COLOR = grey ; end; run;
But still the same results were obtained. Could anyone please tell me what I'm doing wrong or how to get this to work? I'm using SAS 9.3.
Another issue I'm encountering is the sorting. I want to sort the bars so that the same origins appear together and by the horsepower. I sorted using sortkey=national
and used grouporder=data
as recommended by SAS but this didn't change the ordering in the output. Any help is appreciated.
Thanks.
SORT
,where n(DriveTrain)
logs an error. Is that a typo ? – Richard