title: Styling different groups in SAS SGPLOT
body: <p>I am trying to produce a graph with multiple groupings. The sample data code is:</p>
  <blockquote>
  <pre><code>proc sort data=sashelp.cars out=cars;
    by DriveTrain;
    where n(Cylinders);
  run;
  </code></pre>
  </blockquote>
  <p>I used <code>dattrmap</code> to add distinct colors to the different groups as follow:</p>
  <blockquote>
  <pre><code>  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'; &gt;       &gt;       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; 
  </code></pre>
  </blockquote>
  <p>The Attrmap was created with the intention of having different colors for <code>Origin</code> and <code>DriveTrain</code> however, when the output is created the same colors applied to Origin are applied to DriveTrain.</p>
  <p>I also tried using Proc template to change the style as follow:</p>
  <blockquote>
  <pre><code>  /*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;
  </code></pre>
  </blockquote>
  <p>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.</p>
  <p>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 <code>sortkey=national</code> and used <code>grouporder=data</code> as recommended by SAS but this didn't change the ordering in the output. Any help is appreciated.</p>
  <p><a href="https://i.stack.imgur.com/VJIW6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VJIW6.png" alt="Here is the output" /></a>.</p>
  <p>Thanks.</p>