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

I am doing a multicell plot in GTL with some barcharts and what to control the colors with an attributemap. 

The grouping within each of the cell plots are different . To illustrate the "problem" I have played with sashelp.cars where the two plots use car type for group, the other drive train. 

 

In the first cell we have a barchart of engine size by car type. 

In the second cell we have a barchart of engine size by drive train. 

The plot itself is okay as such but I want to control the colors with an attributemap.

I also want to show a legend group item if data is available for that group. Have tried several work around by can not get it to work...... 

 

example_cars.jpg

Here is the code:

data attrmap;
retain ID "cars"
       linecolor "black";
input  
      VALUE $   1-9     
      FILLCOLOR $ 10-19  
      FILLPATTERN $ 20-29
      ;
*--------1---------2---------3---------4---------5---------6---------7---------8---------9;
datalines;
Hybrid   black     solid
SUV      yellow    solid
Sedan    blue      solid
Sports   vivid     solid
Truck    hue       solid
Wagon    orange    solid
All      red       l1
Front    green     l2
Rear     yellow    l3
;
run;


proc template;
   define statgraph multicell;
      begingraph;
        layout lattice   / rowgutter=10px 
                           columngutter=10px;
          layout overlay;
                entry "Car type" / valign=top;
               barchart  x=origin y=engine/ group=type name="legend_1" ;
               discretelegend "legend_1" /displayclipped=true 
                                           autoitemsize=true
                                           LOCATION=outside;
         endlayout;

         layout overlay;
               entry "Car drivetrain" / valign=top;
               barchart  x=origin y=engine/ group=drivetrain name="legend_2" ;
               discretelegend "legend_2" /displayclipped=true 
                                           autoitemsize=true
                                           LOCATION=outside;
         endlayout;
         
      endlayout;
   endgraph;
end;
run;


proc summary data=sashelp.cars;
   class origin type drivetrain;
   var enginesize;
   output mean=engine out=data4plot;
run; 

proc sgrender data=data4plot template=multicell dattrmap=work.attrmap;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

There are two things you need to do here:

1. Split the attrmap into two separate attrmap within the same data set so that you can address them with difference group variables. To do this, input the ID via the datalines instead of retaining one ID.

2. You need to use a DATTRVAR statement in SGRENDER to bind the correct map to each group variable.

 

Here is your modified example:

data attrmap;
retain linecolor "black";
input
      VALUE $   1-9
      FILLCOLOR $ 10-19
      FILLPATTERN $ 20-29
      ID          $ 30-34
      ;
*--------1---------2---------3---------4---------5---------6---------7---------8---------9;
datalines;
Hybrid   black     solid     type
SUV      yellow    solid     type
Sedan    blue      solid     type
Sports   vivid     solid     type
Truck    hue       solid     type
Wagon    orange    solid     type
All      red       l1        drive
Front    green     l2        drive
Rear     yellow    l3        drive
;
run;

proc template;
   define statgraph multicell;
      begingraph;
        layout lattice   / rowgutter=10px
                           columngutter=10px;
          layout overlay;
                entry "Car type" / valign=top;
               barchart  x=origin y=engine/ group=type name="legend_1" ;
               discretelegend "legend_1" /displayclipped=true
                                           autoitemsize=true
                                           LOCATION=outside;
         endlayout;

         layout overlay;
               entry "Car drivetrain" / valign=top;
               barchart  x=origin y=engine/ group=drivetrain name="legend_2" ;
               discretelegend "legend_2" /displayclipped=true
                                           autoitemsize=true
                                           LOCATION=outside;
         endlayout;

      endlayout;
   endgraph;
end;
run;

proc summary data=sashelp.cars;
   class origin type drivetrain;
   var enginesize;
   output mean=engine out=data4plot;
run;

proc sgrender data=data4plot template=multicell dattrmap=work.attrmap;
dattrvar type="type" drivetrain="drive";
run;

View solution in original post

2 REPLIES 2
DanH_sas
SAS Super FREQ

There are two things you need to do here:

1. Split the attrmap into two separate attrmap within the same data set so that you can address them with difference group variables. To do this, input the ID via the datalines instead of retaining one ID.

2. You need to use a DATTRVAR statement in SGRENDER to bind the correct map to each group variable.

 

Here is your modified example:

data attrmap;
retain linecolor "black";
input
      VALUE $   1-9
      FILLCOLOR $ 10-19
      FILLPATTERN $ 20-29
      ID          $ 30-34
      ;
*--------1---------2---------3---------4---------5---------6---------7---------8---------9;
datalines;
Hybrid   black     solid     type
SUV      yellow    solid     type
Sedan    blue      solid     type
Sports   vivid     solid     type
Truck    hue       solid     type
Wagon    orange    solid     type
All      red       l1        drive
Front    green     l2        drive
Rear     yellow    l3        drive
;
run;

proc template;
   define statgraph multicell;
      begingraph;
        layout lattice   / rowgutter=10px
                           columngutter=10px;
          layout overlay;
                entry "Car type" / valign=top;
               barchart  x=origin y=engine/ group=type name="legend_1" ;
               discretelegend "legend_1" /displayclipped=true
                                           autoitemsize=true
                                           LOCATION=outside;
         endlayout;

         layout overlay;
               entry "Car drivetrain" / valign=top;
               barchart  x=origin y=engine/ group=drivetrain name="legend_2" ;
               discretelegend "legend_2" /displayclipped=true
                                           autoitemsize=true
                                           LOCATION=outside;
         endlayout;

      endlayout;
   endgraph;
end;
run;

proc summary data=sashelp.cars;
   class origin type drivetrain;
   var enginesize;
   output mean=engine out=data4plot;
run;

proc sgrender data=data4plot template=multicell dattrmap=work.attrmap;
dattrvar type="type" drivetrain="drive";
run;
Claus_Stenberg
Fluorite | Level 6

Thanks a million -  works like a charm 🙂 

 

Best regards

Claus

 

PS just noticed that a forgot a "nway" in my proc summary but that is a small detail that has nothing to do with the solution 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 684 views
  • 1 like
  • 2 in conversation